User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

These pages will help you setup a productive development environment and semi-automated releases.

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

tutorial:datagen_model

Model Generation

You can generate block (with automatic block states) and item models easily using the FabricModelProvider class.

To get started, 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);
}
tutorial/datagen_model.txt · Last modified: 2022/09/14 19:49 by nexus-dino