Skip to content

The Registry

SimplyCmd edited this page Feb 14, 2022 · 3 revisions

Blocks and items can be registered easily with a simple system that is contained in FeatherLib. Blocks can be registered with block items in the same line, and generate a simple block state, loot table, and held item model without needing to touch the assets folder.

Usage

The first step is to declare your blocks and/or items.

  public static SimpleItem exampleItem1; exampleItem2; exampleItem3;
  public static SimpleBlock exampleBlock1; exampleBlock2; exampleBlock3;

Then, initialize them in your ModInitializer or in their own function called when you want them to be registered.

exampleItem = new SimpleItem(new Identifier("modid", "example_item"), new Item(new FabricItemSettings().group(ItemGroup.MISC)));
exampleBlock = new SimpleBlock(new Identifier("modid", "example_block"), new Block(FabricBlockSettings.of(Material.STONE))).withItem(SimpleBlock.ItemModel.BLOCK, (block) -> new BlockItem(block, new FabricItemSettings().group(ItemGroup.BUILDING_BLOCKS)));

Custom item or block classes work fine with this system, because SimpleItem and SimpleBlock contain the item and block classes, not extend them.

The SimpleBlock has additional parameters that can be called similarly to FabricBlockSettings. The current parameters are:

  • .defaultBlockstate() generates a default block state that points to your block model.
  • .defaultLootTable() generates a default loot table that makes the block drop itself.

Keep in mind these parameters use your block's id to work.

Examples

This is a simple item registry that adds an item to the game.

public class ExampleItemRegistry {
    public static SimpleItem exampleItem;

    public static void register() {
        exampleItem = new SimpleItem(ID("example_item"), new Item(new FabricItemSettings().group(ItemGroup.MISC)));
    }

    private static Identifier ID(String id) {
        // Your mod ID here
        return new Identifier(FeatherLib.MOD_ID, id);
    }
}

...and this is a simple block registry that adds three blocks to the game.

public class ExampleBlockRegistry {
    public static SimpleBlock firstBlock, secondBlock, thirdBlock;

    public static void register() {
        // Creates a block WITHOUT a block item
        firstBlock = new SimpleBlock(ID("first_block"))

        // Creates a block WITH a block item
        secondBlock = new SimpleBlock(ID("second_block"), new Block(FabricBlockSettings.of(Material.STONE))).withItem(SimpleBlock.ItemModel.BLOCK, (block) -> new BlockItem(block, new FabricItemSettings().group(ItemGroup.BUILDING_BLOCKS)));

        // Creates a block that has some default assets generated (and a block item)
        thirdBlock = new SimpleBlock(ID("third_block"), new Block(FabricBlockSettings.of(Material.STONE))).withItem(SimpleBlock.ItemModel.BLOCK, (block) -> new BlockItem(block, new FabricItemSettings().group(ItemGroup.BUILDING_BLOCKS)))
            .defaultBlockstate()
            .defaultLootTable();
    }

    private static ID ID(String id) {
        // Your mod ID here
        return new ID(FeatherLib.MOD_ID, id);
    }
}

Clone this wiki locally