This is an old revision of the document!
Table of Contents
Adding a Block
Introduction
Like items, new blocks are added by most mods. You'll need to create an Item, register it and give it a texture/textures. To add additional behavior to the block you will need a Block class.
Creating a Block
The first step is to create a Block. This can be done by using the Block's constructer that takes in a Block.Settings object, which defines many of the Block's characteristic like hardness and blast resistance. This will create a basic block which won't always be enough, but that will be covered further down.
public class ExampleMod implements ModInitializer
{ // an instance of our new block public static final Block FABRIC_BLOCK = new Block(new Block.Settings().itemGroup(ItemGroup.BUILDING_BLOCKS)); [...] }
Registering a Block
As blocks exist in vanilla, they are registered with the vanilla registry that can be gotten by using Registry.register. The first parameter defines what should be registered, so for blocks its Registry.BLOCK. The second parameter is the name of the block, in the form of an string, it should be of the format modid:name where modid is the id of the mod and name is the block's name. Finally, the third parameter takes in the block that you want to register. This has to be done in the onInitialize method.
public class ExampleMod implements ModInitializer { // block creation […] @Override public void onInitialize() { Registry.register(Registry.BLOCK, "my-mod:fabric_block", FABRIC_BLOCK); } }
Your block can now used ingame by using /setblock ~ ~ ~ modid:name.
Registering a BlockItem
In most cases you want the block to accessable in a creative tab and as an item. To do that use Registry.register again but this time with Registry.ITEM instead of Registry.BLOCK. The name should be the same as the block, the third parameter should be changed tho. Instead of an block instance use new BlockItem(block) Like blocks, this should be done in onInitialize.
public class ExampleMod implements ModInitializer { // block creation […] @Override public void onInitialize() { Registry.register(Registry.ITEM, "my-mod:fabric_block", new BlockItem(FABRIC_BLOCK); } }
Giving your block a texture
As you probably have noticed, the block both in world and in item form is a purple and black checkerboard pattern. This is Minecraft's way to show that the block hasen't got a texture. Texturing a block is more advanced then texturing a item. You will need three files. A blockstate file, a block model file and a item model file (if the block has a blockitem)