Tutorial 3: Basic Items

In this tutorial we will be creating a basic item for minecraft!  Let's begin!

Right-click on com.yourname.yourmodname and go to New > Package.  Name the package core.init and right-click on it, go to New > Class and call the class ItemInit.  Open the class by double-clicking it and you are ready to code an item! 
We need to write some code.  Let's start off by creating a Deferred Registry were we can store all of our items.  We can do this by writing: 
public class ItemInit {

  public static final DeferredRegister ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, HumlandsMod.MOD_ID);
}
This code will create a DeferredRegister of with the default forge ITEMS DeferredRegistry and your Mod ID.  Remember to press Cntl + Shift + O to import everything!  In order to add any basic item, we can write a single line of code!  After the DeferredRegister, add this code: 
public static final RegistryObject EXAMPLE_ITEM = ITEMS.register("example_item",
  () -> new Item(new Item.Properties().group(ItemGroup.MISC)));
This will define our item in the game.  The part in all capitals will be accessible from the code, where as the part in lower case will be accessible from the resources.  The .group(ItemGroup.MISC) is the creative tab in which the item is placed.  You can change this to a different tab, or even make a custom one, but we will do this later.  That's it for the item! 
Now, we need to register the class we main in our main class.  Open the main class, and, in the constructor, after this line: modEventBus.addListener(this::doClientStuff); , add the line: ItemInit.ITEMS.register(bus); .  This will register all the items in your DeferredRegistry into the game!  Remember to press Cntl + Shift + O to import everything!.  Thats it for all the code!. 
All the assets for your mod (blockmodels, lang files, texutures), are in a single folder called assets.  Inside the src/main/resources, create a new package called assets.yourmodid .  Inside there, you want to create the following package structure: 
  1. blockstates
  2. lang
  3. models
    • item
    • block
  4. textures
    • items
    • blocks
It is VERY important to make sure that the files are named EXACTLY right.  Keep in mind that an s at the end of a word can change a lot when it comes to coding! 
Inside the lang package you just made, make an Untitled Text File.  To do this, right click on the package and go to New > Untitled Text File.  In there type: 
{
  "item.yourmodid.example_item": "Example Item"
}
This will make the item show up in game as Example Item and not item.yourmodid.example_item.  Great!  Now we need to save this file.  Press Cntrl + S and then navigate to src > main > resources > assets > yourmodid > lang.  Name the file en_us.json and click OK.  You can make files like this for different languages, but we will be sticking with English-US for now. 
Next, we need to create the model for our item.  In the models > item folder you just made, create a new Untitled Text File by right clicking on the package and going to New > Untitled Text File.  In there, type: 
{
   "parent": "item/generated",
   "textures": {

       "layer0": "yourmodid:items/example_item"
   }
}
That will allow for you item to have a basic model inside the game.  Now we need to save this file.  Press Cntrl + S and then navigate to src > main > resources > assets > yourmodid > models > item.  Name the file the name of your item followed by .json, for example example_item.json, and click OK.  Hang on, we are nearly finished. 
Finally, add the texure. The texture must be a .png file, which is 16x16 pixels in size. Name this file the name of your item followed by .png, for example example_item.png, and place it in src > main > resources > assets > yourmodid > textures > items.  And that is it! You can load up the game and your new item is fully functional! 

That's items done...  Blocks are next!