Modding 1.4.7: Basic Item Part 1

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.


package tutorial;


import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;


@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

@Init
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();

}
}


The first line of code you will have to add to your mod file looks like this.


public static 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.


import net.minecraft.item.Item;


Now inside of the load method you have to add a line like this one.


tutorialItem = new ItemTutorial(5000).setIconIndex(0).setItemName(“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.
The .setIconIndex(0) sets the location of the image on the spritesheet for the item. 0 is the top left, 1 is one space to the right etc.
.setItemName(“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.


package tutorial;

import net.minecraft.item.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = “Tutorial_Tutorialmod”, name = “Tutorial”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
public class Tutorial 
{
@SidedProxy(clientSide = “tutorial.ClientProxyTutorial”, serverSide = “tutorial.CommonProxyTutorial”)
public static CommonProxyTutorial proxy;

public static Item tutorialItem;

@Init
public void load(FMLInitializationEvent event)
{
proxy.registerRenderThings();

tutorialItem = new ItemTutorial(5000).setIconIndex(0).setItemName(“tutorial”);

LanguageRegistry.addName(tutorialItem, “Tutorial Item”);
}
}


Right now you will have an error under ItemTutorial. We will fix that in the next tutorial.

The source code for this tutorial will be available at the end of the last basic Item tutorial.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">