Jump to content

Data Gen - Block Model from JSON template throws error


than00ber1

Recommended Posts

I am trying to generate my block models with Data Generators which I incounter this error.

 

It's easy to spot why this error occurs ("block/minecraft:sand", ':' triggers the error) but I don't understand where this error could come from by looking at my code.

 

Since I have a few variants of the same block, I've replicated Minecraft's way by defining a template JSON for my variant and simply have my block use it as a parent and add a texture.

Heres what I have:

    private void generateSiltBlockFenceGateFromTemplate(SiltFenceGateBlock gate) {
        String texture = Objects.requireNonNull(gate.getParentBlock().getRegistryName()).toString();

        getVariantBuilder(gate).forAllStatesExcept(state -> {
                String base = "silt_fence_gate" + (state.get(OPEN) ? "_open_" : "_close_") + state.get(AbstractSiltBarrierBlock.LAYER);
                if (state.get(IN_WALL)) base = base + "_in_wall"; 
                // <base> would look like "silt_fence_gate_close_1"

                ModelBuilder<?> model = models()
                        .withExistingParent(texture + "_" + base, modLoc("block/template_" + base))
                        .texture("texture", mcLoc("block/" + texture)) // <--- stacktrace points here
                        .element().end();

                int rotation = (int) state.get(HORIZONTAL_FACING).getHorizontalAngle();
                return ConfiguredModel.builder().modelFile(model).uvLock(true).rotationY(rotation).build();
            },
            WATERLOGGED
        );
    }

 

I've also tried to feed it a texture as a string directly but to no avail:

                        .texture("texture", "block/" + texture) // <--- stacktrace points here

 

What I expect is sand_silt_fence_gate_close_1.json:

{
  "parent": "siltsand:block/template_silt_fence_gate_close_1"
  "textures": {
  	"texture": "sand"
  }
}

 

Here's my template JSON: template_silt_fence_gate_close_1.json:

{
  "parent": "block/block",
  "textures": {
    "particle": "#texture"
  },
  "elements": [
    {
      "from": [ 14, 0, 7 ],
      "to": [ 16, 1, 9 ],
      "faces": {
        "north": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "east":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "south": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "west":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "up":    { "uv": [ 0, 0, 2, 2 ], "texture": "#texture" }
      }
    },
    {
      "from": [ 0, 0, 7 ],
      "to": [ 2, 1, 9 ],
      "faces": {
        "north": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "east":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "south": { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "west":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "up":    { "uv": [ 0, 0, 2, 2 ], "texture": "#texture" }
      }
    },
    {
      "from": [ 2, -1, 7 ],
      "to": [ 14, 0, 9 ],
      "faces": {
        "up":    { "uv": [ 0, 0, 12, 2 ], "texture": "#texture" },
        "north": { "uv": [ 0, 0, 12, 1 ], "texture": "#texture" },
        "south": { "uv": [ 0, 0, 12, 1 ], "texture": "#texture" },
        "west":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "east":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }
      }
    },
    {
      "from": [ 10, -7, 7 ],
      "to": [ 14, -6, 9 ],
      "faces": {
        "up":    { "uv": [ 0, 0, 4, 2 ], "texture": "#texture" },
        "north": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" },
        "south": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" },
        "west":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "east":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }
      }
    },
    {
      "from": [ 2, -7, 7 ],
      "to": [ 6, -6, 9 ],
      "faces": {
        "up":    { "uv": [ 0, 0, 4, 2 ], "texture": "#texture" },
        "north": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" },
        "south": { "uv": [ 0, 0, 4, 1 ], "texture": "#texture" },
        "west":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" },
        "east":  { "uv": [ 0, 0, 2, 1 ], "texture": "#texture" }
      }
    }
  ]
}

I have read that maybe this might be caused by invalid JSON but that has been checked too.

 

Any idea why this happens? 

 

PS: I am new to Data Gens so it is very likely that I using the builder wrong.

Edited by than00ber1
added further explanation
Link to comment
Share on other sites

  • than00ber1 changed the title to Data Gen - Block Model from JSON template throws error

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.