User Tools

Site Tools


tutorial:datagen_model

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
tutorial:datagen_model [2022/09/14 19:49] nexus-dinotutorial:datagen_model [2023/02/20 05:19] – [Addin Data Generation For a Directional Block] solidblock
Line 38: Line 38:
  
 <code java> <code java>
-public static Block SIMPLE_BLOCK = Registry.register(Registry.BLOCK, new Identifier("mymod", "simple_block"), new Block(...)); +public static Block SIMPLE_BLOCK = Registry.register(Registries.BLOCK, new Identifier("tutorial", "simple_block"), new Block(...)); 
-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 ''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. 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.
 +
 +==== 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 ''build.gradle'' to remove the ''-Dfabric-api.datagen.strict-validation'' VM arg from the ''loom {}'' block.
  
 ===== 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("mymod", "simple_block"), new Block(...)); +public static Block SIMPLE_BLOCK = Registry.register(Registries.BLOCK, new Identifier("tutorial", "simple_block"), new Block(...)); 
-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, Models.GENERATED);  itemModelGenerator.register(SIMPLE_BLOCK_ITEM, Models.GENERATED);
 +}
 +</code>
 +
 +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 ''MACHINE_BLOCK''
 +
 +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, new Identifier("tutorial", "machine"), MACHINE_BLOCK);
 +}
 +</code>
 +
 +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(FabricDataGenerator generator) {
 + super(generator);
 + }
 + 
 + @Override
 + public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
 + // ...
 +                blockStateModelGenerator.blockStateCollector.accept(MultipartBlockStateSupplier.create(Tutorial.MACHINE_BLOCK)
 +                          .with(When.create().set(Properties.HORIZONTAL_FACING, Direction.NORTH),
 +                          BlockStateVariant.create().put(VariantSettings.X, VariantSettings.Rotation.X)));
 + }
 + 
 + @Override
 + public void generateItemModels(ItemModelGenerator itemModelGenerator) {
 + // ...
 + }
 } }
 </code> </code>
tutorial/datagen_model.txt · Last modified: 2023/06/05 17:43 by mcrafterzz