Basic Items - 1.7.10
Declaring your item:
Items are relatively easy to code with MinecraftForge. The first thing we want to do when creating a new item is to define it in your TutorialMain class under @sidedproxy.
public static Item myFirstItem;
This declares your item WAY before anything else happens. The next thing to is to go into your init() method and write this line of code:
myFirstItem = new MyItem().setUnlocalizedName("myFirstItem");
We haven't created the MyItem class yet, so you'll get an error there.
The method setUnlocalizedName() assigns your item a unique, meaning every item needs to have a different unlocalized name, name that the game can read. This will be used to add textures and names to the item.
MyItem class
package tutorial.item;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
public class MyItem extends Item
{
public MyItem()
{
super();
setCreativeTab(CreativeTabs.tabFood);
}
@Override
public void registerIcons(IIconRegister iconRegister)
{
itemIcon = iconRegister.registerIcon("modId:" + getUnlocalizedName().substring(getUnlocalizedName().indexOf(".") + 1));
}
}
As you can see, this will be the building block of all of our future items. In the constructor you can place other methods such as setStackSize or setMaxDamage, or you can tag them after where you declare the item, like we did for setUnlocalizedName().
Don't worry about the registerIcons() yet, that will be explained in a future tutorial.
And that's all there is to a basic item. Now on to blocks.
Items are relatively easy to code with MinecraftForge. The first thing we want to do when creating a new item is to define it in your TutorialMain class under @sidedproxy.
public static Item myFirstItem;
This declares your item WAY before anything else happens. The next thing to is to go into your init() method and write this line of code:
myFirstItem = new MyItem().setUnlocalizedName("myFirstItem");
We haven't created the MyItem class yet, so you'll get an error there.
The method setUnlocalizedName() assigns your item a unique, meaning every item needs to have a different unlocalized name, name that the game can read. This will be used to add textures and names to the item.
MyItem class
package tutorial.item;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
public class MyItem extends Item
{
public MyItem()
{
super();
setCreativeTab(CreativeTabs.tabFood);
}
@Override
public void registerIcons(IIconRegister iconRegister)
{
itemIcon = iconRegister.registerIcon("modId:" + getUnlocalizedName().substring(getUnlocalizedName().indexOf(".") + 1));
}
}
As you can see, this will be the building block of all of our future items. In the constructor you can place other methods such as setStackSize or setMaxDamage, or you can tag them after where you declare the item, like we did for setUnlocalizedName().
Don't worry about the registerIcons() yet, that will be explained in a future tutorial.
And that's all there is to a basic item. Now on to blocks.