Minecraft 1.15 modding with forge – 4 – Custom basic item

Hello everyone,

Today I am going to show how to make a custom item, using the DeferredRegister.

The recommended way to register objects like items is through the DeferredRegister system. This way you will not use any annotation magic (@SubscribeEvent, @ObjectHolder) and your mod will automatically work with registry replacements.

You can choose where to put this, but I’ll create a new class for it called ModItems.
In here add a public static final DeferredRegister<Item> field called ITEMS and create a new instance of the DeferredRegister class. The DeferredRegister‘s constructor takes the registry you want to register to, which will be ForgeRegistries.ITEMS in this case, and your modid.

public static final DeferredRegister<Item> ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, TutorialMod.MOD_ID);

Now to register the item itself add another field, this field will also be public static and final but will be of type RegistryObject<Item>. You can name it whatever you want but I recommend naming it after your item’s registry name so it is clear what it is.

Now you can register your item by calling ITEMS#register(String registryName, Supplier<? extends Item> supplier).
The first argument is simple, just your item’s registryName. The registryName has to be all lowercase and can only contain the following characters: a-z 0-9 / . _

The second argument is slightly more complicated. It takes a supplier (for technical reasons related to loading), this can be done in multiple ways but the easiest is to use a lambda. For example:

 () -> new Item(..) 

As you can see you need to create an item in the lambda/supplier. To create an instance of the Item class you need to pass in a Item.Properties instance. You can call methods on this instance to set things like the items creative tab, stacksize and maxDamage.

 public static final RegistryObject<Item> TUTORIAL_DUST = ITEMS.register("tutorial_dust", () -> new Item(new Item.Properties())); 

You may want to access the item instance later again, this is possible! Just reference the field you are creating and call “.get()”.

 ModItems.TUTORIAL_DUST.get() 

Full example:

Now as a last step you need to register your DeferredRegister to forge.
In your main mod’s constructor you can register it by calling ModItems.ITEMS.register() and passing it FMLJavaModLoadingContext.get().getModEventBus() as argument:

 ModItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus()); 

This is technically enough for forge to load the item. When you start the game, and load a world you can give yourself the item with the command: “/give @p modid:itemname”. When you do this you will see that it doesn’t have a model and texture yet. So lets add those right now!

To add a model and texture create a some new folders in src/main/resources called assets/modid. In this folder create models/item  and textures/item.

In textures/item you can add a texture (make sure its size is a power of 2, 16×16, 32×32, etc.). It doesn’t matter what you call it but it has to be lowercase and you have to remember the name. I will call it tutorial_dust.png and I will use this texture:
In the models/item package create a new json file. In the json file add the following json code:

Remember to save it as REGISTRYNAME.json. You have to replace the words in capslock with the corresponding values, REGISTRYNAME should be the same as the item’s registry name. The texture name shouldn’t contain the extension (.png).

You may have noticed that the name isn’t displaying correct. That is because we haven’t added a lang file yet, so lets do that. In assets/modid create a new folder called lang, in this folder create a new json file. In this json file add the following json:

And again, replace the words in caps with your own values. Save this file in the lang package and call it en_us.json.

Now you can start the game and you should have an item with texture and name!

displays the item in an item frame

This would be an example on how to make it stack to max 32 and add it to a creative tab (ItemGroup):

new Item(new Item.Properties().maxStackSize(32).group(ItemGroup.MISC))

Well, that was it for this part! In the next part, we will add a custom block. By clicking here you will be sent to the code of this tutorial.
As always if you have any question don’t hesitate to ask in the comments! Also if you saw any errors in the tutorial please let me know so I can fix it!

~suppergerrie2

Posted in Forge Tutorial 1.15.

9 Comments

  1. Thank you so much! I was looking all over on how to create my item with custom properties and you gave a very straight forward answer! The only thing I was missing was () -> but no way could I have found that out. Thanks again so much

  2. Preface – Brand new to all of this

    “Now as a last step you need to register your DeferredRegister to forge.
    In your main mod’s constructor you can register it by calling ModItems.ITEMS.register() and passing it FMLJavaModLoadingContext.get().getModEventBus() as argument:”

    This is where I am totally lost. Got everything else in there, but where exactly do I drop this code? I looked at your other tutorials but this is the first mention of the ‘Main Mod’s Constructor’.

    Once again, apologies for my ignorance. Thanks in advance!

    • Your main mod file is the file with “@Mod” in my case it is TutorialMod.java, but in your case it can be whatever you named it.

      • Might I get an example of what that looks like? I copied and pasted ModItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus()); in the TutorialMod public class but get multiple errors (Cannot resolve symbol ‘register’, Cannot resolve symbol ‘get’). I am using the latest version of IntelliJ Community.

        I know I am missing something and/or placing this in the wrong spot. Read over tutorial 3 multiple times but couldn’t find a solution to this particular problem. I assume you expect us to know what we are doing to some degree lol.

        Thanks again for your patience!

        • In the last tutorial, we added the method
          “public static void registerItems(RegistryEvent.Register event)”. you should put ModItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus()); in there.

  3. Personally, this line:
    ModItems.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
    didnt work for me for some reason, so instead I used code from the 1.14 tutorial.
    Could you possibly add the imports to that line or something?

    • What exactly did not work?
      The only import needed is import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; but your IDE should be able to do that for you.

Comments are closed.