Minecraft 1.13 modding with forge – 4 – Custom basic block

Hello everyone,

Today we are going to make a custom block, I am going to show you how to register your blocks, register block models and add ItemBlocks.

First, we need to create a class where we are going to register all of our blocks. So inside the init package create a class ModBlocks.

The block we will be creating will be the most basic block possible, it won’t have any special effects.

In the ModBlocks class, we will be instantiating and registering our objects.

Now we need to let forge know we want to register a block, this is done in a RegistryEvent just like for items.
Add a public static method called registerBlocks it has to have an argument of type RegistryEvent.Register<Block> (this is how forge knows to call this method when the event is fired) I’ll refer to this argument as event but a better more descriptive name could be blockRegistryEvent. Above the method add an annotation @SubscribeEvent and above the class, declaration add an annotation @Mod.EventBusSubscriber and set the modid argument to your modid and the bus value to Bus.MOD (In pre 1.13 versions you didn’t need to set the bus, but this changed in 1.13).

  • In the registerBlocks method, you can register the block by calling event.registerAll and passing in a new instance of the Block class.
    To create an instance of the Block class you need to pass in a Block.Properties instance. You can create an instance by calling Block.Properties::create, and you can call methods on this instance to set things like the hardness, light value, etc.
  • Now you also need to set the registry name on for your item, you do this by calling setRegistryName on the block instance and passing in your modid for the first argument, and the item name as the second argument, the name has to be all lowercase and can only contain the following characters: a-z 0-9 / . _
  • We need to access the block instance later again to create an ItemBlock. So add the @ObjectHolder annotation above the class and pass in your modid. Now create a public static final Block variable, the name has to exactly match your item’s registry name (Because it is final you need to set it to null, but forge will set it to your item’s instance). It’s better to use ObjectHolder because people could possibly replace your item, and now you’ll automatically use that replacement.


Now, let’s add the ItemBlock, you do this by instead of instantiating an Item you instantiate the ItemBlock, in here you need to pass in a reference to your block and the Item.Properties you want. (Don’t forget to set the registry name). For more information go to my previous tutorial about items.

In the assets/modid/ folder create a new folder called blockstates, in the model and texture folder you also need to create a block folder.
In the textures/block folder, 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_block.png and I will use this texture:
In the models/block folder create a new JSON file, and add the following JSON:

Of course, you need to replace the words in caps with whatever your values are. The texture name should be without the extension. Save this model, and remember the name (make sure the name is lowercase)

In the blockstates folder create a new JSON file. In the JSON file add the following JSON code:

Remember to save it as NAME.json. You have to replace the words in capslock with the corresponding values, NAME should be the same as the block’s registry name.
Your item also needs a specific model so it looks like a block, you do this by creating a file in the models/item and adding the following JSON:

Make sure the file name matches the registry name!
You may have noticed that the name isn’t displaying correctly. In the lang file (assets/modid/lang/en_us.json) add a new entry, like this:

"block.modid.registryname": "Block Name"

Now you can start the game and you should have a block with texture and name, and an item to place it!

Well, that was it for this part!
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 Deprecated, Forge tutorial, Forge Tutorial 1.13.

19 Comments

  1. When the texture package in resources is present i get a “Unable to create the autoreloaded config” exception when attempting to test the mod. I have triple checked every line to make sure everything is as it should be. You ever had a similar error?

    • Because I have to accept them first. Sadly that is the only way to not have spam on my site. I get about 1 spam comment for every normal comment…

  2. Could you show how to make custom stairs and slabs? I tried stairs and it compiles and runs ok the stairs in the inventory is perfect but when i go to place the stairs block it is just the black and pink cube I have the correct stuff in the blockstate file the correct stuff in the 3 models files stairs, inner_stairs, and outer_stairs file. and 1 model file for the item model. I have one line of code for the ItemBlock registry and one line of code for the Block registry. are there any files I am missing?

    • Post your code (on github), can’t really help without that. Make sure you have a blockstate and the models and they all reference the right files.

      • I finally gotten it to work. I needed to make a custom stairs class and extend BlockStairs. My only problem now is I cant seem to be able to set the harvest tool or level would you have any ideal as to do this in 1.13.2? I use to use this.harvestLevel(“pickaxe”, 3); or something similar to that.

  3. How can I make a translucend / opaque block? The blockItem in hand is translucend but when put down is solid.

    • Create a class that extends Block, and in that class override getRenderLayer and return either CUTOUT, CUTOUT_MIPPED or TRANSLUCENT, depending on your block. (From the javadoc: Gets the render layer this block will render on. SOLID for solid blocks, CUTOUT or CUTOUT_MIPPED for on-off transparency (glass, reeds), TRANSLUCENT for fully blended transparency (stained glass)).

  4. Don you meant just “Block” here?

    “”Now, let’s add the ItemBlock, you do this by instead of instantiating an Item you instantiate the ItemBlock, “”

    I was a tad confused. But keep up the good work! Really been helpfull for me getting started in making a mod!

    • I do mean ItemBlock. The blocks in the world are different from the items in your inventory. Without an ItemBlock you can’t place them without using setblock (Like air). So we register an ItemBlock so the players can actually place the block.

      • Hmm then i dont get where you initiate the ItemBlock.
        Dont you have to declare somewhere to add the ItemBlock?

        The only place in the Git of your file i can see ItemBlock is as a Import. But nowhere else. So i think i am missing something in my understanding how this works.

        But i will try to re-engineer some other mods from 1.13 to see how they do it.
        Thx for the reply!

    • You dont need it for this to work, but if you want to reference it later it can be useful. It is mostly here to show how the object holder works.

      • ok, but then you shouldn’t use a static instantiation anyway. In that case you also don’t need that @ObjectHolder. Just Make a class where all your blocks and items references are and use those references within the registration.

        • I’m confused? I don’t statically initialize the block? I just show how to use the object holder to have a reference to your block. It doesn’t need to be in the ModBlocks class, it can be wherever you want. But I like it there.

  5. This tutorial is great!

    PS: In the “item_block_model.json” you didn’t use the capslock format which could be confusing.

Comments are closed.