tutorial:datagen_model
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorial:datagen_model [2022/08/16 20:07] – created mineblock11 | tutorial:datagen_model [2023/06/05 17:43] (current) – Change to FabricDataOutput mcrafterzz | ||
---|---|---|---|
Line 3: | Line 3: | ||
You can generate block (with automatic block states) and item models easily using the '' | You can generate block (with automatic block states) and item models easily using the '' | ||
- | To create a model generator, create a class that extends '' | + | To get started, create a class that extends '' |
<code java> | <code java> | ||
private static class MyModelGenerator extends FabricModelProvider { | private static class MyModelGenerator extends FabricModelProvider { | ||
- | private MyModelGenerator(FabricDataGenerator | + | private MyModelGenerator(FabricDataOutput |
super(generator); | super(generator); | ||
} | } | ||
Line 38: | Line 38: | ||
<code java> | <code java> | ||
- | public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, new Identifier(" | + | public static Block SIMPLE_BLOCK = Registry.register(Registries.BLOCK, new Identifier(" |
- | public static BlockItem SIMPLE_BLOCK_ITEM = Registry.register(Registry.ITEM, ..., new BlockItem(SIMPLE_BLOCK, | + | public static BlockItem SIMPLE_BLOCK_ITEM = Registry.register(Registries.ITEM, ..., new BlockItem(SIMPLE_BLOCK, |
// ... | // ... | ||
Line 49: | Line 49: | ||
Since a '' | Since a '' | ||
+ | |||
+ | ==== Strict Validation ==== | ||
+ | By default, data generation will throw an exception if the run did not generate blockstates for all blocks belonging to the processed mods. | ||
+ | Fabric API allows disabling this. To do so, edit your '' | ||
===== Adding Item Models ===== | ===== Adding Item Models ===== | ||
Line 57: | Line 61: | ||
<code java> | <code java> | ||
- | public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, new Identifier(" | + | public static Block SIMPLE_BLOCK = Registry.register(Registries.BLOCK, new Identifier(" |
- | public static BlockItem SIMPLE_BLOCK_ITEM = Registry.register(Registry.ITEM, ..., new BlockItem(SIMPLE_BLOCK, | + | public static BlockItem SIMPLE_BLOCK_ITEM = Registry.register(Registries.ITEM, ..., new BlockItem(SIMPLE_BLOCK, |
// ... | // ... | ||
Line 64: | Line 68: | ||
public void generateItemModels(ItemModelGenerator itemModelGenerator) { | public void generateItemModels(ItemModelGenerator itemModelGenerator) { | ||
itemModelGenerator.register(SIMPLE_BLOCK_ITEM, | itemModelGenerator.register(SIMPLE_BLOCK_ITEM, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | FIXME //**This is not done yet!!**// | ||
+ | ==== Addin Data Generation For a Directional Block ==== | ||
+ | **QUICK WARNING**: This is very complicated as heck!!! | ||
+ | |||
+ | In this, example, we will generate directional blockstates for our '' | ||
+ | |||
+ | Firstly, we add the block itself and register it! | ||
+ | <code java> | ||
+ | // In the Tutorial class (or your mod initializer class) | ||
+ | public static final Block MACHINE_BLOCK = new Block(FabricBlockSettings.copy(Blocks.BLAST_FURNACE)); | ||
+ | |||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | Registry.register(Registries.BLOCK, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Now that we have successfully registered our block, let's get to the good stuff! | ||
+ | |||
+ | <code java> | ||
+ | private static class MyModelGenerator extends FabricModelProvider { | ||
+ | private MyModelGenerator(FabricDataOutput generator) { | ||
+ | super(generator); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) { | ||
+ | // ... | ||
+ | blockStateModelGenerator.blockStateCollector.accept(MultipartBlockStateSupplier.create(Tutorial.MACHINE_BLOCK) | ||
+ | .with(When.create().set(Properties.HORIZONTAL_FACING, | ||
+ | BlockStateVariant.create().put(VariantSettings.X, | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void generateItemModels(ItemModelGenerator itemModelGenerator) { | ||
+ | // ... | ||
+ | } | ||
} | } | ||
</ | </ |
tutorial/datagen_model.txt · Last modified: 2023/06/05 17:43 by mcrafterzz