diff --git a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java index 2d14927c3..dc1a2eb44 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java @@ -12,6 +12,7 @@ import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; +import org.apache.commons.lang3.tuple.ImmutablePair; public class VoxelShaper { @@ -68,6 +69,29 @@ public class VoxelShaper { } public static VoxelShaper forDirectional(VoxelShape southShape) { + return forDirectional(southShape, Direction.SOUTH); + } + + + + public static VoxelShaper forDirectional(VoxelShape shape, Direction facing){ + if (facing != Direction.UP) { + ImmutablePair rot = rotationValuesForDirection(facing); + shape = rotatedCopy(shape, 360 - rot.getLeft(), 360 - rot.getRight()); + } + return forDirectionsFacingUp(shape, Direction.values()); + } + + private static VoxelShaper forDirectionsFacingUp(VoxelShape shape, Direction[] directions){ + VoxelShaper voxelShaper = new VoxelShaper(); + for (Direction dir : directions) { + ImmutablePair rotation = rotationValuesForDirection(dir); + voxelShaper.shapes.put(dir, rotatedCopy(shape, rotation.getLeft(), rotation.getRight())); + } + return voxelShaper; + } + + public static VoxelShaper forDirectionalOld(VoxelShape southShape) { VoxelShaper voxelShaper = new VoxelShaper(); for (Direction facing : Direction.values()) { int rotX = facing.getAxis().isVertical() ? (facing == Direction.UP ? 270 : 90) : 0; @@ -83,11 +107,18 @@ public class VoxelShaper { return this; } - private static Direction axisAsFace(Axis axis) { + private static ImmutablePair rotationValuesForDirection(Direction facing) { + //assume facing up as the default rotation + return ImmutablePair.of( + facing == Direction.UP ? 0 : (Direction.Plane.VERTICAL.test(facing) ? 180 : 90), + Direction.Plane.VERTICAL.test(facing) ? 0 : (int) -facing.getHorizontalAngle()); + } + + public static Direction axisAsFace(Axis axis) { return Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis); } - private static VoxelShape rotatedCopy(VoxelShape shape, int rotX, int rotY) { + private static VoxelShape rotatedCopy(VoxelShape shape, int rotationX, int rotationY) { MutableObject result = new MutableObject<>(VoxelShapes.empty()); shape.forEachBox((x1, y1, z1, x2, y2, z2) -> { @@ -95,10 +126,10 @@ public class VoxelShaper { Vec3d v1 = new Vec3d(x1, y1, z1).scale(16).subtract(center); Vec3d v2 = new Vec3d(x2, y2, z2).scale(16).subtract(center); - v1 = VecHelper.rotate(v1, rotX, Axis.X); - v1 = VecHelper.rotate(v1, rotY, Axis.Y).add(center); - v2 = VecHelper.rotate(v2, rotX, Axis.X); - v2 = VecHelper.rotate(v2, rotY, Axis.Y).add(center); + v1 = VecHelper.rotate(v1, rotationX, Axis.X); + v1 = VecHelper.rotate(v1, rotationY, Axis.Y).add(center); + v2 = VecHelper.rotate(v2, rotationX, Axis.X); + v2 = VecHelper.rotate(v2, rotationY, Axis.Y).add(center); VoxelShape rotated = Block.makeCuboidShape(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z); result.setValue(VoxelShapes.or(result.getValue(), rotated)); diff --git a/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java b/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java index db6b7972f..dc15fa602 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java @@ -1,10 +1,45 @@ package com.simibubi.create.foundation.utility; import net.minecraft.block.Block; +import net.minecraft.util.Direction; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.math.shapes.VoxelShapes; + +import static net.minecraft.block.Block.makeCuboidShape; public class VoxelShapers { - public static final VoxelShaper SHORT_CASING = VoxelShaper - .forDirectional(Block.makeCuboidShape(0, 0, 0, 16, 16, 12)); + public static final VoxelShape + LOGISTICAL_CASING_SINGLE_SHAPE = VoxelShapes.or( + makeCuboidShape(0, 0, 0, 16, 2, 16), + makeCuboidShape(1, 1, 1, 15, 15, 15), + makeCuboidShape(0, 14, 0, 16, 16, 16)) + + ; + + private static final VoxelShape + LOGISTICAL_CASING_MIDDLE_SHAPE = VoxelShapes.or( + makeCuboidShape(1,0,1,15,16,15), + makeCuboidShape(0,0,0,2,16,2), + makeCuboidShape(14,0,0,16,16,2), + makeCuboidShape(0,0,14,2,16,16), + makeCuboidShape(14,0,14,16,16,16)), + + LOGISTICAL_CASING_CAP_SHAPE = VoxelShapes.or( + LOGISTICAL_CASING_MIDDLE_SHAPE, + makeCuboidShape(0,0,0,16,2,16)) + + ; + + + + + public static final VoxelShaper + SHORT_CASING = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 12, 16), Direction.UP), + LOGISTICAL_CASING_MIDDLE = VoxelShaper.forDirectional(LOGISTICAL_CASING_MIDDLE_SHAPE, Direction.UP), + LOGISTICAL_CASING_CAP = VoxelShaper.forDirectional(LOGISTICAL_CASING_CAP_SHAPE, Direction.UP) + + ; + } diff --git a/src/main/java/com/simibubi/create/modules/logistics/management/base/LogisticalCasingBlock.java b/src/main/java/com/simibubi/create/modules/logistics/management/base/LogisticalCasingBlock.java index 1adee5cb9..1f823f780 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/management/base/LogisticalCasingBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/management/base/LogisticalCasingBlock.java @@ -11,6 +11,8 @@ import java.util.Set; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IWithTileEntity; +import com.simibubi.create.foundation.utility.VoxelShaper; +import com.simibubi.create.foundation.utility.VoxelShapers; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -48,9 +50,6 @@ public class LogisticalCasingBlock extends Block implements IWithTileEntity PART = EnumProperty.create("part", Part.class); public static final BooleanProperty ACTIVE = BooleanProperty.create("active"); - public static final VoxelShape SINGLE_SHAPE = VoxelShapes.or(makeCuboidShape(0, 0, 0, 16, 2, 16), - makeCuboidShape(1, 1, 1, 15, 15, 15), makeCuboidShape(0, 14, 0, 16, 16, 16)); - public LogisticalCasingBlock() { super(Properties.from(Blocks.DARK_OAK_PLANKS)); setDefaultState(getDefaultState().with(PART, Part.NONE).with(AXIS, Axis.Y).with(ACTIVE, false)); @@ -115,7 +114,20 @@ public class LogisticalCasingBlock extends Block implements IWithTileEntity