Modding 1.5.1: Basic Item Part 2

In this tutorial I will show you how to create the Item file for your basic Item. I will start in the mod file. This is the file I will start with.


package tutorial;

import net.minecraft.block.Block;
importnet.minecraft.block.material.Material;
import net.minecraft.item.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
importcpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.network.NetworkMod;
importcpw.mods.fml.common.registry.GameRegistry;
importcpw.mods.fml.common.registry.LanguageRegistry;
@Mod(modid = Tutorial.modid, name = “Mod Name”, version = “1.0”)
@NetworkMod(clientSideRequired = true, serverSideRequired = false)
publicclass Tutorial
{
       publicstaticfinal String modid = “YourName_ModName”;
      
       publicstatic Block tutorialBlock;
      
       publicstatic Item tutorialItem;
      
       @Init
       publicvoid load(FMLInitializationEvent event)
       {
             tutorialBlock = new BlockTutorialBlock(500, Material.rock).setUnlocalizedName(“tutorialBlock”);
            
             GameRegistry.registerBlock(tutorialBlock, modid + tutorialBlock.getUnlocalizedName2());
            
             LanguageRegistry.addName(tutorialBlock, “Tutorial Block”);
            
             tutorialItem = new ItemTutorial(5000).setUnlocalizedName(“tutorial”);
            
             LanguageRegistry.addName(tutorialItem, “Tutorial Item”);
       }
}

To create your Item file simply hover your mouse over the ItemTutorial and click Create Class. When you do that you will get a file just like this one.


package tutorial;

publicclass ItemTutorial {
}

The first thing you need to do in here is make it extend Item. Do that by adding extends Item behind the class name. You will get an error under Item which can be fixed by importing the file.
Once you have imported it you will get an error under your file name. To fix that one you will have to hover your mouse over the filename and select add Constructor. You will now have a file that looks like this.


package tutorial;

importnet.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
publicclass ItemTutorial extends Item
{
       public ItemTutorial(int id)
       {
             super(id);
       }
}

Now simply remove the comment change par1 into id for clarity and your basic Item is done.
One thing I suggest to add is a creative tab location. To do that you will have to add this one line of code to the constructor.


this.setCreativeTab(CreativeTabs.tabMaterials);


The thing inside of the brackets is the tab it will be shown on.
To do this you will also have to import CreativeTabs.

Now the file should look like this.


package tutorial;
importnet.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
publicclass ItemTutorial extends Item
{
       public ItemTutorial(int id)
       {
             super(id);
             this.setCreativeTab(CreativeTabs.tabMaterials);
       }
}

You can download the source code over here.

In the next tutorials I will show you how to set a custom Image for the Item. There will also be special uses and other features for items.

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="">