From 54db20a623dd99a2519d47a8257bdcec28bc62f3 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 16 Mar 2024 16:09:09 +0000 Subject: [PATCH] Give stable doors their internals back --- .../datagen/providers/BlockModels.java | 2 + .../providers/UBlockStateModelGenerator.java | 77 ++++++++++++++++++- .../unicopia/models/block/door_left.json | 19 +++++ .../unicopia/models/block/door_right.json | 19 +++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/assets/unicopia/models/block/door_left.json create mode 100644 src/main/resources/assets/unicopia/models/block/door_right.json diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/BlockModels.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/BlockModels.java index 90f3f2bb..28c6acd4 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/BlockModels.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/BlockModels.java @@ -30,6 +30,8 @@ public interface BlockModels { Model STRAIGHT_STAIRS = block("seethrough_stairs", TextureKey.BOTTOM, TextureKey.TOP, TextureKey.SIDE, STEP); Model INNER_STAIRS = block("inner_seethrough_stairs", "_inner", TextureKey.BOTTOM, TextureKey.TOP, TextureKey.SIDE, STEP); Model OUTER_STAIRS = block("outer_seethrough_stairs", "_outer", TextureKey.BOTTOM, TextureKey.TOP, TextureKey.SIDE, STEP); + Model DOOR_LEFT = block("door_left", TextureKey.BOTTOM, TextureKey.TOP); + Model DOOR_RIGHT = block("door_right", TextureKey.BOTTOM, TextureKey.TOP); Factory CROP = Factory.of(TextureMap::crop, Models.CROP); Factory CUBE_ALL = Factory.of(TextureMap::all, Models.CUBE_ALL); diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java index fe4b4e18..59bd9502 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UBlockStateModelGenerator.java @@ -18,7 +18,10 @@ import com.minelittlepony.unicopia.server.world.Tree; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import net.minecraft.block.Block; import net.minecraft.block.Blocks; +import net.minecraft.block.enums.DoorHinge; +import net.minecraft.block.enums.DoubleBlockHalf; import net.minecraft.data.client.BlockStateModelGenerator; +import net.minecraft.data.client.BlockStateSupplier; import net.minecraft.data.client.BlockStateVariant; import net.minecraft.data.client.BlockStateVariantMap; import net.minecraft.data.client.Model; @@ -75,7 +78,7 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator { registerAll((g, block) -> g.registerParentedItemModel(block, ModelIds.getBlockModelId(block)), UBlocks.SHAPING_BENCH, UBlocks.SURFACE_CHITIN); registerAll(UBlockStateModelGenerator::registerSimpleState, UBlocks.SHAPING_BENCH, UBlocks.BANANAS); // doors - registerAll(UBlockStateModelGenerator::registerDoor, UBlocks.STABLE_DOOR, UBlocks.DARK_OAK_DOOR, UBlocks.CRYSTAL_DOOR, UBlocks.CLOUD_DOOR); + registerAll(UBlockStateModelGenerator::registerStableDoor, UBlocks.STABLE_DOOR, UBlocks.DARK_OAK_DOOR, UBlocks.CRYSTAL_DOOR, UBlocks.CLOUD_DOOR); // cloud blocks createCustomTexturePool(UBlocks.CLOUD, TexturedModel.CUBE_ALL).same(UBlocks.UNSTABLE_CLOUD).slab(UBlocks.CLOUD_SLAB).stairs(UBlocks.CLOUD_STAIRS); @@ -311,6 +314,78 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator { super.registerBed(bed, particleSource); } + public void registerStableDoor(Block door) { + TextureMap topTextures = TextureMap.topBottom(door); + TextureMap bottomTextures = topTextures.copyAndAdd(TextureKey.TOP, topTextures.getTexture(TextureKey.BOTTOM)); + registerItemModel(door.asItem()); + blockStateCollector.accept(createStableDoorBlockState(door, + BlockModels.DOOR_LEFT.upload(door, "_bottom_left", bottomTextures, modelCollector), + BlockModels.DOOR_RIGHT.upload(door, "_bottom_right", bottomTextures, modelCollector), + BlockModels.DOOR_LEFT.upload(door, "_top_left", topTextures, modelCollector), + BlockModels.DOOR_RIGHT.upload(door, "_top_right", topTextures, modelCollector) + )); + } + + public static BlockStateSupplier createStableDoorBlockState(Block doorBlock, Identifier bottomLeftHingeClosedModelId, Identifier bottomRightHingeClosedModelId, Identifier topLeftHingeClosedModelId, Identifier topRightHingeClosedModelId) { + var variants = BlockStateVariantMap.create(Properties.HORIZONTAL_FACING, Properties.DOUBLE_BLOCK_HALF, Properties.DOOR_HINGE, Properties.OPEN); + fillStableDoorVariantMap(variants, DoubleBlockHalf.LOWER, bottomLeftHingeClosedModelId, bottomRightHingeClosedModelId); + fillStableDoorVariantMap(variants, DoubleBlockHalf.UPPER, topLeftHingeClosedModelId, topRightHingeClosedModelId); + return VariantsBlockStateSupplier.create(doorBlock).coordinate(variants); + } + + public static BlockStateVariantMap.QuadrupleProperty fillStableDoorVariantMap( + BlockStateVariantMap.QuadrupleProperty variantMap, + DoubleBlockHalf targetHalf, Identifier leftModelId, Identifier rightModelId) { + return variantMap + .register(Direction.EAST, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId)) + .register(Direction.SOUTH, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R90)) + .register(Direction.WEST, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R180)) + .register(Direction.NORTH, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R270)) + + .register(Direction.EAST, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId)) + .register(Direction.SOUTH, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R90)) + .register(Direction.WEST, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R180)) + .register(Direction.NORTH, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R270)) + + .register(Direction.EAST, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R90)) + .register(Direction.SOUTH, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R180)) + .register(Direction.WEST, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R270)) + .register(Direction.NORTH, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, rightModelId)) + + .register(Direction.EAST, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R270)) + .register(Direction.SOUTH, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId)) + .register(Direction.WEST, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R90)) + .register(Direction.NORTH, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create() + .put(VariantSettings.MODEL, leftModelId) + .put(VariantSettings.Y, VariantSettings.Rotation.R180)); + } + public void registerHiveBlock(Block hive) { Identifier core = ModelIds.getBlockSubModelId(hive, "_core"); Identifier side = ModelIds.getBlockSubModelId(hive, "_side"); diff --git a/src/main/resources/assets/unicopia/models/block/door_left.json b/src/main/resources/assets/unicopia/models/block/door_left.json new file mode 100644 index 00000000..6c5b0b27 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/door_left.json @@ -0,0 +1,19 @@ +{ + "ambientocclusion": false, + "textures": { + "particle": "#top" + }, + "elements": [ + { "from": [ 0, 0, 0 ], + "to": [ 3, 16, 16 ], + "faces": { + "up": { "uv": [ 13, 0, 16, 16 ], "texture": "#bottom", "cullface": "up" }, + "down": { "uv": [ 13, 0, 16, 16 ], "texture": "#bottom", "cullface": "down" }, + "north": { "uv": [ 3, 0, 0, 16 ], "texture": "#top", "cullface": "north" }, + "south": { "uv": [ 0, 0, 3, 16 ], "texture": "#top", "cullface": "south" }, + "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "cullface": "west" }, + "east": { "uv": [ 16, 0, 0, 16 ], "texture": "#top", "cullface": "east" } + } + } + ] +} diff --git a/src/main/resources/assets/unicopia/models/block/door_right.json b/src/main/resources/assets/unicopia/models/block/door_right.json new file mode 100644 index 00000000..bf096276 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/block/door_right.json @@ -0,0 +1,19 @@ +{ + "ambientocclusion": false, + "textures": { + "particle": "#top" + }, + "elements": [ + { "from": [ 0, 0, 0 ], + "to": [ 3, 16, 16 ], + "faces": { + "up": { "uv": [ 13, 0, 16, 16 ], "texture": "#bottom", "cullface": "up" }, + "down": { "uv": [ 13, 0, 16, 16 ], "texture": "#bottom", "cullface": "down" }, + "north": { "uv": [ 3, 0, 0, 16 ], "texture": "#top", "cullface": "north" }, + "south": { "uv": [ 0, 0, 3, 16 ], "texture": "#top", "cullface": "south" }, + "west": { "uv": [ 16, 0, 0, 16 ], "texture": "#top", "cullface": "west" }, + "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#top", "cullface": "east" } + } + } + ] +}