Alright so in this tutorial we will be discussing metadata for items. First before I show you how to make this metadata I am going to explain what metadata is and how it works, to the best of my ability. Metadata is basically a way of "cramming" a bunch of item / block ids into one id to conserve space in the block registry array, where Minecraft stores all the blocks registered. Alright so let's get started, first you are going to need a basic Item class which can be found here. Then you are going to need to insert: the following things into your super-constructor:
setHasSubtypes(true); // This allows the item to be marked as a metadata item.
setMaxDamage(0); // This makes it so your item doesn't have the damage bar at the bottom of its icon, when "damaged" similar to the Tools.
Now you need to add the following method to your item:
@Override
public int getIconFromDamage(int i){
return i; // Returning this allows your items metadata to coincide with your texturing so if your texture is on the 0 slot then make it 0
}
And this method:
@Override
public String getItemNameIS(ItemStack stack){
return names[stack.getItemDamage()]; // Names is a string[] that will be covered later in this tutorial, if you wan to just return a specific name continue.
}
And if you didn't want to do the above but just wanted to return a specific name then use this method:
@Override
public String getItemNameIS(ItemStack stack){
// You could also use a switch statement here as well for all those saying that
if(stack == <value here>){
return <value>;
} else{
return <default value>;
}
}
And finally add this method:
@SideOnly(Side.CLIENT)
public void getSubItems(int itemID, CreativeTabs tabs, List list){
// You can also take a more direct approach and do each one individual but I prefer the lazy / right way
for(int i = 0; i < <amount of items here>; ++i){
list.add(new ItemStack(itemID, 1, i));
}
}
setHasSubtypes(true); // This allows the item to be marked as a metadata item.
setMaxDamage(0); // This makes it so your item doesn't have the damage bar at the bottom of its icon, when "damaged" similar to the Tools.
Now you need to add the following method to your item:
@Override
public int getIconFromDamage(int i){
return i; // Returning this allows your items metadata to coincide with your texturing so if your texture is on the 0 slot then make it 0
}
And this method:
@Override
public String getItemNameIS(ItemStack stack){
return names[stack.getItemDamage()]; // Names is a string[] that will be covered later in this tutorial, if you wan to just return a specific name continue.
}
And if you didn't want to do the above but just wanted to return a specific name then use this method:
@Override
public String getItemNameIS(ItemStack stack){
// You could also use a switch statement here as well for all those saying that
if(stack == <value here>){
return <value>;
} else{
return <default value>;
}
}
And finally add this method:
@SideOnly(Side.CLIENT)
public void getSubItems(int itemID, CreativeTabs tabs, List list){
// You can also take a more direct approach and do each one individual but I prefer the lazy / right way
for(int i = 0; i < <amount of items here>; ++i){
list.add(new ItemStack(itemID, 1, i));
}
}