Skip to main content

Blocks

caution

As of 1.2.3, this is outdated. Refer to this test class instead for the time being.

Creating your Block​

Block objects can be created through the BlockBase class.
You can customize your Block from the ground up using FabricBlockSettings, or use the available methods with specific parameters.

public static final Block RUBY_ORE = new BlockBase(Material.STONE, 2.5f, 7.0f, BlockSoundGroup.STONE);

You may also provide a List to which add a Block as soon as its object is created. This can be useful to later register all your blocks, since you'll just have to cycle through its contents.

public static final List<Block> BLOCKS = new ArrayList<>();

public static final Block RUBY_ORE = new BlockBase(BLOCKS, Material.STONE, 2.5f, 7.0f, BlockSoundGroup.STONE);

ItemGroup​

With this Block we can create an ItemGroup, a.k.a. a tab in the creative menu, to which you can add all your blocks and items.

To do so we can utilize the the ItemGroupBase class.

public static final ItemGroup YOURMOD_GROUP = new ItemGroupBase("yourmodid", "itemgroup", RUBY_ORE).group;

Registering​

Registering is done with the RegistryHandler class.

Now we can register this Block and give it an Item form that player can hold in their inventory with registerBlockAndItem().

RegistryHandler.registerBlockAndItem("yourmodid", "ruby_ore", RUBY_ORE, YOURMOD_GROUP);

Result​

Your code should now look something like this:

MyMod.java
public static final Block RUBY_ORE = new BlockBase(Material.STONE, 2.5f, 7.0f, BlockSoundGroup.STONE);

public static final ItemGroup YOURMOD_GROUP = new ItemGroupBase("yourmodid", "itemgroup", RUBY_ORE).group;

@Override
public void onInitialize() {

RegistryHandler.registerBlockAndItem("yourmodid", "ruby_ore", RUBY_ORE, YOURMOD_GROUP);
}