Tutorial 4: Items

In this tutorial we will be adding our very first item to the game.  Let's begin!

Create a new class called ItemInit. I have placed it in a new package called init, I've done this because in the future we will be having many initialization classes which we can put in here.

Now we need to create a list where we can initialize all of our items, to do this we need to create a new static array list of ITEM. Just like this:
	//Creates a new ArrayList for our Items
	public static final List ITEMS = new ArrayList();
Now we need to add our item, to do this we need to create a new class called ItemBase that extends Item. In this class we can set properties for items that don't have any special uses in the constructor.
public class ItemBase extends Item
	public ItemBase(String name)
		//Sets the registry and unlocalised name to a string we can change
		//Adds the Item to the ITEM List in ItemInit

We put a String in the parameters of ItemBase so we can set a new string for every Item we add using ItemBase.

Go back into ItemInit and initialize your item underneath the ArrayList we made before like this:
public static final Item TUTORIAL_ITEM = new ItemBase("tutorial_item");
Now we need to go into CommonProxy class and create a method called registerItemRenderer this will get the resource location of the item:
public void registerItemRenderer(Item item, int meta, String id) {}
Now we need to go into ClientProxy class and create and overrideregisterItemRenderer:
public void registerItemRenderer(Item item, int meta, String id)
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), id));

Now we need to create a new package inside of our util package called handlers. This is were we are going to be putting our handler classes.

Now we need to create a new Class inside of this package called RegistryHandler

We need to make sure this class is and @EventBusSubscriber so it gets fetched when the game is loading, this also means we don't have to call it from our Main Class:
public class RegistryHandler

Now we need to make two methods in this class, one to register the Items from our ItemInit Class and one to register the models:
public static void onItemRegister(RegistryEvent.Register event)
	//Gets the items from the ItemInit Class
	event.getRegistry().registerAll(ItemInit.ITEMS.toArray(new Item[0]));

public static void onModelRegister(ModelRegistryEvent event)
	 //Checks if it is an Item from ItemInit
	for(Item item : ItemInit.ITEMS)
		//Registers the Items
		Main.proxy.registerItemRenderer(item, 0, "inventory");

That's it our item should now be in the Game! However it won't have any textures because we haven't added them yet.
To get your item you must do /give @a modid:item_name this is beacuse we haven't assigned it to a creative tab yet.

We now need to add some assets to make this work. Go into the src/main/resources (where our mcmod.info file is) and create a new package and call it assets create another package inside of that with the name of your modid, in my case it will be tutorialmod.

Inside this package we need to create some more packages, one called textures and one called models, inside the models package create another package called item. And in the textures package create yet another package called item.
Now we need to create a new Untitled Text File in the lang package. In this file we will be adding the names for our items like so:
item.tutorial_item.name=Tutorial Item
When we save this file make sure it is in the lang package and call it en_us.lang
Now create a new JSON file in models/item and give it the same name as your items registryName (The string we made in ItemInit). This will be the item's model file where we reference the texture and how it is held, in this case I will just be using a generic item:
    "parent": "item/generated",
    "textures": {
        "layer0": "tutorialmod:items/tutorial_item"

JSON stands for JavaScript Object Notation which transmitts data objects!

Now, the last thing we need to add is the texture, to do this you need to create one, there are many ways of doing this, I recommend using Paint.new becuase it is, in my opinion, the best free image editor. Once you have created your texture drag and drop it into the textures/items package.

Your texture needs to be 1:1 pixel ratio and needs to be a power of 16 (16x16 is recommended because it uses the least memory) other wise it will now work.
You also need to make sure your texture name is the same as name as you referenced in the model json file!

Finally we're finished!  Thank you for following this tutorial, look out for the next tutorial for adding Blocks.
- Mr. Pineapple