Modding 1.5.1: Custom Item Texture

In this tutorial I will show you how to add custom textures to your item. All of the code for this tutorial is done in the Item file. This is the file I will start with.


package tutorial;

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

The first thing you will have to do before you can add the texture to the item is to actually make the texture and make sure it is saved correctly etc.
To do this you will have to make a 16×16 sprite for the Item. I’m not going into detail about this, because I’m no artist. However, I use GIMP to make the textures I use.
The next part is saving the file. I know much more about that, so this is what you will have to do. For an item you need to make sure that the name for the file is: item.unlocalizedname.png
Then there is also the part where you need to make sure that it is in the right folder. In the newest versions of Forge for 1.5.1 Forge will load the images for you. You don’t have to add any code for that like you used to in earlier versions. However, because this is automated you also have to follow a couple of rules for the folder structure where you will have to save the images. This structure goes like this.
mods/[modid]/textures/items/Image.png
If you follow these rules you should be able to assign a texture to your item quite easily.

Now to get those textures to load in MCP you will have to open the forge folder where you have mcp installed in. Then enter the mcp folder and then the jars folder in there. When you are there you should be able to find the Minecraft.jar. In here you will have to paste the complete folder structure.
When you have done that your textures will be loaded in for you by Forge. The next part is to actually use them in your item. To do this you will have to add this one simple method.


@SideOnly(Side.CLIENT)

publicvoid updateIcons(IconRegister par1IconRegister)
    {
        this.iconIndex = par1IconRegister.registerIcon(Tutorial.modid + “:” + this.getUnlocalizedName());
    }

The only thing you have to change in here is Tutorial into whatever your mod file name is. Then your textures should load just fine in the game.
The whole file should now look like this.


package tutorial;

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

@SideOnly(Side.CLIENT)

       publicvoid updateIcons(IconRegister par1IconRegister)
    {
        this.iconIndex = par1IconRegister.registerIcon(Tutorial.modid + “:” + this.getUnlocalizedName());
    }
}

This method simply sets the iconIndex, which is the Icon used to render the item, to an Image located in the folder structure you made earlier. par1IconRegister.registerIcon is the method that loads this image.
In the next Item tutorials there will be more customization for the items.

Leave a Reply to Fred Bouton Cancel 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="">