From 8a67be4afdd5d394c7066611dcdbbf0876f94593 Mon Sep 17 00:00:00 2001 From: Nicholas Smit <48810167+AnonymousHacker1279@users.noreply.github.com> Date: Sat, 9 Jul 2022 12:21:06 -0400 Subject: [PATCH] [1.19.x] Fix door datagenerator (#8821) * Fix door datagenerator Fix datagenerator for door blocks. Successor to #8687, addresses comments made there about statement complexity. * Fix extra space around parameter Fix extra space before comma around a parameter. --- .../model/generators/BlockStateProvider.java | 53 ++++++++++++++----- .../model/generators/ModelProvider.java | 26 +++++++-- .../debug/DataGeneratorTest.java | 7 ++- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/minecraftforge/client/model/generators/BlockStateProvider.java b/src/main/java/net/minecraftforge/client/model/generators/BlockStateProvider.java index b9e2ac2292..a279c40501 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/BlockStateProvider.java +++ b/src/main/java/net/minecraftforge/client/model/generators/BlockStateProvider.java @@ -534,29 +534,56 @@ public abstract class BlockStateProvider implements DataProvider { } private void doorBlockInternal(DoorBlock block, String baseName, ResourceLocation bottom, ResourceLocation top) { - ModelFile bottomLeft = models().doorBottomLeft(baseName + "_bottom", bottom, top); - ModelFile bottomRight = models().doorBottomRight(baseName + "_bottom_hinge", bottom, top); - ModelFile topLeft = models().doorTopLeft(baseName + "_top", bottom, top); - ModelFile topRight = models().doorTopRight(baseName + "_top_hinge", bottom, top); - doorBlock(block, bottomLeft, bottomRight, topLeft, topRight); + ModelFile bottomLeft = models().doorBottomLeft(baseName + "_bottom_left", bottom, top); + ModelFile bottomLeftOpen = models().doorBottomLeftOpen(baseName + "_bottom_left_open", bottom, top); + ModelFile bottomRight = models().doorBottomRight(baseName + "_bottom_right", bottom, top); + ModelFile bottomRightOpen = models().doorBottomRightOpen(baseName + "_bottom_right_open", bottom, top); + ModelFile topLeft = models().doorTopLeft(baseName + "_top_left", bottom, top); + ModelFile topLeftOpen = models().doorTopLeftOpen(baseName + "_top_left_open", bottom, top); + ModelFile topRight = models().doorTopRight(baseName + "_top_right", bottom, top); + ModelFile topRightOpen = models().doorTopRightOpen(baseName + "_top_right_open", bottom, top); + doorBlock(block, bottomLeft, bottomLeftOpen, bottomRight, bottomRightOpen, topLeft, topLeftOpen, topRight, topRightOpen); } - public void doorBlock(DoorBlock block, ModelFile bottomLeft, ModelFile bottomRight, ModelFile topLeft, ModelFile topRight) { + public void doorBlock(DoorBlock block, ModelFile bottomLeft, ModelFile bottomLeftOpen, ModelFile bottomRight, ModelFile bottomRightOpen, ModelFile topLeft, ModelFile topLeftOpen, ModelFile topRight, ModelFile topRightOpen) { getVariantBuilder(block).forAllStatesExcept(state -> { int yRot = ((int) state.getValue(DoorBlock.FACING).toYRot()) + 90; - boolean rh = state.getValue(DoorBlock.HINGE) == DoorHingeSide.RIGHT; + boolean right = state.getValue(DoorBlock.HINGE) == DoorHingeSide.RIGHT; boolean open = state.getValue(DoorBlock.OPEN); - boolean right = rh ^ open; + boolean lower = state.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER; if (open) { yRot += 90; } - if (rh && open) { + if (right && open) { yRot += 180; } yRot %= 360; - return ConfiguredModel.builder().modelFile(state.getValue(DoorBlock.HALF) == DoubleBlockHalf.LOWER ? (right ? bottomRight : bottomLeft) : (right ? topRight : topLeft)) - .rotationY(yRot) - .build(); + + ModelFile model = null; + if (lower && right && open) { + model = bottomRightOpen; + } else if (lower && !right && open) { + model = bottomLeftOpen; + } + if (lower && right && !open) { + model = bottomRight; + } else if (lower && !right && !open) { + model = bottomLeft; + } + if (!lower && right && open) { + model = topRightOpen; + } else if (!lower && !right && open) { + model = topLeftOpen; + } + if (!lower && right && !open) { + model = topRight; + } else if (!lower && !right && !open) { + model = topLeft; + } + + return ConfiguredModel.builder().modelFile(model) + .rotationY(yRot) + .build(); }, DoorBlock.POWERED); } @@ -645,4 +672,4 @@ public abstract class BlockStateProvider implements DataProvider { return new ConfiguredModelList(ImmutableList.builder().addAll(this.models).add(models).build()); } } -} +} \ No newline at end of file diff --git a/src/main/java/net/minecraftforge/client/model/generators/ModelProvider.java b/src/main/java/net/minecraftforge/client/model/generators/ModelProvider.java index 014e7f64ab..8bdc3a6f77 100644 --- a/src/main/java/net/minecraftforge/client/model/generators/ModelProvider.java +++ b/src/main/java/net/minecraftforge/client/model/generators/ModelProvider.java @@ -304,19 +304,35 @@ public abstract class ModelProvider> implements DataPr } public T doorBottomLeft(String name, ResourceLocation bottom, ResourceLocation top) { - return door(name, "door_bottom", bottom, top); + return door(name, "door_bottom_left", bottom, top); + } + + public T doorBottomLeftOpen(String name, ResourceLocation bottom, ResourceLocation top) { + return door(name, "door_bottom_left_open", bottom, top); } public T doorBottomRight(String name, ResourceLocation bottom, ResourceLocation top) { - return door(name, "door_bottom_rh", bottom, top); + return door(name, "door_bottom_right", bottom, top); + } + + public T doorBottomRightOpen(String name, ResourceLocation bottom, ResourceLocation top) { + return door(name, "door_bottom_right_open", bottom, top); } public T doorTopLeft(String name, ResourceLocation bottom, ResourceLocation top) { - return door(name, "door_top", bottom, top); + return door(name, "door_top_left", bottom, top); + } + + public T doorTopLeftOpen(String name, ResourceLocation bottom, ResourceLocation top) { + return door(name, "door_top_left_open", bottom, top); } public T doorTopRight(String name, ResourceLocation bottom, ResourceLocation top) { - return door(name, "door_top_rh", bottom, top); + return door(name, "door_top_right", bottom, top); + } + + public T doorTopRightOpen(String name, ResourceLocation bottom, ResourceLocation top) { + return door(name, "door_top_right_open", bottom, top); } public T trapdoorBottom(String name, ResourceLocation texture) { @@ -395,4 +411,4 @@ public abstract class ModelProvider> implements DataPr ResourceLocation loc = model.getLocation(); return generator.getOutputFolder().resolve("assets/" + loc.getNamespace() + "/models/" + loc.getPath() + ".json"); } -} +} \ No newline at end of file diff --git a/src/test/java/net/minecraftforge/debug/DataGeneratorTest.java b/src/test/java/net/minecraftforge/debug/DataGeneratorTest.java index d925acdba5..264f3504e1 100644 --- a/src/test/java/net/minecraftforge/debug/DataGeneratorTest.java +++ b/src/test/java/net/minecraftforge/debug/DataGeneratorTest.java @@ -798,7 +798,7 @@ public class DataGeneratorTest stairsBlock((StairBlock) Blocks.ACACIA_STAIRS, "acacia", mcLoc("block/acacia_planks")); slabBlock((SlabBlock) Blocks.ACACIA_SLAB, ForgeRegistries.BLOCKS.getKey(Blocks.ACACIA_PLANKS), mcLoc("block/acacia_planks")); - // TODO 1.19: fix fenceBlock, wallBlock, doorBlock, and co -SS + // TODO 1.19: fix fenceBlock, wallBlock, and co -SS // fenceBlock((FenceBlock) Blocks.ACACIA_FENCE, "acacia", mcLoc("block/acacia_planks")); fenceGateBlock((FenceGateBlock) Blocks.ACACIA_FENCE_GATE, "acacia", mcLoc("block/acacia_planks")); @@ -806,8 +806,7 @@ public class DataGeneratorTest paneBlock((IronBarsBlock) Blocks.GLASS_PANE, "glass", mcLoc("block/glass"), mcLoc("block/glass_pane_top")); - - // doorBlock((DoorBlock) Blocks.ACACIA_DOOR, "acacia", mcLoc("block/acacia_door_bottom"), mcLoc("block/acacia_door_top")); + doorBlock((DoorBlock) Blocks.ACACIA_DOOR, "acacia", mcLoc("block/acacia_door_bottom"), mcLoc("block/acacia_door_top")); trapdoorBlock((TrapDoorBlock) Blocks.ACACIA_TRAPDOOR, "acacia", mcLoc("block/acacia_trapdoor"), true); trapdoorBlock((TrapDoorBlock) Blocks.OAK_TRAPDOOR, "oak", mcLoc("block/oak_trapdoor"), false); // Test a non-orientable trapdoor @@ -1149,4 +1148,4 @@ public class DataGeneratorTest // So remove modid to match return model.replaceAll("^\\w+:", "minecraft:"); } -} +} \ No newline at end of file