Modding 1.4.7: 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.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”);
}
}


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;

public class 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;

import net.minecraft.item.Item;

public class ItemTutorial extends Item
{

public ItemTutorial(int par1) {
super(par1);
// TODO Auto-generated constructor stub
}

}


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 simply is the tab it will be shown on.
To do this you will also have to import CreativeTabs.

If you want to use a custom spritesheet for your Item and you haven’t read the Custom Block Textures tutorial yet I suggest you read it over here. Once you have done that you should understand the next method.


public String getTextureFile()
    {
            return “/tutorialitems.png”;
    }


Of course you will also have to register that texture in the ClientProxy by using this line of code in there.


MinecraftForgeClient.preloadTexture(“/tutorialitems.png”);


So the ClientProxy should now look something like this.


package tutorial;

import net.minecraftforge.client.MinecraftForgeClient;

public class ClientProxyTutorial extends CommonProxyTutorial
{
@Override
public void registerRenderThings()
{
MinecraftForgeClient.preloadTexture(“/tutorialblocks.png”);
MinecraftForgeClient.preloadTexture(“/tutorialitems.png”);
}
}


And your Item file should now look like this.


package tutorial;

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

public class ItemTutorial extends Item
{
public ItemTutorial(int id) 
{
super(id);
this.setCreativeTab(CreativeTabs.tabMaterials);
}

public String getTextureFile()
    {
            return “/tutorialitems.png”;
    }
}


If you want a good template for an item spritesheet I suggest using this one.

It’s simply a 256 by 256 transparant texture file.

You can download the source code over here.

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