package tutorial;
import net.minecraft.client.renderer.texture.IconRegister;
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);
}
}
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 16x16 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: 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.6 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
Make sure that everything is also lower case or you will get errors.
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)
public void
registerIcons(IconRegister par1IconRegister)
{
this.itemIcon =
par1IconRegister.registerIcon(Tutorial.modid + ":" + (this.getUnlocalizedName().substring(5)));
}
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;
import net.minecraft.client.renderer.texture.IconRegister;
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);
}
@SideOnly(Side.CLIENT)
public void
registerIcons(IconRegister par1IconRegister)
{
this.itemIcon =
par1IconRegister.registerIcon(Tutorial.modid + ":" + (this.getUnlocalizedName().substring(5)));
}
}
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.
You can download the source code and the assets folder over here.
When you are done you can go back to the tutorial list over here.

Geen opmerkingen:
Een reactie posten