Jump to content

[1.9] Brand-new to modding; GameRegistry.registerItem deprecated


Recommended Posts

Posted

I'm new to minecraft modding. I couldn't find any decent tutorials for 1.9, so I've been relying on a 1.8 tutorial (http://bedrockminer.jimdo.com/modding-tutorials) to get started with. Everything went relatively smoothly until I came to implementing a custom item. Eclipse claims GameRegistry.registerItem is deprecated, yet I'm not sure what to use instead. I looked for fixes to this on the internet, but they were all too vague for me to get anything out of them. Can anyone nudge me in the right direction? I'll include the code below.

 

(Sorry for the overabundance of code. I didn't know which scripts were significant to the problem, so I included everything.)

 

Main.java

package com.Tinarg.Test;

import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

@Mod(modid = Main.MODID, name = Main.MODNAME, version = Main.VERSION)
public class Main {

    public static final String MODID = "test";
    public static final String MODNAME = "Test";
    public static final String VERSION = "1.9-R1";

    @Instance
    public static Main instance = new Main();

    @SidedProxy(clientSide="com.Tinarg.Test.ClientProxy", serverSide="com.Tinarg.Test.ServerProxy")
    public static CommonProxy proxy;
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent e) {
    }

    @EventHandler
    public void init(FMLInitializationEvent e) {
    }

    @EventHandler
    public void postInit(FMLPostInitializationEvent e) {
    }
    
}

BasicItem.java

package com.Tinarg.Test.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;

public class BasicItem extends Item {

    public BasicItem(String unlocalizedName) {
        super();
        this.setUnlocalizedName(unlocalizedName);
        this.setCreativeTab(CreativeTabs.tabMaterials);
    }
}

ModItems.java

package com.Tinarg.Test.items;

import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;

public final class ModItems {

public static Item TestItem;

    public static void createItems() {
    	GameRegistry.registerItem(TestItem = new BasicItem("test_item"), "test_item");
    }
}

CommonProxy.java

package com.Tinarg.Test;

import com.Tinarg.Test.items.ModItems;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class CommonProxy {

    public void preInit(FMLPreInitializationEvent e) {
        ModItems.createItems();
    }

    public void init(FMLInitializationEvent e) {

    }

    public void postInit(FMLPostInitializationEvent e) {

    }
}

Client/ServerProxy.java (Mostly identical)

package com.Tinarg.Test;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class ClientProxy extends CommonProxy {

    @Override
    public void preInit(FMLPreInitializationEvent e) {
        super.preInit(e);
    }

    @Override
    public void init(FMLInitializationEvent e) {
        super.init(e);
    }

    @Override
    public void postInit(FMLPostInitializationEvent e) {
        super.postInit(e);
    }
}

Thanks in advance, and sorry for being so clueless. :P

Posted

The doc comments of the deprecated

GameRegistry

methods tell you what to use instead.

 

In this case, use

GameRegistry.register

. This registers any

IForgeRegistryEntry

implementation, including

Block

and

Item

.

 

You should use

IForgeRegistryEntry#setRegistryName

(or the overloads from

IForgeRegistryEntry.Impl

) to set the registry name of the object (usually in the constructor) and then use the single-argument overload of

GameRegistry.register

to register it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

Here are some up-to-date tutorials for basic modding in 1.9.4 which should come in handy in the future:

https://shadowfacts.net/tutorials/

http://modwiki.temporal-reality.com/mw/index.php/Main_Page

 

I'd also recommend reading this (it was written for 1.8 but is still mostly relevant), this and this to get a good understanding of how Minecraft Forge works.

Colore - The mod that adds monochrome blocks in every color of the rainbow!

http://www.minecraftforge.net/forum/index.php?topic=35149

 

If you're looking to learn how to make mods for 1.9.4, I wrote a helpful article with links to a lot of useful resources for learning Minecraft 1.9.4 modding!

 

http://supergeniuszeb.com/mods/a-helpful-list-of-minecraft-1-9-4-modding-resources/

Posted

The doc comments of the deprecated

GameRegistry

methods tell you what to use instead.

 

In this case, use

GameRegistry.register

. This registers any

IForgeRegistryEntry

implementation, including

Block

and

Item

.

 

You should use

IForgeRegistryEntry#setRegistryName

(or the overloads from

IForgeRegistryEntry.Impl

) to set the registry name of the object (usually in the constructor) and then use the single-argument overload of

GameRegistry.register

to register it.

 

I don't think I did this right. What's the syntax for the IForgeRegistryEntry#setRegistryName thingamajig?

package com.Tinarg.Test.items;

import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.common.registry.IForgeRegistryEntry;

public final class ModItems {

public static Item TestItem;

    public static void createItems() {
    	GameRegistry.register(TestItem = new BasicItem("test_item"));
    	IForgeRegistryEntry.setRegistryName(TestItem,"test_item");
    }
}

Posted

It's a method you call, but it's not static. Remember that Item inherits from IForgeRegistryEntry.

 

I think I'll just try starting over with the other tutorial Super found. There's probably a lot of other stuff that's broken too, considering I used an outdated tutorial.

 

Thanks for the help!

Posted

By the way, your main class is basically empty. Your item won't ever show up in-game because none of your methods ever get called.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.