Adding a basic Item | mcmod.dev

Tutorials CustomQuests Generator (1.x.x) CustomQuests Wiki (2.x.x)

How does it work?

Since 1.14 a lot of things are handled by events, registering items, blocks, commands and effects are some of these uses. We will be doing this in the 'EventHandler' class we created last tutorial. We will also be creating a static class to store all the block instances in.

Creating the Objects class

As mentioned before, we need a place to store our item instances. Since minecraft only uses one instance of each item, we can can make the variable 'public static final'. I like to make static subclasses just for the sake of readability. In this tutorial we'll be adding a coin.
Below is the full 'Objects' class for now:


        

As you can see, the Item constructor takes an Item.Properties argument, which we're providing a new instance of that class. You can also call some methods it the Item.Properties class, which will change some properties from the default values to the ones provided by you. An example is the '.maxStackSize()' which as you might have guessed, sets the limit of how big a stack (i.e. in your inventory) can be. I'd suggest playing a bit around with it after we're done with this tutorial. Then the only thing left to do here is give it a registry name by calling '.setRegistryName()', and providing it a 'ResourceLocation'. This ResourceLocation should be your modid combined with a unique identifier (this will also be the item name players use when using the /give command for example). A common mistake is using uppercase chars in here, but this ResourceLocation is also bound by the same rules as the modid.

Creating the event subscriber

Now we got the instantiation out of the way, it will be quite easy to register the item itself in the EventHandler class. All we got to do is get the registry from the event, and register the item to that registry.
(Note: The 'Item' in the <> brackets is interchangeable with other registry types)


        

Now you you can run the game and get the item by typing you modid + : + item name, which in our mod's case is '/give @p randomlycreative:item_coin'. As you can see, the item has the oh so beautiful black/pink texture and no pretty name.

Adding localization

Open the 'lang' folder from last time, and create a new file there, call it 'en_us.json'. In this file we will put the english translation for all our items, blocks and other unlocalized strings. The file contains one json object which contains all string keys and string values. The key is structured as follows: "<type>.<modid>.<item_name>". The value is the string that you want to display for that item whenever the language in set to US english.


        

Adding a texture and a model

The last thing left to do is the add a texture and a model for the item, this goes respectively into the 'assets/modid/textures/item' and 'assets/modid/models/item' folders. Put the texture you want in the folder, and name it to your item name. (Note: The texture size should be a multiplicand of 16x16, and the file extension should be .png)

Also create a new json file in the models/items folder, and call it to your item name: 'item_coin.json'. Inside the file, we're specifying a parent model, and the texture we want to apply. The texture name corresponds with the name of the texture in the texture folder, but be smart and keep it simple, use the same names for the model and the texture.


        

If you launch the game, the texture and the name should be good now.