From e8fcd4d050acf290ed8fff51bb68d73928b47918 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 23 Dec 2024 21:35:19 +0100 Subject: [PATCH] Fixed bale models --- .../unicopia/block/EdibleBlock.java | 37 +++++++++++++++---- .../UExternalBlockStateModelGenerator.java | 20 +++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java b/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java index e9a9351c4..00f8a3699 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java @@ -32,6 +32,7 @@ import net.minecraft.util.Util; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; import net.minecraft.util.math.Vec3d; import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShapes; @@ -53,15 +54,13 @@ public class EdibleBlock extends HayBlock { // [up/down][north/south][west/east] public static final BooleanProperty[] SEGMENTS = { - BOTTOM_NORTH_WEST, - BOTTOM_NORTH_EAST, - BOTTOM_SOUTH_WEST, - BOTTOM_SOUTH_EAST, - TOP_NORTH_WEST, - TOP_NORTH_EAST, - TOP_SOUTH_WEST, - TOP_SOUTH_EAST + BOTTOM_NORTH_WEST, BOTTOM_NORTH_EAST, + BOTTOM_SOUTH_WEST, BOTTOM_SOUTH_EAST, + + TOP_NORTH_WEST, TOP_NORTH_EAST, + TOP_SOUTH_WEST, TOP_SOUTH_EAST }; + private static final VoxelShape[] SHAPES = { Block.createCuboidShape(0, 0, 0, 8, 8, 8), Block.createCuboidShape(8, 0, 0, 16, 8, 8), @@ -83,6 +82,28 @@ public class EdibleBlock extends HayBlock { return shape == null ? VoxelShapes.fullCube() : shape.simplify(); }); + public static int rotate(Direction.Axis axis, int index) { + Direction x = ((index & 1) == 0 ? Direction.EAST : Direction.WEST).rotateClockwise(axis); + Direction y = ((index & 4) == 0 ? Direction.DOWN : Direction.UP).rotateClockwise(axis); + Direction z = ((index & 2) == 0 ? Direction.NORTH : Direction.SOUTH).rotateClockwise(axis); + return toIndex(x) | toIndex(y) | toIndex(z); + } + + private static int toIndex(Direction direction) { + if (direction.getAxis() == Direction.Axis.X) { + direction = direction.getOpposite(); + } + return direction.getDirection() == Direction.AxisDirection.POSITIVE ? getOffset(direction.getAxis()) : 0; + } + + private static int getOffset(Direction.Axis axis) { + return switch (axis) { + case X -> 1; + case Z -> 2; + case Y -> 4; + }; + } + static void bootstrap() { UseBlockCallback.EVENT.register((PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) -> { if (!Pony.of(player).getSpecies().isEquine() diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UExternalBlockStateModelGenerator.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UExternalBlockStateModelGenerator.java index 3c3309e0c..cfe9b741c 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UExternalBlockStateModelGenerator.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UExternalBlockStateModelGenerator.java @@ -7,7 +7,6 @@ import static net.minecraft.data.client.VariantSettings.Y; import static net.minecraft.data.client.VariantSettings.Rotation.R0; import static net.minecraft.data.client.VariantSettings.Rotation.R90; - import java.util.HashMap; import java.util.Map; import java.util.function.Consumer; @@ -53,14 +52,25 @@ public void registerBale(Identifier blockId, Identifier baseBlockId, String endS for (Direction.Axis axis : Direction.Axis.VALUES) { for (int i = 0; i < EdibleBlock.SEGMENTS.length; i++) { - BooleanProperty segment = EdibleBlock.SEGMENTS[i]; - segment.getName(); + int index = i; + if (axis == Direction.Axis.X) { + index = EdibleBlock.rotate(Direction.Axis.Z, index); + index = EdibleBlock.rotate(Direction.Axis.Z, index); + index = EdibleBlock.rotate(Direction.Axis.Z, index); + index = EdibleBlock.rotate(Direction.Axis.X, index); + } + if (axis == Direction.Axis.Z) { + index = EdibleBlock.rotate(Direction.Axis.X, index); + } + + BooleanProperty segment = EdibleBlock.SEGMENTS[index]; + supplier.with(When.create().set(EdibleBlock.AXIS, axis).set(segment, true), BlockStateVariant.create() .put(MODEL, uploadedModels.computeIfAbsent(i, ii -> { return BlockModels.BALE_MODELS[ii].getLeft().upload(blockId.withPath(p -> "block/" + p + BlockModels.BALE_MODELS[ii].getRight()), textures, modelCollector); })) - .put(X, axis == Direction.Axis.Y ? R0 : R90) - .put(Y, axis == Direction.Axis.X ? R90 : R0) + .put(X, axis == Direction.Axis.Y ? R0 : axis == Direction.Axis.X ? R90 : R90) + .put(Y, axis == Direction.Axis.Y ? R0 : axis == Direction.Axis.X ? R90 : R0) ); } }