#Using BlockStateModelGenerator to generate block model with variants

2 messages · Page 1 of 1 (latest)

shrewd ginkgo
#

I was following the tutorial (https://fabricmc.net/wiki/tutorial:datagen_model) to generate block models, but as it says it's incomplete.

In my use case, my block has a block state with a single EnumProperty ("char"), and I have a different texture for each enum. The idea is the block will display a selected character (A-Z, 0-9 or space), I have a texture for each possible character.

Since I will also be making the block directional at some point, and I already have 37 different textures, it seemed best to use the datagen to generate the block state / models rather than do it all manually.

In my FabricModelProvider implementing class, I have this so far generating the block state models:

        public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
            MultipartBlockStateSupplier multiPartBlockStateSupplier = MultipartBlockStateSupplier.create(LargeSignBlock.LARGE_SIGN_BLOCK);
            for (LargeSignCharacter character : LargeSignCharacter.values()) {
                multiPartBlockStateSupplier = multiPartBlockStateSupplier
                    .with(When.create().set(LargeSignBlock.CHAR, character),
                          BlockStateVariant.create().put(
                                    VariantSettings.MODEL, 
                                    character.getIdentifier()));
            }
            blockStateModelGenerator.blockStateCollector.accept(multiPartBlockStateSupplier);
        }

This has generated a blockstate file, that looks correct. Here is the start of it:

{
  "multipart": [
    {
      "apply": {
        "model": "jordanl2:large_sign_space"
      },
      "when": {
        "char": "space"
      }
    },
    {
      "apply": {
        "model": "jordanl2:large_sign_a"
      },
      "when": {
        "char": "a"
      }
    },

However, no models have been generated, and I'm not sure what I'm meant to do next. To start with, I'm fine with just cubes with the selected texture.

shrewd ginkgo
#

I added code into the loop which is now generating the models, seemingly correctly:

        @Override
        public void generateBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
            MultipartBlockStateSupplier multiPartBlockStateSupplier = MultipartBlockStateSupplier.create(LargeSignBlock.LARGE_SIGN_BLOCK);
            
            for (LargeSignCharacter character : LargeSignCharacter.values()) {
                multiPartBlockStateSupplier = multiPartBlockStateSupplier
                    .with(When.create().set(LargeSignBlock.CHAR, character),
                          BlockStateVariant.create().put(
                                  VariantSettings.MODEL, 
                                  character.getIdentifier()));

                Model model = new Model(Optional.of(new Identifier("minecraft", "block/cube_all")),
                        Optional.of("_" + character.asString()),
                        TextureKey.ALL);
                TextureMap textures = new TextureMap();
                textures.put(TextureKey.ALL, character.getIdentifier());
                model.upload(LargeSignBlock.LARGE_SIGN_BLOCK, textures, blockStateModelGenerator.modelCollector);
            }
            
            blockStateModelGenerator.blockStateCollector.accept(multiPartBlockStateSupplier);
        }

Example file:

$ cat src/main/generated/assets/jordanl2/models/block/large_sign_a.json 
{
  "parent": "minecraft:block/cube_all",
  "textures": {
    "all": "jordanl2:large_sign_a"
  }
}

But, still just purple checkerboard textures when I run the game. So, seems the blockstate file is wrong, and I don't know why.

Does anyone even use this datagen system? I've seen no examples of it being used in the wild.