This is an old revision of the document!
Table of Contents
Model Generation
You can generate block (with automatic block states) and item models easily using the FabricModelProvider
class.
To create a model generator, create a class that extends FabricModelProvider
, and register it at your datagen entrypoint like so:
private static class MyModelGenerator extends FabricModelProvider { private MyModelGenerator(FabricDataGenerator generator) { super(generator); } @Override public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) { // ... } @Override public void generateItemModels(ItemModelGenerator itemModelGenerator) { // ... } } // ... @Override public void onInitializeDataGenerator(FabricDataGenerator fabricDataGenerator) { // ... fabricDataGenerator.addProvider(MyModelGenerator::new); // ... }
Adding Block Models
The BlockStateModelGenerator
class contains many methods to create block models, in this example, we will create a block with the same texture on each side, also known as minecraft:block/cube_all
in json.
public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, new Identifier("mymod", "simple_block"), new Block(...)); public static BlockItem SIMPLE_BLOCK_ITEM = Registry.register(Registry.ITEM, ..., new BlockItem(SIMPLE_BLOCK, ...)); // ... @Override public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) { blockStateModelGenerator.registerSimpleCubeAll(SIMPLE_BLOCK); }
Since a BlockItem
for SIMPLE_BLOCK
exists and has been registered, an item model will also be automatically generated that parents the block model. This can be overridden in the generateItemModels
method.
Adding Item Models
The ItemModelGenerator
contains miscellaneous methods to create item models.
In this example, we will override the item model generated from the SIMPLE_BLOCK
block model in the previous example. We will generate an item model from SIMPLE_BLOCK_ITEM
public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, new Identifier("mymod", "simple_block"), new Block(...)); public static BlockItem SIMPLE_BLOCK_ITEM = Registry.register(Registry.ITEM, ..., new BlockItem(SIMPLE_BLOCK, ...)); // ... @Override public void generateItemModels(ItemModelGenerator itemModelGenerator) { itemModelGenerator.register(SIMPLE_BLOCK_ITEM, Models.GENERATED); }