In this tutorial I will show you how to add a basic Item to Minecraft. In the first tutorial I will explain all the code you need in the mod file. The second tutorial will be about the Item file.
This is the mod file I will start with.
The first line of code you will have to add to your mod file looks like this.
publicstatic Item tutorialItem;
This line has to be added below the CommonProxy line and above the @Init line. When you add it you will get an error under Item. To fix that Press Ctrl, Shift, O and select the net.minecraft.item.Item import, or you can add this line of code to the file yourself above the @Mod line.
Now inside of the load method you have to add a line like this one.
tutorialItem = new ItemTutorial(5000).setUnlocalizedName(“tutorial”);
The first thing you put in this line is the item variable name you created earlier. What you set it equal to is the file where you will put a lot of information for the item. Inside of the brackets behind ItemTutorial is the Id for the item. I suggest keeping this somewhere above 4096.
.setUnlocalizedName(“tutorial”) simply sets a name for the item. It isn’t really used in the code, but you have to get a different one for every item or you will get strange errors. I suggest keeping it the same as the variable name.
There is one last line of code that you have to add to the mod file. It should be similar to the one below.
LanguageRegistry.addName(tutorialItem, “Tutorial Item”);
This line of code will simply make sure that your tutorialItem will get the name Tutorial Item inside of the game. The first parameter is always the item and the second one the name in game.
You will also have to import LanguageRegistry just like you did earlier.
The whole file should now look something like this.
Right now you will have an error under ItemTutorial. We will fix that in the next tutorial.
The tutorial source code will be available at the last part of the basic item tutorials.