From 74721cda9515760516a5e2fb05fbfa7cbf302a76 Mon Sep 17 00:00:00 2001 From: zelophed Date: Sat, 7 Dec 2019 18:38:08 +0100 Subject: [PATCH 1/6] started work on voxel shape refactoring -reworked the belt shapes, still need to revisit for casings Signed-off-by: Zelophed --- .../foundation/utility/VoxelShaper.java | 12 ++ .../contraptions/relays/belt/BeltShapes.java | 201 +++++++++++++----- 2 files changed, 154 insertions(+), 59 deletions(-) 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 41419b239..2d14927c3 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java @@ -15,6 +15,8 @@ import net.minecraft.util.math.shapes.VoxelShapes; public class VoxelShaper { + //big todo lul + private Map shapes = new HashMap<>(); public VoxelShape get(Direction direction) { @@ -46,6 +48,16 @@ public class VoxelShaper { return voxelShaper; } + public static VoxelShaper forVerticalBelt(VoxelShape southBeltShape){ + VoxelShaper voxelShaper = new VoxelShaper(); + for (Direction facing : Direction.values()) { + if (facing.getAxis().isVertical()) + continue; + voxelShaper.shapes.put(facing, rotatedCopy(rotatedCopy(southBeltShape, facing.getAxisDirection() == AxisDirection.NEGATIVE ? 90 : 270, 0),0,(int) -facing.getHorizontalAngle())); + } + return voxelShaper; + } + public static VoxelShaper forRotatedPillar(VoxelShape zShape) { VoxelShaper voxelShaper = new VoxelShaper(); for (Axis axis : Axis.values()) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java index 4b7e5b0a6..f97db8016 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java @@ -16,49 +16,161 @@ import net.minecraft.util.math.shapes.VoxelShapes; public class BeltShapes { - private static final VoxelShape SLOPE_BUILDING_BLOCK_X = makeCuboidShape(5, 5, 1, 11, 11, 15), - SLOPE_BUILDING_BLOCK_Z = makeCuboidShape(1, 5, 5, 15, 11, 11), - CASING_HORIZONTAL = makeCuboidShape(0, 0, 0, 16, 11, 16); + /* + * | hi. i made these comments mostly to help me with creating the shapes. but they should also be able to help you understand what i'm doing here if that's why you came here. cheers + * | + * | belt shape slope south descending + * | generated by makeSlopePart + * | z + * | y 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 | | | | + * | | | | | | | + * | +5 | # | | belt shape flat south ending | belt shape flat south full | + * | +4 | # # | | generated by makeFlatEnding | generated by makeFlatFull | + * | +3 | # # # | z |z |z | + * | +2 | # # # # | 15 14 ... | 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 | 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 | + * | +1 | # # # # # | | | | | | | | | + * | 15 ------+ - - - - - - - - - # # # # # #-- | --+---------- | --+ - - - - - - - - - - - - - - +-- | --+ - - - - - - - - - - - - - - +--- | + * | 14 | # # # # # # # | | | | | | | | | + * | 13 | # # # # # # # # | | | | | | | | | + * | 12 | # # # # # # # # # | | | | # # # # # # # # # # # # # # | | # # # # # # # # # # # # # # # # | + * | 11 | # # # # # # # # # # | | | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 10 | # # # # # # # # # # # | # | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 9 | # # # # # # # # # # # | | # | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 8 | # # # # # # # # # # # | | # | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 7 | # # # # # # # # # # # | | # | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 6 | # # # # # # # # # # # | | # | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 5 # # # # # # # # # # # | | # | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 4 # # # # # # # # # # | | # | # # # # # # # # # # # # # # # # | # # # # # # # # # # # # # # # # | + * | 3 # # # # # # # # # | | # | | # # # # # # # # # # # # # # | | # # # # # # # # # # # # # # # # | + * | 2 # # # # # # # # | | # | | | | | | | + * | 1 # # # # # # # | | # | | | | | | | + * | 0 -------# # # # # # - - - - - - - - - +-- | --#---------- | --+ - - - - - - - - - - - - - - +-- | --+ - - - - - - - - - - - - - - +--- | + * |-1 # # # # # | | | | | | | | | | + * |-2 # # # # | | | | | | | | | | + * |-3 # # # | slice used | | | + * |-4 # # | to create | | | + * |-5 # | the stairs | | | + * | x 1 to 14 | | | | + */ - private static final VoxelShaper SLOPE_END = VoxelShaper.forHorizontal(makeCuboidShape(1, 3, 0, 15, 13, 10)), - SLOPE_TOP_END = VoxelShaper.forHorizontal( - VoxelShapes.or(SLOPE_END.get(Direction.SOUTH), createHalfSlope(Direction.SOUTH, false))), - SLOPE_BOTTOM_END = VoxelShaper.forHorizontal( - VoxelShapes.or(SLOPE_END.get(Direction.SOUTH), createHalfSlope(Direction.SOUTH, true))), - FLAT_STRAIGHT = VoxelShaper.forHorizontalAxis(makeCuboidShape(0, 3, 1, 16, 13, 15)), - VERTICAL_STRAIGHT = VoxelShaper.forHorizontalAxis(makeCuboidShape(1, 0, 3, 15, 16, 13)), - SLOPE_STRAIGHT = VoxelShaper.forHorizontal(createSlope(Direction.SOUTH)), - CASING_TOP_END = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 0, 16, 11, 11)); + /* + * |Belt shapes always consist of 2 halves depending on state. This class generated all shapes for belts facing SOUTH and then uses VoxelShapers to fill the remaining 3 Directions + * |Middle shapes use the same building part in both halved and don't need to be composed + * |some of these shapes could be skipped and easily achieved by rotating other shapes but i left them in for clarity's sake + * | Flat Belts: Sloped Belts: (DESC) (ASC) + * | south half north half south half north half south half north half + * | + * | Middle flat full flat full Middle slope desc slope desc slope asc slope asc + * | End flat end flat full End flat end slope desc flat end slope asc + * | Start flat full flat end Start slope desc flat end slope asc flat end + */ + + //Building parts for the shapes + private static final VoxelShape + SLOPE_DESC_PART = makeSlopePart(false), + SLOPE_ASC_PART = makeSlopePart(true), + FLAT_FULL_PART = makeFlatFull(), + FLAT_END_PART = makeFlatEnding(); + + private static final VoxelShape SOUTH_MASK = makeCuboidShape(0,-5,8,16,16+5,16); + private static final VoxelShape NORTH_MASK = makeCuboidShape(0,-5,0,16,16+5,8); + + //Vertical Shapes + private static final VoxelShaper + VERTICAL_FULL = VoxelShaper.forVerticalBelt(FLAT_FULL_PART), + VERTICAL_END = VoxelShaper.forVerticalBelt(compose(FLAT_END_PART, FLAT_FULL_PART)), + VERTICAL_START = VoxelShaper.forVerticalBelt(compose(FLAT_FULL_PART, FLAT_END_PART)); + //Flat Shapes + private static final VoxelShaper + FLAT_FULL = VoxelShaper.forHorizontalAxis(FLAT_FULL_PART), + FLAT_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, FLAT_FULL_PART)), + FLAT_START = VoxelShaper.forHorizontal(compose(FLAT_FULL_PART, FLAT_END_PART)); + //Sloped Shapes + private static final VoxelShaper + SLOPE_DESC = VoxelShaper.forHorizontal(SLOPE_DESC_PART), + SLOPE_ASC = VoxelShaper.forHorizontal(SLOPE_ASC_PART), + SLOPE_DESC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_DESC_PART)), + SLOPE_DESC_START = VoxelShaper.forHorizontal(compose(SLOPE_DESC_PART, FLAT_END_PART)), + SLOPE_ASC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_ASC_PART)), + SLOPE_ASC_START = VoxelShaper.forHorizontal(compose(SLOPE_ASC_PART, FLAT_END_PART)); + + + + private static VoxelShape compose(VoxelShape southPart, VoxelShape northPart){ + return VoxelShapes.or( + VoxelShapes.combine(SOUTH_MASK, southPart, IBooleanFunction.AND), + VoxelShapes.combine(NORTH_MASK, northPart, IBooleanFunction.AND) + ); + } + + private static VoxelShape makeSlopePart(boolean ascendingInstead) { + VoxelShape slice = makeCuboidShape(1, 0, 16, 15, 11, 15); + VoxelShape result = VoxelShapes.empty(); + + for (int i = 0; i < 16; i++) { + + int yOffset = ascendingInstead ? 10 - i : i - 5; + + result = VoxelShapes.or( + result,//move slice i voxels "right" and i-5 voxels "down" + slice.withOffset(0, yOffset / 16f, -i / 16f)); + } + + return result; + } + + private static VoxelShape makeFlatEnding(){ + return VoxelShapes.or( + makeCuboidShape(1,4,0,15,12,16), + makeCuboidShape(1,3,1,15,13,15) + ); + } + + private static VoxelShape makeFlatFull(){ + return makeCuboidShape(1,3,0,15,13,16); + } + + private static final VoxelShape CASING_HORIZONTAL = makeCuboidShape(0, 0, 0, 16, 11, 16); + //todo still need to remove these two + private static final VoxelShaper CASING_TOP_END = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 0, 16, 11, 11)); public static VoxelShape getShape(BlockState state) { Direction facing = state.get(BeltBlock.HORIZONTAL_FACING); Axis axis = facing.getAxis(); - Axis perpendicularAxis = facing.rotateY().getAxis(); Part part = state.get(BeltBlock.PART); Slope slope = state.get(BeltBlock.SLOPE); - if (slope == Slope.HORIZONTAL) - return FLAT_STRAIGHT.get(perpendicularAxis); - if (slope == Slope.VERTICAL) - return VERTICAL_STRAIGHT.get(axis); - - if (part != Part.MIDDLE && part != Part.PULLEY) { - boolean upward = slope == Slope.UPWARD; - if (part == Part.START) - upward = !upward; - else - facing = facing.getOpposite(); - - return upward ? SLOPE_TOP_END.get(facing) : SLOPE_BOTTOM_END.get(facing); + //vertical + if (slope == Slope.VERTICAL) { + if (part == Part.MIDDLE || part == Part.PULLEY) + return VERTICAL_FULL.get(axis); + //vertical ending + return (part == Part.START ? VERTICAL_START : VERTICAL_END).get(facing); } - if (slope == Slope.DOWNWARD) - facing = facing.getOpposite(); + //flat part + if (slope == Slope.HORIZONTAL) { + if (part == Part.MIDDLE || part == Part.PULLEY) + return FLAT_FULL.get(axis); + //flat ending + return (part == Part.START ? FLAT_START : FLAT_END).get(facing); + } + + //slope + if (part == Part.MIDDLE || part == Part.PULLEY) + return (slope == Slope.DOWNWARD ? SLOPE_DESC : SLOPE_ASC).get(facing); + //sloped ending + if (part == Part.START) + return (slope == Slope.DOWNWARD ? SLOPE_DESC_START : SLOPE_ASC_START).get(facing); + if (part == Part.END) + return (slope == Slope.DOWNWARD ? SLOPE_DESC_END : SLOPE_ASC_END).get(facing); + + //bad state + return VoxelShapes.empty(); - return SLOPE_STRAIGHT.get(facing); } - public static VoxelShape getCasingShape(BlockState state) { + public static VoxelShape getCasingShape(BlockState state) {//todo if (!state.get(BeltBlock.CASING)) return VoxelShapes.empty(); @@ -87,33 +199,4 @@ public class BeltShapes { return CASING_TOP_END.get(facing.getOpposite()); } - protected static VoxelShape createSlope(Direction facing) { - return VoxelShapes.or(createHalfSlope(facing.getOpposite(), false), createHalfSlope(facing, true)); - } - - protected static VoxelShape createHalfSlope(Direction facing, boolean upward) { - VoxelShape shape = VoxelShapes.empty(); - VoxelShape buildingBlock = facing.getAxis() == Axis.X ? SLOPE_BUILDING_BLOCK_X : SLOPE_BUILDING_BLOCK_Z; - Vec3i directionVec = facing.getDirectionVec(); - - int x = directionVec.getX(); - int y = upward ? 1 : -1; - int z = directionVec.getZ(); - - for (int segment = 0; segment < 6; segment++) - shape = VoxelShapes.or(shape, - buildingBlock.withOffset(x * segment / 16f, y * segment / 16f, z * segment / 16f)); - - if (!upward) - return shape; - - VoxelShape mask = makeCuboidShape(0, -8, 0, 16, 24, 16); - for (int segment = 6; segment < 11; segment++) - shape = VoxelShapes.or(shape, - VoxelShapes.combine(mask, - buildingBlock.withOffset(x * segment / 16f, y * segment / 16f, z * segment / 16f), - IBooleanFunction.AND)); - return shape; - } - } From 6fb24e0d861b43205e70c289c62911ea78375903 Mon Sep 17 00:00:00 2001 From: zelophed Date: Sun, 8 Dec 2019 02:23:19 +0100 Subject: [PATCH 2/6] improved shape for logistical casing some changes to voxel shaper Signed-off-by: Zelophed --- .../foundation/utility/VoxelShaper.java | 43 ++++++++++++++++--- .../foundation/utility/VoxelShapers.java | 39 ++++++++++++++++- .../base/LogisticalCasingBlock.java | 20 +++++++-- 3 files changed, 90 insertions(+), 12 deletions(-) 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 Date: Mon, 9 Dec 2019 20:43:30 +0100 Subject: [PATCH 3/6] refactor to VoxelShaper VoxelShaper is more flexible now belt tunnel shape reworked Signed-off-by: Zelophed --- .../foundation/utility/VoxelShaper.java | 116 ++++++++---------- .../foundation/utility/VoxelShapers.java | 4 +- .../receivers/HarvesterBlock.java | 6 +- .../contraptions/relays/belt/BeltShapes.java | 36 +++--- .../relays/belt/BeltTunnelBlock.java | 8 +- .../relays/belt/BeltTunnelShapes.java | 99 +++++++++------ 6 files changed, 135 insertions(+), 134 deletions(-) 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 dc1a2eb44..751d75c3c 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java @@ -1,7 +1,9 @@ package com.simibubi.create.foundation.utility; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; +import java.util.function.Function; import org.apache.commons.lang3.mutable.MutableObject; @@ -12,12 +14,9 @@ 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 { - //big todo lul - private Map shapes = new HashMap<>(); public VoxelShape get(Direction direction) { @@ -28,108 +27,76 @@ public class VoxelShaper { return shapes.get(axisAsFace(axis)); } - public static VoxelShaper forHorizontal(VoxelShape southShape) { - VoxelShaper voxelShaper = new VoxelShaper(); - for (Direction facing : Direction.values()) { - if (facing.getAxis().isVertical()) - continue; - voxelShaper.shapes.put(facing, rotatedCopy(southShape, 0, (int) -facing.getHorizontalAngle())); - } - return voxelShaper; + public static VoxelShaper forHorizontal(VoxelShape shape, Direction facing){ + shape = rotateUp(shape, facing); + return forDirectionsWithRotation(shape, Direction.Plane.HORIZONTAL, new DefaultRotationValues()); } - public static VoxelShaper forHorizontalAxis(VoxelShape zShape) { - VoxelShaper voxelShaper = new VoxelShaper(); - for (Axis axis : Axis.values()) { - if (axis.isVertical()) - continue; - Direction facing = axisAsFace(axis); - voxelShaper.shapes.put(facing, rotatedCopy(zShape, 0, (int) -facing.getHorizontalAngle())); - } - return voxelShaper; + public static VoxelShaper forHorizontalAxis(VoxelShape shape, Direction facing){ + shape = rotateUp(shape, facing); + return forDirectionsWithRotation(shape, Arrays.asList(Direction.SOUTH, Direction.EAST), new DefaultRotationValues()); } - public static VoxelShaper forVerticalBelt(VoxelShape southBeltShape){ - VoxelShaper voxelShaper = new VoxelShaper(); - for (Direction facing : Direction.values()) { - if (facing.getAxis().isVertical()) - continue; - voxelShaper.shapes.put(facing, rotatedCopy(rotatedCopy(southBeltShape, facing.getAxisDirection() == AxisDirection.NEGATIVE ? 90 : 270, 0),0,(int) -facing.getHorizontalAngle())); - } - return voxelShaper; - } - - public static VoxelShaper forRotatedPillar(VoxelShape zShape) { + public static VoxelShaper forRotatedPillar(VoxelShape zShape) {//dunno what this was intended for VoxelShaper voxelShaper = new VoxelShaper(); for (Axis axis : Axis.values()) { Direction facing = axisAsFace(axis); - voxelShaper.shapes.put(facing, rotatedCopy(zShape, 0, (int) -facing.getHorizontalAngle())); + voxelShaper.shapes.put(facing, rotatedCopy(zShape, new Vec3d(0, (int) -facing.getHorizontalAngle(),0))); } return 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()); + shape = rotateUp(shape, facing); + return forDirectionsWithRotation(shape, Arrays.asList(Direction.values()), new DefaultRotationValues()); } - private static VoxelShaper forDirectionsFacingUp(VoxelShape shape, Direction[] directions){ + protected static VoxelShaper forDirectionsWithRotation(VoxelShape shape, Iterable directions, Function rotationValues){ 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; - int rotY = facing.getAxis().isVertical() ? 0 : (int) -facing.getHorizontalAngle(); - voxelShaper.shapes.put(facing, rotatedCopy(southShape, rotX, rotY)); + voxelShaper.shapes.put(dir, rotatedCopy(shape, rotationValues.apply(dir))); } return voxelShaper; } public VoxelShaper withVerticalShapes(VoxelShape upShape) { shapes.put(Direction.UP, upShape); - shapes.put(Direction.DOWN, rotatedCopy(upShape, 180, 0)); + shapes.put(Direction.DOWN, rotatedCopy(upShape, new Vec3d(0, 180, 0))); return this; } - 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 VoxelShaper withShape(VoxelShape shape, Direction facing){ + shapes.put(facing, shape); + return this; } public static Direction axisAsFace(Axis axis) { return Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis); } - private static VoxelShape rotatedCopy(VoxelShape shape, int rotationX, int rotationY) { + private static VoxelShape rotateUp(VoxelShape shape, Direction facing){ + if (facing != Direction.UP) { + Vec3d rot = new DefaultRotationValues().apply(facing); + shape = rotatedCopy(shape, new Vec3d(360, 360,360).subtract(rot)); + } + return shape; + } + + protected static VoxelShape rotatedCopy(VoxelShape shape, Vec3d rotation){ MutableObject result = new MutableObject<>(VoxelShapes.empty()); + Vec3d center = new Vec3d(8, 8, 8); shape.forEachBox((x1, y1, z1, x2, y2, z2) -> { - Vec3d center = new Vec3d(8, 8, 8); 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, 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); + v1 = VecHelper.rotate(v1, (float) rotation.x, Axis.X); + v1 = VecHelper.rotate(v1, (float) rotation.y, Axis.Y); + v1 = VecHelper.rotate(v1, (float) rotation.z, Axis.Z).add(center); + + v2 = VecHelper.rotate(v2, (float) rotation.x, Axis.X); + v2 = VecHelper.rotate(v2, (float) rotation.y, Axis.Y); + v2 = VecHelper.rotate(v2, (float) rotation.z, Axis.Z).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)); @@ -138,4 +105,17 @@ public class VoxelShaper { return result.getValue(); } + protected static class DefaultRotationValues implements Function { + + //assume facing up as the default rotation + @Override + public Vec3d apply(Direction direction) { + return new Vec3d( + direction == Direction.UP ? 0 : (Direction.Plane.VERTICAL.test(direction) ? 180 : 90), + Direction.Plane.VERTICAL.test(direction) ? 0 : (int) -direction.getHorizontalAngle(), + 0 + ); + } + } + } 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 dc15fa602..0ee627436 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java @@ -1,6 +1,5 @@ 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; @@ -37,7 +36,8 @@ public class VoxelShapers { 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) + LOGISTICAL_CASING_CAP = VoxelShaper.forDirectional(LOGISTICAL_CASING_CAP_SHAPE, Direction.UP), + HARVESTER_BASE = VoxelShaper.forHorizontal(makeCuboidShape(0, 2, 0, 16, 14, 3), Direction.SOUTH) ; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java index e8b06b775..ff88c8168 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/HarvesterBlock.java @@ -5,7 +5,7 @@ import java.util.List; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IRenderUtilityBlock; import com.simibubi.create.foundation.utility.SuperByteBuffer; -import com.simibubi.create.foundation.utility.VoxelShaper; +import com.simibubi.create.foundation.utility.VoxelShapers; import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior; import net.minecraft.block.Block; @@ -39,8 +39,6 @@ import net.minecraftforge.common.IPlantable; public class HarvesterBlock extends HorizontalBlock implements IHaveMovementBehavior { - private static VoxelShaper SHAPER = VoxelShaper.forHorizontal(Block.makeCuboidShape(0, 2, 0, 16, 14, 3)); - public HarvesterBlock() { super(Properties.from(Blocks.IRON_BLOCK)); } @@ -63,7 +61,7 @@ public class HarvesterBlock extends HorizontalBlock implements IHaveMovementBeha @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { Direction direction = state.get(HORIZONTAL_FACING); - return SHAPER.get(direction); + return VoxelShapers.HARVESTER_BASE.get(direction); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java index f97db8016..deec31fcf 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java @@ -9,7 +9,7 @@ import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope; import net.minecraft.block.BlockState; import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; -import net.minecraft.util.math.Vec3i; +import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; @@ -77,22 +77,22 @@ public class BeltShapes { //Vertical Shapes private static final VoxelShaper - VERTICAL_FULL = VoxelShaper.forVerticalBelt(FLAT_FULL_PART), - VERTICAL_END = VoxelShaper.forVerticalBelt(compose(FLAT_END_PART, FLAT_FULL_PART)), - VERTICAL_START = VoxelShaper.forVerticalBelt(compose(FLAT_FULL_PART, FLAT_END_PART)); + VERTICAL_FULL = VerticalBeltShaper.make(FLAT_FULL_PART), + VERTICAL_END = VerticalBeltShaper.make(compose(FLAT_END_PART, FLAT_FULL_PART)), + VERTICAL_START = VerticalBeltShaper.make(compose(FLAT_FULL_PART, FLAT_END_PART)); //Flat Shapes private static final VoxelShaper - FLAT_FULL = VoxelShaper.forHorizontalAxis(FLAT_FULL_PART), - FLAT_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, FLAT_FULL_PART)), - FLAT_START = VoxelShaper.forHorizontal(compose(FLAT_FULL_PART, FLAT_END_PART)); + FLAT_FULL = VoxelShaper.forHorizontalAxis(FLAT_FULL_PART, Direction.SOUTH), + FLAT_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, FLAT_FULL_PART), Direction.SOUTH), + FLAT_START = VoxelShaper.forHorizontal(compose(FLAT_FULL_PART, FLAT_END_PART), Direction.SOUTH); //Sloped Shapes private static final VoxelShaper - SLOPE_DESC = VoxelShaper.forHorizontal(SLOPE_DESC_PART), - SLOPE_ASC = VoxelShaper.forHorizontal(SLOPE_ASC_PART), - SLOPE_DESC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_DESC_PART)), - SLOPE_DESC_START = VoxelShaper.forHorizontal(compose(SLOPE_DESC_PART, FLAT_END_PART)), - SLOPE_ASC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_ASC_PART)), - SLOPE_ASC_START = VoxelShaper.forHorizontal(compose(SLOPE_ASC_PART, FLAT_END_PART)); + SLOPE_DESC = VoxelShaper.forHorizontal(SLOPE_DESC_PART, Direction.SOUTH), + SLOPE_ASC = VoxelShaper.forHorizontal(SLOPE_ASC_PART, Direction.SOUTH), + SLOPE_DESC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_DESC_PART), Direction.SOUTH), + SLOPE_DESC_START = VoxelShaper.forHorizontal(compose(SLOPE_DESC_PART, FLAT_END_PART), Direction.SOUTH), + SLOPE_ASC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_ASC_PART), Direction.SOUTH), + SLOPE_ASC_START = VoxelShaper.forHorizontal(compose(SLOPE_ASC_PART, FLAT_END_PART), Direction.SOUTH); @@ -132,7 +132,7 @@ public class BeltShapes { private static final VoxelShape CASING_HORIZONTAL = makeCuboidShape(0, 0, 0, 16, 11, 16); //todo still need to remove these two - private static final VoxelShaper CASING_TOP_END = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 0, 16, 11, 11)); + private static final VoxelShaper CASING_TOP_END = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 0, 16, 11, 11), Direction.SOUTH); public static VoxelShape getShape(BlockState state) { Direction facing = state.get(BeltBlock.HORIZONTAL_FACING); @@ -199,4 +199,12 @@ public class BeltShapes { return CASING_TOP_END.get(facing.getOpposite()); } + private static class VerticalBeltShaper extends VoxelShaper { + + public static VoxelShaper make(VoxelShape southBeltShape){ + return forDirectionsWithRotation(southBeltShape, Direction.Plane.HORIZONTAL,//idk, this can probably be improved :S + direction -> new Vec3d(direction.getAxisDirection() == Direction.AxisDirection.NEGATIVE ? 90 : 270, -direction.getHorizontalAngle(), 0)); + } + } + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java index bf21c7118..40e919e34 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltTunnelBlock.java @@ -58,13 +58,7 @@ public class BeltTunnelBlock extends Block implements IWithTileEntity Date: Tue, 10 Dec 2019 02:23:34 +0100 Subject: [PATCH 4/6] moved most shapes to central AllShapes class also some more changes to voxelshaper :) Signed-off-by: Zelophed --- .../create/foundation/utility/AllShapes.java | 94 +++++++++++++++++++ .../foundation/utility/VoxelShaper.java | 52 ++++++---- .../foundation/utility/VoxelShapers.java | 45 --------- .../contraptions/generators/MotorBlock.java | 9 +- .../contraptions/receivers/BasinBlock.java | 5 +- .../receivers/CrushingWheelBlock.java | 5 +- .../contraptions/receivers/DrillBlock.java | 4 +- .../receivers/HarvesterBlock.java | 4 +- .../receivers/MechanicalMixerBlock.java | 3 +- .../receivers/MechanicalPressBlock.java | 5 +- .../contraptions/receivers/SawBlock.java | 4 +- .../receivers/TurntableBlock.java | 7 +- .../mounted/CartAssemblerBlock.java | 9 +- .../piston/MechanicalPistonBlock.java | 45 +-------- .../piston/MechanicalPistonHeadBlock.java | 35 +------ .../constructs/piston/PistonPoleBlock.java | 14 +-- .../contraptions/relays/CogWheelBlock.java | 20 +--- .../contraptions/relays/ShaftBlock.java | 7 +- .../contraptions/relays/belt/BeltBlock.java | 2 +- .../contraptions/relays/belt/BeltShapes.java | 10 +- .../modules/economy/ShopShelfBlock.java | 2 +- .../logistics/block/RedstoneBridgeBlock.java | 25 +---- .../block/belts/BeltFunnelBlock.java | 21 +---- .../logistics/block/belts/ExtractorBlock.java | 17 +--- .../block/inventories/FlexcrateBlock.java | 5 +- .../base/LogisticalCasingBlock.java | 9 +- .../base/LogisticalControllerBlock.java | 24 +---- .../index/LogisticalIndexBlock.java | 21 +---- .../villager/LogisticiansTableBlock.java | 46 +-------- .../villager/PackageFunnelBlock.java | 26 +---- .../schematics/block/CreativeCrateBlock.java | 11 +-- 31 files changed, 198 insertions(+), 388 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/AllShapes.java delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java diff --git a/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java new file mode 100644 index 000000000..b9f1cfa32 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java @@ -0,0 +1,94 @@ +package com.simibubi.create.foundation.utility; + +import net.minecraft.block.Blocks; +import net.minecraft.block.DirectionalBlock; +import net.minecraft.block.PistonHeadBlock; +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 AllShapes { + + public static final VoxelShaper + SHORT_CASING = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 12, 16), Direction.UP), + HARVESTER_BASE = VoxelShaper.forHorizontal(makeCuboidShape(0, 2, 0, 16, 14, 3), Direction.SOUTH), + MOTOR_BLOCK = VoxelShaper.forHorizontal(makeCuboidShape(0, 3, 3, 16, 13, 13), Direction.EAST), + FOUR_VOXEL_POLE = VoxelShaper.forDirectionalAxis(makeCuboidShape(6, 0, 6, 10, 16, 10), Direction.Axis.Y), + SIX_VOXEL_POLE = VoxelShaper.forDirectionalAxis(makeCuboidShape(5, 0, 5, 11, 16, 11), Direction.Axis.Y), + BELT_FUNNEL = VoxelShaper.forHorizontal(makeCuboidShape(3, -4, 11, 13, 8, 17), Direction.SOUTH), + BELT_EXTRACTOR = VoxelShaper.forHorizontal(makeCuboidShape(4, 2, 11, 12, 10, 17), Direction.SOUTH) + + ; + + 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)), + CART_ASSEMBLER_SHAPE = VoxelShapes.or( + VoxelShapes.fullCube(), + makeCuboidShape(-2, 0, 1, 18, 13, 15)), + MECHANICAL_PISTON_HEAD_SHAPE_UP = Blocks.PISTON_HEAD.getShape(Blocks.PISTON_HEAD.getStateContainer().getBaseState().with(DirectionalBlock.FACING, Direction.UP).with(PistonHeadBlock.SHORT, true), null, null, null), + MECHANICAL_PISTON_EXTENDED_SHAPE_UP = VoxelShapes.or( + SHORT_CASING.get(Direction.UP), + FOUR_VOXEL_POLE.get(Direction.Axis.Y)), + SMALL_GEAR_SHAPE = makeCuboidShape(2, 6, 2, 14, 10, 14), + LARGE_GEAR_SHAPE = makeCuboidShape(0, 6, 0, 16, 10, 16), + VERTICAL_TABLET_SHAPE_SOUTH = makeCuboidShape(3, 1, -1, 13, 15, 3), + SQUARE_TABLET_SHAPE_SOUTH = makeCuboidShape(2, 2, -1, 14, 14, 3), + PACKAGE_FUNNEL_SHAPE_UP = makeCuboidShape(1, -1, 1, 15, 3, 15), + TABLE_POLE_SHAPE = VoxelShapes.or( + makeCuboidShape(4, 0, 4, 12, 2, 12), + makeCuboidShape(5, 2, 5, 11, 14, 11)), + LOGISTICS_TABLE_SLOPE_SOUTH = VoxelShapes.or( + makeCuboidShape(0, 10D, 15, 16, 14, 10.667), + makeCuboidShape(0, 12, 10.667, 16, 16, 6.333), + makeCuboidShape(0, 14, 6.333, 16, 18, 2)) + + ; + + 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)), + BASIN_BLOCK_SHAPE = makeCuboidShape(0, 0, 0, 16, 13, 16),//todo maybe + CRUSHING_WHEEL_COLLISION_SHAPE = makeCuboidShape(0, 0, 0, 16, 22, 16), + MECHANICAL_PRESS_SHAPE = VoxelShapes.fullCube(),//todo maybe + TURNTABLE_SHAPE = VoxelShapes.or( + makeCuboidShape(1, 6, 1, 15, 8, 15), + makeCuboidShape(5, 0, 5, 11, 6, 11)), + CRATE_BLOCK_SHAPE = makeCuboidShape(1, 0, 1, 15, 14, 15), + LOGISTICS_TABLE_BASE = TABLE_POLE_SHAPE + + ; + + + + + public static final VoxelShaper + LOGISTICAL_CASING_MIDDLE = VoxelShaper.forDirectional(LOGISTICAL_CASING_MIDDLE_SHAPE, Direction.UP), + LOGISTICAL_CASING_CAP = VoxelShaper.forDirectional(LOGISTICAL_CASING_CAP_SHAPE, Direction.UP), + CART_ASSEMBLER = VoxelShaper.forHorizontalAxis(CART_ASSEMBLER_SHAPE, Direction.SOUTH), + MECHANICAL_PISTON_HEAD = VoxelShaper.forDirectional(MECHANICAL_PISTON_HEAD_SHAPE_UP, Direction.UP), + MECHANICAL_PISTON = SHORT_CASING, + MECHANICAL_PISTON_EXTENDED = VoxelShaper.forDirectional(MECHANICAL_PISTON_EXTENDED_SHAPE_UP, Direction.UP), + SMALL_GEAR = VoxelShaper.forDirectionalAxis(VoxelShapes.or(SMALL_GEAR_SHAPE, SIX_VOXEL_POLE.get(Direction.Axis.Y)), Direction.Axis.Y), + LARGE_GEAR = VoxelShaper.forDirectionalAxis(VoxelShapes.or(LARGE_GEAR_SHAPE, SIX_VOXEL_POLE.get(Direction.Axis.Y)), Direction.Axis.Y), + LOGISTICAL_CONTROLLER = VoxelShaper.forDirectional(SQUARE_TABLET_SHAPE_SOUTH, Direction.SOUTH), + REDSTONE_BRIDGE = VoxelShaper.forHorizontal(VERTICAL_TABLET_SHAPE_SOUTH, Direction.SOUTH).withVerticalShapes(LOGISTICAL_CONTROLLER.get(Direction.UP)), + LOGISTICAL_INDEX = REDSTONE_BRIDGE, + PACKAGE_FUNNEL = VoxelShaper.forDirectional(PACKAGE_FUNNEL_SHAPE_UP, Direction.UP), + LOGISTICS_TABLE = VoxelShaper.forHorizontal(VoxelShapes.or(TABLE_POLE_SHAPE, LOGISTICS_TABLE_SLOPE_SOUTH), Direction.SOUTH) + + ; + + +} 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 751d75c3c..73ad591af 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java @@ -28,13 +28,11 @@ public class VoxelShaper { } public static VoxelShaper forHorizontal(VoxelShape shape, Direction facing){ - shape = rotateUp(shape, facing); - return forDirectionsWithRotation(shape, Direction.Plane.HORIZONTAL, new DefaultRotationValues()); + return forDirectionsWithRotation(shape, facing, Direction.Plane.HORIZONTAL, new HorizontalRotationValues()); } public static VoxelShaper forHorizontalAxis(VoxelShape shape, Direction facing){ - shape = rotateUp(shape, facing); - return forDirectionsWithRotation(shape, Arrays.asList(Direction.SOUTH, Direction.EAST), new DefaultRotationValues()); + return forDirectionsWithRotation(shape, facing, Arrays.asList(Direction.SOUTH, Direction.EAST), new HorizontalRotationValues()); } public static VoxelShaper forRotatedPillar(VoxelShape zShape) {//dunno what this was intended for @@ -47,21 +45,16 @@ public class VoxelShaper { } public static VoxelShaper forDirectional(VoxelShape shape, Direction facing){ - shape = rotateUp(shape, facing); - return forDirectionsWithRotation(shape, Arrays.asList(Direction.values()), new DefaultRotationValues()); + return forDirectionsWithRotation(shape, facing, Arrays.asList(Direction.values()), new DefaultRotationValues()); } - protected static VoxelShaper forDirectionsWithRotation(VoxelShape shape, Iterable directions, Function rotationValues){ - VoxelShaper voxelShaper = new VoxelShaper(); - for (Direction dir : directions) { - voxelShaper.shapes.put(dir, rotatedCopy(shape, rotationValues.apply(dir))); - } - return voxelShaper; + public static VoxelShaper forDirectionalAxis(VoxelShape shape, Axis along){ + return forDirectionsWithRotation(shape, axisAsFace(along), Arrays.asList(Direction.SOUTH, Direction.EAST, Direction.UP), new DefaultRotationValues()); } public VoxelShaper withVerticalShapes(VoxelShape upShape) { shapes.put(Direction.UP, upShape); - shapes.put(Direction.DOWN, rotatedCopy(upShape, new Vec3d(0, 180, 0))); + shapes.put(Direction.DOWN, rotatedCopy(upShape, new Vec3d(180, 0, 0))); return this; } @@ -74,15 +67,26 @@ public class VoxelShaper { return Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis); } - private static VoxelShape rotateUp(VoxelShape shape, Direction facing){ - if (facing != Direction.UP) { - Vec3d rot = new DefaultRotationValues().apply(facing); - shape = rotatedCopy(shape, new Vec3d(360, 360,360).subtract(rot)); + protected static VoxelShaper forDirectionsWithRotation(VoxelShape shape, Direction facing, Iterable directions, Function rotationValues){ + VoxelShaper voxelShaper = new VoxelShaper(); + for (Direction dir : directions) { + voxelShaper.shapes.put(dir, rotate(shape, facing, dir, rotationValues)); + //voxelShaper.shapes.put(dir, rotatedCopy(shape, rotationValues.apply(dir))); } - return shape; + return voxelShaper; + } + + protected static VoxelShape rotate(VoxelShape shape, Direction from, Direction to, Function usingValues){ + if (from == to) + return shape; + + return rotatedCopy(shape, usingValues.apply(from).inverse().add(usingValues.apply(to))); } protected static VoxelShape rotatedCopy(VoxelShape shape, Vec3d rotation){ + if (rotation.equals(Vec3d.ZERO)) + return shape; + MutableObject result = new MutableObject<>(VoxelShapes.empty()); Vec3d center = new Vec3d(8, 8, 8); @@ -106,7 +110,6 @@ public class VoxelShaper { } protected static class DefaultRotationValues implements Function { - //assume facing up as the default rotation @Override public Vec3d apply(Direction direction) { @@ -118,4 +121,15 @@ public class VoxelShaper { } } + protected static class HorizontalRotationValues implements Function { + @Override + public Vec3d apply(Direction direction) { + return new Vec3d( + 0, + -direction.getHorizontalAngle(), + 0 + ); + } + } + } diff --git a/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java b/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java deleted file mode 100644 index 0ee627436..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.simibubi.create.foundation.utility; - -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 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), - HARVESTER_BASE = VoxelShaper.forHorizontal(makeCuboidShape(0, 2, 0, 16, 14, 3), Direction.SOUTH) - - ; - - -} diff --git a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java index 78c66b271..de43e9ee1 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.generators; import com.simibubi.create.foundation.block.IBlockWithScrollableValue; import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock; import net.minecraft.block.BlockState; @@ -19,11 +20,7 @@ import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.World; -public class MotorBlock extends HorizontalKineticBlock - implements IWithTileEntity, IBlockWithScrollableValue { - - protected static final VoxelShape MOTOR_X = makeCuboidShape(0, 3, 3, 16, 13, 13); - protected static final VoxelShape MOTOR_Z = makeCuboidShape(3, 3, 0, 13, 13, 16); +public class MotorBlock extends HorizontalKineticBlock implements IWithTileEntity, IBlockWithScrollableValue { private static final Vec3d valuePos = new Vec3d(15 / 16f, 5 / 16f, 5 / 16f); @@ -33,7 +30,7 @@ public class MotorBlock extends HorizontalKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return state.get(HORIZONTAL_FACING).getAxis() == Axis.X ? MOTOR_X : MOTOR_Z; + return AllShapes.MOTOR_BLOCK.get(state.get(HORIZONTAL_FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/BasinBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/BasinBlock.java index 850d049de..d7cad991e 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/BasinBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/BasinBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.receivers; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IWithTileEntity; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -25,8 +26,6 @@ import net.minecraftforge.items.ItemStackHandler; public class BasinBlock extends Block implements IWithTileEntity { - public static final VoxelShape SHAPE = makeCuboidShape(0, 0, 0, 16, 13, 16); - public BasinBlock() { super(Properties.from(Blocks.ANDESITE)); } @@ -85,7 +84,7 @@ public class BasinBlock extends Block implements IWithTileEntity, IBeltAttachment { - public static VoxelShape SHAPE = makeCuboidShape(0, 0, 0, 16, 16, 16); - public MechanicalPressBlock() { super(Properties.from(Blocks.PISTON)); } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return SHAPE; + return AllShapes.MECHANICAL_PRESS_SHAPE; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java index c4015e7b8..623f9a614 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java @@ -1,7 +1,7 @@ package com.simibubi.create.modules.contraptions.receivers; import com.simibubi.create.foundation.block.IWithTileEntity; -import com.simibubi.create.foundation.utility.VoxelShapers; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock; import com.simibubi.create.modules.contraptions.receivers.constructs.IHaveMovementBehavior; import com.simibubi.create.modules.logistics.block.IBlockWithFilter; @@ -82,7 +82,7 @@ public class SawBlock extends DirectionalAxisKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return VoxelShapers.SHORT_CASING.get(state.get(FACING)); + return AllShapes.SHORT_CASING.get(state.get(FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java index 4f4bdfeff..190b7d107 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/TurntableBlock.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.contraptions.receivers; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.modules.contraptions.base.KineticBlock; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; @@ -23,10 +24,6 @@ import net.minecraft.world.World; public class TurntableBlock extends KineticBlock { - protected static final VoxelShape SHAPE = VoxelShapes.or( - Block.makeCuboidShape(1.0D, 6.0D, 1.0D, 15.0D, 8.0D, 15.0D), - Block.makeCuboidShape(5.0D, 0.0D, 5.0D, 11.0D, 6.0D, 11.0D)); - public TurntableBlock() { super(Properties.from(Blocks.STRIPPED_SPRUCE_LOG)); } @@ -38,7 +35,7 @@ public class TurntableBlock extends KineticBlock { @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return SHAPE; + return AllShapes.TURNTABLE_SHAPE; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/CartAssemblerBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/CartAssemblerBlock.java index e81dd354a..19d63280f 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/CartAssemblerBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/mounted/CartAssemblerBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs.mounted; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.RenderUtilityBlock; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.AbstractRailBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockState; @@ -17,6 +18,7 @@ import net.minecraft.state.IProperty; import net.minecraft.state.StateContainer.Builder; import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.state.properties.RailShape; +import net.minecraft.util.Direction; import net.minecraft.util.Direction.Axis; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.ISelectionContext; @@ -31,9 +33,6 @@ public class CartAssemblerBlock extends AbstractRailBlock { RailShape.NORTH_SOUTH); public static BooleanProperty POWERED = BlockStateProperties.POWERED; - public static VoxelShape X_SHAPE = VoxelShapes.or(VoxelShapes.fullCube(), makeCuboidShape(1, 0, -2, 15, 13, 18)); - public static VoxelShape Z_SHAPE = VoxelShapes.or(VoxelShapes.fullCube(), makeCuboidShape(-2, 0, 1, 18, 13, 15)); - public CartAssemblerBlock() { super(true, Properties.from(Blocks.PISTON)); setDefaultState(getDefaultState().with(POWERED, false)); @@ -118,7 +117,7 @@ public class CartAssemblerBlock extends AbstractRailBlock { @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return state.get(RAIL_SHAPE) == RailShape.EAST_WEST ? X_SHAPE : Z_SHAPE; + return AllShapes.CART_ASSEMBLER.get(state.get(RAIL_SHAPE) == RailShape.NORTH_SOUTH ? Direction.Axis.Z : Direction.Axis.X); } @Override @@ -126,7 +125,7 @@ public class CartAssemblerBlock extends AbstractRailBlock { ISelectionContext context) { if (context.getEntity() instanceof AbstractMinecartEntity) return VoxelShapes.empty(); - return VoxelShapes.fullCube(); + return getShape(state, worldIn, pos, context); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonBlock.java index 6dcf88bcb..d65b563a3 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonBlock.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateConfig; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock; @@ -33,20 +34,6 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock { public static final EnumProperty STATE = EnumProperty.create("state", PistonState.class); - protected static final VoxelShape BASE_SHAPE_UP = makeCuboidShape(0, 0, 0, 16, 12, 16), - BASE_SHAPE_DOWN = makeCuboidShape(0, 4, 0, 16, 16, 16), - BASE_SHAPE_EAST = makeCuboidShape(0, 0, 0, 12, 16, 16), - BASE_SHAPE_WEST = makeCuboidShape(4, 0, 0, 16, 16, 16), - BASE_SHAPE_SOUTH = makeCuboidShape(0, 0, 0, 16, 16, 12), - BASE_SHAPE_NORTH = makeCuboidShape(0, 0, 4, 16, 16, 16), - - EXTENDED_SHAPE_UP = VoxelShapes.or(BASE_SHAPE_UP, MechanicalPistonHeadBlock.AXIS_SHAPE_Y), - EXTENDED_SHAPE_DOWN = VoxelShapes.or(BASE_SHAPE_DOWN, MechanicalPistonHeadBlock.AXIS_SHAPE_Y), - EXTENDED_SHAPE_EAST = VoxelShapes.or(BASE_SHAPE_EAST, MechanicalPistonHeadBlock.AXIS_SHAPE_X), - EXTENDED_SHAPE_WEST = VoxelShapes.or(BASE_SHAPE_WEST, MechanicalPistonHeadBlock.AXIS_SHAPE_X), - EXTENDED_SHAPE_SOUTH = VoxelShapes.or(BASE_SHAPE_SOUTH, MechanicalPistonHeadBlock.AXIS_SHAPE_Z), - EXTENDED_SHAPE_NORTH = VoxelShapes.or(BASE_SHAPE_NORTH, MechanicalPistonHeadBlock.AXIS_SHAPE_Z); - protected boolean isSticky; public MechanicalPistonBlock(boolean sticky) { @@ -155,36 +142,10 @@ public class MechanicalPistonBlock extends DirectionalAxisKineticBlock { public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { if (state.get(STATE) == PistonState.EXTENDED) - switch (state.get(FACING)) { - case DOWN: - return EXTENDED_SHAPE_DOWN; - case EAST: - return EXTENDED_SHAPE_EAST; - case NORTH: - return EXTENDED_SHAPE_NORTH; - case SOUTH: - return EXTENDED_SHAPE_SOUTH; - case UP: - return EXTENDED_SHAPE_UP; - case WEST: - return EXTENDED_SHAPE_WEST; - } + return AllShapes.MECHANICAL_PISTON_EXTENDED.get(state.get(FACING)); if (state.get(STATE) == PistonState.MOVING) - switch (state.get(FACING)) { - case DOWN: - return BASE_SHAPE_DOWN; - case EAST: - return BASE_SHAPE_EAST; - case NORTH: - return BASE_SHAPE_NORTH; - case SOUTH: - return BASE_SHAPE_SOUTH; - case UP: - return BASE_SHAPE_UP; - case WEST: - return BASE_SHAPE_WEST; - } + return AllShapes.MECHANICAL_PISTON.get(state.get(FACING)); return VoxelShapes.fullCube(); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonHeadBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonHeadBlock.java index 549b35823..bc07eaa50 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonHeadBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/MechanicalPistonHeadBlock.java @@ -4,6 +4,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.IWithoutBlockItem; import com.simibubi.create.foundation.block.ProperDirectionalBlock; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState; import net.minecraft.block.Block; @@ -28,22 +29,6 @@ public class MechanicalPistonHeadBlock extends ProperDirectionalBlock implements public static final EnumProperty TYPE = BlockStateProperties.PISTON_TYPE; - public static final VoxelShape AXIS_SHAPE_X = makeCuboidShape(0, 6, 6, 16, 10, 10), - AXIS_SHAPE_Y = makeCuboidShape(6, 0, 6, 10, 16, 10), AXIS_SHAPE_Z = makeCuboidShape(6, 6, 0, 10, 10, 16), - - TOP_SHAPE_UP = makeCuboidShape(0, 12, 0, 16, 16, 16), TOP_SHAPE_DOWN = makeCuboidShape(0, 0, 0, 16, 4, 16), - TOP_SHAPE_EAST = makeCuboidShape(12, 0, 0, 16, 16, 16), - TOP_SHAPE_WEST = makeCuboidShape(0, 0, 0, 4, 16, 16), - TOP_SHAPE_SOUTH = makeCuboidShape(0, 0, 12, 16, 16, 16), - TOP_SHAPE_NORTH = makeCuboidShape(0, 0, 0, 16, 16, 4), - - EXTENSION_SHAPE_UP = VoxelShapes.or(AXIS_SHAPE_Y, TOP_SHAPE_UP), - EXTENSION_SHAPE_DOWN = VoxelShapes.or(AXIS_SHAPE_Y, TOP_SHAPE_DOWN), - EXTENSION_SHAPE_EAST = VoxelShapes.or(AXIS_SHAPE_X, TOP_SHAPE_EAST), - EXTENSION_SHAPE_WEST = VoxelShapes.or(AXIS_SHAPE_X, TOP_SHAPE_WEST), - EXTENSION_SHAPE_SOUTH = VoxelShapes.or(AXIS_SHAPE_Z, TOP_SHAPE_SOUTH), - EXTENSION_SHAPE_NORTH = VoxelShapes.or(AXIS_SHAPE_Z, TOP_SHAPE_NORTH); - public MechanicalPistonHeadBlock() { super(Properties.from(Blocks.PISTON_HEAD)); } @@ -95,22 +80,6 @@ public class MechanicalPistonHeadBlock extends ProperDirectionalBlock implements @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - - switch (state.get(FACING)) { - case DOWN: - return EXTENSION_SHAPE_DOWN; - case EAST: - return EXTENSION_SHAPE_EAST; - case NORTH: - return EXTENSION_SHAPE_NORTH; - case SOUTH: - return EXTENSION_SHAPE_SOUTH; - case UP: - return EXTENSION_SHAPE_UP; - case WEST: - return EXTENSION_SHAPE_WEST; - } - - return VoxelShapes.empty(); + return AllShapes.MECHANICAL_PISTON_HEAD.get(state.get(FACING)); } } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonPoleBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonPoleBlock.java index 5a9cbb1be..7c266e950 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonPoleBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/piston/PistonPoleBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs.piston; import com.simibubi.create.AllBlocks; import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.ProperDirectionalBlock; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.contraptions.receivers.constructs.piston.MechanicalPistonBlock.PistonState; import net.minecraft.block.BlockState; @@ -16,7 +17,6 @@ import net.minecraft.util.Direction.AxisDirection; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; @@ -73,17 +73,7 @@ public class PistonPoleBlock extends ProperDirectionalBlock { @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - - switch (state.get(FACING).getAxis()) { - case X: - return MechanicalPistonHeadBlock.AXIS_SHAPE_X; - case Y: - return MechanicalPistonHeadBlock.AXIS_SHAPE_Y; - case Z: - return MechanicalPistonHeadBlock.AXIS_SHAPE_Z; - } - - return VoxelShapes.empty(); + return AllShapes.FOUR_VOXEL_POLE.get(state.get(FACING).getAxis()); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java index 4760ba5b8..d5dab9245 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/CogWheelBlock.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.contraptions.relays; import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.contraptions.base.IRotate; import net.minecraft.block.Block; @@ -21,14 +22,6 @@ public class CogWheelBlock extends ShaftBlock { private boolean isLarge; - protected static final VoxelShape GEAR_X = makeCuboidShape(6, 2, 2, 10, 14, 14); - protected static final VoxelShape GEAR_Y = makeCuboidShape(2, 6, 2, 14, 10, 14); - protected static final VoxelShape GEAR_Z = makeCuboidShape(2, 2, 6, 14, 14, 10); - - protected static final VoxelShape LARGE_GEAR_X = makeCuboidShape(6, 0, 0, 10, 16, 16); - protected static final VoxelShape LARGE_GEAR_Y = makeCuboidShape(0, 6, 0, 16, 10, 16); - protected static final VoxelShape LARGE_GEAR_Z = makeCuboidShape(0, 0, 6, 16, 16, 10); - public CogWheelBlock(boolean large) { super(Properties.from(Blocks.GRANITE)); isLarge = large; @@ -36,7 +29,7 @@ public class CogWheelBlock extends ShaftBlock { @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return VoxelShapes.or(super.getShape(state, worldIn, pos, context), getGearShape(state)); + return (isLarge ? AllShapes.LARGE_GEAR : AllShapes.SMALL_GEAR).get(state.get(AXIS)); } @Override @@ -65,15 +58,6 @@ public class CogWheelBlock extends ShaftBlock { return getDefaultState().with(AXIS, ((IRotate) block).getRotationAxis(placedAgainst)); } - private VoxelShape getGearShape(BlockState state) { - if (state.get(AXIS) == Axis.X) - return isLarge ? LARGE_GEAR_X : GEAR_X; - if (state.get(AXIS) == Axis.Z) - return isLarge ? LARGE_GEAR_Z : GEAR_Z; - - return isLarge ? LARGE_GEAR_Y : GEAR_Y; - } - @Override public float getParticleTargetRadius() { return isLarge ? 1.125f : .65f; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java index 2b0ac3921..b7c9e805f 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/ShaftBlock.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.contraptions.relays; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.contraptions.base.RotatedPillarKineticBlock; import net.minecraft.block.BlockState; @@ -14,10 +15,6 @@ import net.minecraft.world.World; public class ShaftBlock extends RotatedPillarKineticBlock { - public static final VoxelShape AXIS_X = makeCuboidShape(0, 5, 5, 16, 11, 11); - public static final VoxelShape AXIS_Y = makeCuboidShape(5, 0, 5, 11, 16, 11); - public static final VoxelShape AXIS_Z = makeCuboidShape(5, 5, 0, 11, 11, 16); - public ShaftBlock(Properties properties) { super(properties); } @@ -34,7 +31,7 @@ public class ShaftBlock extends RotatedPillarKineticBlock { @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return state.get(AXIS) == Axis.X ? AXIS_X : state.get(AXIS) == Axis.Z ? AXIS_Z : AXIS_Y; + return AllShapes.SIX_VOXEL_POLE.get(state.get(AXIS)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 20ae90803..330d3e976 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -55,7 +55,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt public static final IProperty SLOPE = EnumProperty.create("slope", Slope.class); public static final IProperty PART = EnumProperty.create("part", Part.class); public static final BooleanProperty CASING = BooleanProperty.create("casing"); - private final VoxelShape collisionMask = makeCuboidShape(0, 0, 0, 16, 19, 16); + private final VoxelShape collisionMask = makeCuboidShape(0, 0, 0, 16, 19, 16);//todo review public BeltBlock() { super(Properties.from(Blocks.BROWN_WOOL)); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java index deec31fcf..8949f892d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java @@ -202,8 +202,14 @@ public class BeltShapes { private static class VerticalBeltShaper extends VoxelShaper { public static VoxelShaper make(VoxelShape southBeltShape){ - return forDirectionsWithRotation(southBeltShape, Direction.Plane.HORIZONTAL,//idk, this can probably be improved :S - direction -> new Vec3d(direction.getAxisDirection() == Direction.AxisDirection.NEGATIVE ? 90 : 270, -direction.getHorizontalAngle(), 0)); + return forDirectionsWithRotation( + rotatedCopy(southBeltShape, new Vec3d(-90,0,0)), + Direction.SOUTH, + Direction.Plane.HORIZONTAL,//idk, this can probably be improved :S + direction -> new Vec3d( + direction.getAxisDirection() == Direction.AxisDirection.POSITIVE ? 0 : 180, + -direction.getHorizontalAngle(), + 0)); } } diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java index 06b9f0823..14bc2c021 100644 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java +++ b/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java @@ -25,7 +25,7 @@ import net.minecraftforge.fml.network.NetworkHooks; public class ShopShelfBlock extends HorizontalBlock implements IWithoutBlockItem { - public static final VoxelShape TOP_SHAPE = makeCuboidShape(0, 14, 0, 16, 16, 16); + public static final VoxelShape TOP_SHAPE = makeCuboidShape(0, 14, 0, 16, 16, 16);//todo review public static final VoxelShape BODY_SOUTH_SHAPE = makeCuboidShape(0, 0, 0, 16, 14, 14); public static final VoxelShape BODY_NORTH_SHAPE = makeCuboidShape(0, 0, 2, 16, 14, 16); diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeBlock.java index a3fa142de..63621665a 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/RedstoneBridgeBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.logistics.block; import java.util.ArrayList; import java.util.List; +import com.simibubi.create.foundation.utility.AllShapes; import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.foundation.block.ProperDirectionalBlock; @@ -37,13 +38,6 @@ public class RedstoneBridgeBlock extends ProperDirectionalBlock implements IBloc public static final BooleanProperty RECEIVER = BooleanProperty.create("receiver"); private static final List> itemPositions = new ArrayList<>(Direction.values().length); - public static final VoxelShape UP_SHAPE = makeCuboidShape(2, 0, 2, 14, 3, 14), - DOWN_SHAPE = makeCuboidShape(2, 13, 2, 14, 16, 14); - - public static final VoxelShape SOUTH_SHAPE = makeCuboidShape(3, 1, -1, 13, 15, 3), - NORTH_SHAPE = makeCuboidShape(3, 1, 13, 13, 15, 17), EAST_SHAPE = makeCuboidShape(-1, 1, 3, 3, 15, 13), - WEST_SHAPE = makeCuboidShape(13, 1, 3, 17, 15, 13); - public RedstoneBridgeBlock() { super(Properties.from(Blocks.DARK_OAK_LOG)); cacheItemPositions(); @@ -174,22 +168,7 @@ public class RedstoneBridgeBlock extends ProperDirectionalBlock implements IBloc @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - Direction facing = state.get(FACING); - - if (facing == Direction.UP) - return UP_SHAPE; - if (facing == Direction.DOWN) - return DOWN_SHAPE; - if (facing == Direction.EAST) - return EAST_SHAPE; - if (facing == Direction.WEST) - return WEST_SHAPE; - if (facing == Direction.NORTH) - return NORTH_SHAPE; - if (facing == Direction.SOUTH) - return SOUTH_SHAPE; - - return VoxelShapes.empty(); + return AllShapes.REDSTONE_BRIDGE.get(state.get(FACING)); } private void cacheItemPositions() { diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/belts/BeltFunnelBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/belts/BeltFunnelBlock.java index 4919c99f6..b08f2fc43 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/belts/BeltFunnelBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/belts/BeltFunnelBlock.java @@ -6,6 +6,7 @@ import java.util.List; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IWithTileEntity; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.BeltAttachmentState; import com.simibubi.create.modules.contraptions.relays.belt.AllBeltAttachments.IBeltAttachment; @@ -38,12 +39,7 @@ import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public class BeltFunnelBlock extends HorizontalBlock - implements IBeltAttachment, IWithTileEntity, IBlockWithFilter { - - public static final VoxelShape SHAPE_NORTH = makeCuboidShape(3, -4, -1, 13, 8, 5), - SHAPE_SOUTH = makeCuboidShape(3, -4, 11, 13, 8, 17), SHAPE_WEST = makeCuboidShape(-1, -4, 3, 5, 8, 13), - SHAPE_EAST = makeCuboidShape(11, -4, 3, 17, 8, 13); +public class BeltFunnelBlock extends HorizontalBlock implements IBeltAttachment, IWithTileEntity, IBlockWithFilter { public BeltFunnelBlock() { super(Properties.from(Blocks.ANDESITE)); @@ -105,18 +101,7 @@ public class BeltFunnelBlock extends HorizontalBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - Direction facing = state.get(HORIZONTAL_FACING); - - if (facing == Direction.EAST) - return SHAPE_EAST; - if (facing == Direction.WEST) - return SHAPE_WEST; - if (facing == Direction.SOUTH) - return SHAPE_SOUTH; - if (facing == Direction.NORTH) - return SHAPE_NORTH; - - return VoxelShapes.empty(); + return AllShapes.BELT_FUNNEL.get(state.get(HORIZONTAL_FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorBlock.java index b666ef189..797a94759 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/belts/ExtractorBlock.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import com.simibubi.create.AllBlocks; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.VecHelper; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock; import com.simibubi.create.modules.logistics.block.IBlockWithFilter; @@ -35,9 +36,6 @@ import net.minecraft.world.World; public class ExtractorBlock extends HorizontalBlock implements IBlockWithFilter { public static BooleanProperty POWERED = BlockStateProperties.POWERED; - public static final VoxelShape SHAPE_NORTH = makeCuboidShape(4, 2, -1, 12, 10, 5), - SHAPE_SOUTH = makeCuboidShape(4, 2, 11, 12, 10, 17), SHAPE_WEST = makeCuboidShape(-1, 2, 4, 5, 10, 12), - SHAPE_EAST = makeCuboidShape(11, 2, 4, 17, 10, 12); private static final List itemPositions = new ArrayList<>(Direction.values().length); public ExtractorBlock() { @@ -150,18 +148,7 @@ public class ExtractorBlock extends HorizontalBlock implements IBlockWithFilter @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - Direction facing = state.get(HORIZONTAL_FACING); - - if (facing == Direction.EAST) - return SHAPE_EAST; - if (facing == Direction.WEST) - return SHAPE_WEST; - if (facing == Direction.SOUTH) - return SHAPE_SOUTH; - if (facing == Direction.NORTH) - return SHAPE_NORTH; - - return VoxelShapes.empty(); + return AllShapes.BELT_EXTRACTOR.get(state.get(HORIZONTAL_FACING)); } private void cacheItemPositions() { diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateBlock.java b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateBlock.java index e264502d7..70429e440 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/inventories/FlexcrateBlock.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.logistics.block.inventories; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -18,15 +19,13 @@ import net.minecraftforge.fml.network.NetworkHooks; public class FlexcrateBlock extends Block { - public static final VoxelShape SHAPE = makeCuboidShape(1, 0, 1, 15, 14, 15); - public FlexcrateBlock() { super(Properties.from(Blocks.ANDESITE)); } @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return SHAPE; + return AllShapes.CRATE_BLOCK_SHAPE; } @Override 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 1f823f780..f6a855bbf 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 @@ -12,7 +12,7 @@ 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 com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -33,7 +33,6 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; import net.minecraft.world.IBlockReader; @@ -117,16 +116,16 @@ public class LogisticalCasingBlock extends Block implements IWithTileEntity TYPE = EnumProperty.create("type", Type.class); - public static final VoxelShape UP_SHAPE = makeCuboidShape(2, -1, 2, 14, 3, 14), - DOWN_SHAPE = makeCuboidShape(2, 13, 2, 14, 17, 14), SOUTH_SHAPE = makeCuboidShape(2, 2, -1, 14, 14, 3), - NORTH_SHAPE = makeCuboidShape(2, 2, 13, 14, 14, 17), EAST_SHAPE = makeCuboidShape(-1, 2, 2, 3, 14, 14), - WEST_SHAPE = makeCuboidShape(13, 2, 2, 17, 14, 14); - public LogisticalControllerBlock() { super(Properties.from(Blocks.PISTON)); } @@ -271,22 +266,7 @@ public class LogisticalControllerBlock extends DirectionalBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - Direction facing = state.get(FACING); - - if (facing == Direction.UP) - return UP_SHAPE; - if (facing == Direction.DOWN) - return DOWN_SHAPE; - if (facing == Direction.EAST) - return EAST_SHAPE; - if (facing == Direction.WEST) - return WEST_SHAPE; - if (facing == Direction.NORTH) - return NORTH_SHAPE; - if (facing == Direction.SOUTH) - return SOUTH_SHAPE; - - return VoxelShapes.empty(); + return AllShapes.LOGISTICAL_CONTROLLER.get(state.get(FACING)); } public static class LogisticalControllerIndicatorBlock extends RenderUtilityBlock { diff --git a/src/main/java/com/simibubi/create/modules/logistics/management/index/LogisticalIndexBlock.java b/src/main/java/com/simibubi/create/modules/logistics/management/index/LogisticalIndexBlock.java index 6a48ae56d..1e57ce11c 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/management/index/LogisticalIndexBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/management/index/LogisticalIndexBlock.java @@ -4,6 +4,7 @@ import com.simibubi.create.AllItems; import com.simibubi.create.foundation.block.IBlockWithColorHandler; import com.simibubi.create.foundation.block.IWithTileEntity; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -29,12 +30,7 @@ import net.minecraft.world.IWorldReader; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; -public class LogisticalIndexBlock extends HorizontalBlock - implements IBlockWithColorHandler, IWithTileEntity { - - public static final VoxelShape SOUTH_SHAPE = makeCuboidShape(3, 1, -1, 13, 15, 3), - NORTH_SHAPE = makeCuboidShape(3, 1, 13, 13, 15, 17), EAST_SHAPE = makeCuboidShape(-1, 1, 3, 3, 15, 13), - WEST_SHAPE = makeCuboidShape(13, 1, 3, 17, 15, 13); +public class LogisticalIndexBlock extends HorizontalBlock implements IBlockWithColorHandler, IWithTileEntity { public LogisticalIndexBlock() { super(Properties.from(Blocks.GRANITE)); @@ -126,18 +122,7 @@ public class LogisticalIndexBlock extends HorizontalBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - Direction facing = state.get(HORIZONTAL_FACING); - - if (facing == Direction.EAST) - return EAST_SHAPE; - if (facing == Direction.WEST) - return WEST_SHAPE; - if (facing == Direction.NORTH) - return NORTH_SHAPE; - if (facing == Direction.SOUTH) - return SOUTH_SHAPE; - - return VoxelShapes.empty(); + return AllShapes.LOGISTICAL_INDEX.get(state.get(HORIZONTAL_FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/logistics/transport/villager/LogisticiansTableBlock.java b/src/main/java/com/simibubi/create/modules/logistics/transport/villager/LogisticiansTableBlock.java index 5f083f3cd..2d7e6e297 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/transport/villager/LogisticiansTableBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/transport/villager/LogisticiansTableBlock.java @@ -5,6 +5,7 @@ import java.util.Random; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.block.IWithTileEntity; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -33,29 +34,6 @@ import net.minecraft.world.World; public class LogisticiansTableBlock extends HorizontalBlock implements IWithTileEntity { - private static final VoxelShape BASE_SHAPE = Block.makeCuboidShape(4.0D, 0.0D, 4.0D, 12.0D, 2.0D, 12.0D); - private static final VoxelShape POLE_SHAPE = Block.makeCuboidShape(5.0D, 2.0D, 5.0D, 11.0D, 14.0D, 11.0D); - private static final VoxelShape RENDER_SHAPE = VoxelShapes.or(BASE_SHAPE, POLE_SHAPE); - private static final VoxelShape TOP_COLLISION_SHAPE = Block.makeCuboidShape(0.0D, 15.0D, 0.0D, 16.0D, 15.0D, 16.0D); - private static final VoxelShape COLLISION_SHAPE = VoxelShapes.or(RENDER_SHAPE, TOP_COLLISION_SHAPE); - - private static final VoxelShape WEST_SHAPE = VoxelShapes.or( - Block.makeCuboidShape(1.0D, 10.0D, 0.0D, 5.333333D, 14.0D, 16.0D), - Block.makeCuboidShape(5.333333D, 12.0D, 0.0D, 9.666667D, 16.0D, 16.0D), - Block.makeCuboidShape(9.666667D, 14.0D, 0.0D, 14.0D, 18.0D, 16.0D), RENDER_SHAPE); - private static final VoxelShape NORTH_SHAPE = VoxelShapes.or( - Block.makeCuboidShape(0.0D, 10.0D, 1.0D, 16.0D, 14.0D, 5.333333D), - Block.makeCuboidShape(0.0D, 12.0D, 5.333333D, 16.0D, 16.0D, 9.666667D), - Block.makeCuboidShape(0.0D, 14.0D, 9.666667D, 16.0D, 18.0D, 14.0D), RENDER_SHAPE); - private static final VoxelShape EAST_SHAPE = VoxelShapes.or( - Block.makeCuboidShape(15.0D, 10.0D, 0.0D, 10.666667D, 14.0D, 16.0D), - Block.makeCuboidShape(10.666667D, 12.0D, 0.0D, 6.333333D, 16.0D, 16.0D), - Block.makeCuboidShape(6.333333D, 14.0D, 0.0D, 2.0D, 18.0D, 16.0D), RENDER_SHAPE); - private static final VoxelShape SOUTH_SHAPE = VoxelShapes.or( - Block.makeCuboidShape(0.0D, 10.0D, 15.0D, 16.0D, 14.0D, 10.666667D), - Block.makeCuboidShape(0.0D, 12.0D, 10.666667D, 16.0D, 16.0D, 6.333333D), - Block.makeCuboidShape(0.0D, 14.0D, 6.333333D, 16.0D, 18.0D, 2.0D), RENDER_SHAPE); - public LogisticiansTableBlock() { super(Properties.from(Blocks.SPRUCE_LOG)); } @@ -95,10 +73,6 @@ public class LogisticiansTableBlock extends HorizontalBlock implements IWithTile super.fillStateContainer(builder); } - public VoxelShape getRenderShape(BlockState state, IBlockReader worldIn, BlockPos pos) { - return RENDER_SHAPE; - } - public boolean func_220074_n(BlockState state) { return true; } @@ -123,24 +97,12 @@ public class LogisticiansTableBlock extends HorizontalBlock implements IWithTile return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); } - public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, - ISelectionContext context) { - return COLLISION_SHAPE; + public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return AllShapes.LOGISTICS_TABLE_BASE; } public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - switch (state.get(HORIZONTAL_FACING)) { - case NORTH: - return NORTH_SHAPE; - case SOUTH: - return SOUTH_SHAPE; - case EAST: - return EAST_SHAPE; - case WEST: - return WEST_SHAPE; - default: - return RENDER_SHAPE; - } + return AllShapes.LOGISTICS_TABLE.get(state.get(HORIZONTAL_FACING)); } } diff --git a/src/main/java/com/simibubi/create/modules/logistics/transport/villager/PackageFunnelBlock.java b/src/main/java/com/simibubi/create/modules/logistics/transport/villager/PackageFunnelBlock.java index cda8e4c51..3b6c63ed1 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/transport/villager/PackageFunnelBlock.java +++ b/src/main/java/com/simibubi/create/modules/logistics/transport/villager/PackageFunnelBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.logistics.transport.villager; import com.simibubi.create.AllBlocks; import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.block.ProperDirectionalBlock; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.modules.logistics.management.base.ILogisticalCasingAttachment; import com.simibubi.create.modules.logistics.management.base.LogisticalCasingTileEntity; import com.simibubi.create.modules.logistics.transport.CardboardBoxEntity; @@ -22,13 +23,7 @@ import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; import net.minecraft.world.World; -public class PackageFunnelBlock extends ProperDirectionalBlock - implements IWithTileEntity, ILogisticalCasingAttachment { - - public static final VoxelShape UP_SHAPE = makeCuboidShape(1, -1, 1, 15, 3, 15), - DOWN_SHAPE = makeCuboidShape(1, 13, 1, 15, 17, 15), SOUTH_SHAPE = makeCuboidShape(1, 1, -1, 15, 15, 3), - NORTH_SHAPE = makeCuboidShape(1, 1, 13, 15, 15, 17), EAST_SHAPE = makeCuboidShape(-1, 1, 1, 3, 15, 15), - WEST_SHAPE = makeCuboidShape(13, 1, 1, 17, 15, 15); +public class PackageFunnelBlock extends ProperDirectionalBlock implements IWithTileEntity, ILogisticalCasingAttachment { public PackageFunnelBlock() { super(Properties.from(Blocks.PISTON)); @@ -82,22 +77,7 @@ public class PackageFunnelBlock extends ProperDirectionalBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - Direction facing = state.get(FACING); - - if (facing == Direction.UP) - return UP_SHAPE; - if (facing == Direction.DOWN) - return DOWN_SHAPE; - if (facing == Direction.EAST) - return EAST_SHAPE; - if (facing == Direction.WEST) - return WEST_SHAPE; - if (facing == Direction.NORTH) - return NORTH_SHAPE; - if (facing == Direction.SOUTH) - return SOUTH_SHAPE; - - return VoxelShapes.empty(); + return AllShapes.PACKAGE_FUNNEL.get(state.get(FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/CreativeCrateBlock.java b/src/main/java/com/simibubi/create/modules/schematics/block/CreativeCrateBlock.java index 791e1689e..fe226272d 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/CreativeCrateBlock.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/CreativeCrateBlock.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.schematics.block; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.material.Material; @@ -10,8 +11,6 @@ import net.minecraft.world.IBlockReader; public class CreativeCrateBlock extends Block { - protected static final VoxelShape shape = makeCuboidShape(1, 0, 1, 15, 14, 15); - public CreativeCrateBlock() { super(Properties.create(Material.WOOD)); } @@ -23,13 +22,7 @@ public class CreativeCrateBlock extends Block { @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return shape; - } - - @Override - public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, - ISelectionContext context) { - return shape; + return AllShapes.CRATE_BLOCK_SHAPE; } } From 7a96a8b7ed9679d26a417ed94b2afbdfcc4d796a Mon Sep 17 00:00:00 2001 From: zelophed Date: Tue, 10 Dec 2019 17:45:42 +0100 Subject: [PATCH 5/6] finishing touches to refactor new shapes for cannon and schematic table viewing shapes for mixer and press now differ from regular shape to allow for levers being placed on their side entirely removed economy package Signed-off-by: Zelophed --- .../create/foundation/utility/AllShapes.java | 27 +++-- .../foundation/utility/VoxelShaper.java | 3 +- .../contraptions/receivers/DrillBlock.java | 2 +- .../receivers/MechanicalMixerBlock.java | 6 +- .../receivers/MechanicalPressBlock.java | 6 +- .../contraptions/receivers/SawBlock.java | 2 +- .../contraptions/relays/belt/BeltBlock.java | 4 +- .../contraptions/relays/belt/BeltShapes.java | 33 +++--- .../modules/economy/ShopShelfBlock.java | 101 ------------------ .../modules/economy/ShopShelfContainer.java | 25 ----- .../modules/economy/ShopShelfScreen.java | 19 ---- .../modules/economy/ShopShelfTileEntity.java | 62 ----------- .../schematics/block/SchematicTableBlock.java | 13 +++ .../schematics/block/SchematicannonBlock.java | 8 ++ 14 files changed, 70 insertions(+), 241 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java diff --git a/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java index b9f1cfa32..1227fbbd3 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java @@ -12,7 +12,9 @@ import static net.minecraft.block.Block.makeCuboidShape; public class AllShapes { public static final VoxelShaper - SHORT_CASING = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 12, 16), Direction.UP), + SHORT_CASING_14_VOXEL = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 14, 16), Direction.UP), + SHORT_CASING_12_VOXEL = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 12, 16), Direction.UP), + SHORT_CASING_11_VOXEL = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 11, 16), Direction.UP), HARVESTER_BASE = VoxelShaper.forHorizontal(makeCuboidShape(0, 2, 0, 16, 14, 3), Direction.SOUTH), MOTOR_BLOCK = VoxelShaper.forHorizontal(makeCuboidShape(0, 3, 3, 16, 13, 13), Direction.EAST), FOUR_VOXEL_POLE = VoxelShaper.forDirectionalAxis(makeCuboidShape(6, 0, 6, 10, 16, 10), Direction.Axis.Y), @@ -37,7 +39,7 @@ public class AllShapes { makeCuboidShape(-2, 0, 1, 18, 13, 15)), MECHANICAL_PISTON_HEAD_SHAPE_UP = Blocks.PISTON_HEAD.getShape(Blocks.PISTON_HEAD.getStateContainer().getBaseState().with(DirectionalBlock.FACING, Direction.UP).with(PistonHeadBlock.SHORT, true), null, null, null), MECHANICAL_PISTON_EXTENDED_SHAPE_UP = VoxelShapes.or( - SHORT_CASING.get(Direction.UP), + SHORT_CASING_12_VOXEL.get(Direction.UP), FOUR_VOXEL_POLE.get(Direction.Axis.Y)), SMALL_GEAR_SHAPE = makeCuboidShape(2, 6, 2, 14, 10, 14), LARGE_GEAR_SHAPE = makeCuboidShape(0, 6, 0, 16, 10, 16), @@ -50,7 +52,11 @@ public class AllShapes { LOGISTICS_TABLE_SLOPE_SOUTH = VoxelShapes.or( makeCuboidShape(0, 10D, 15, 16, 14, 10.667), makeCuboidShape(0, 12, 10.667, 16, 16, 6.333), - makeCuboidShape(0, 14, 6.333, 16, 18, 2)) + makeCuboidShape(0, 14, 6.333, 16, 18, 2)), + SCHEMATICS_TABLE_SLOPE_SOUTH = VoxelShapes.or( + makeCuboidShape(0, 10, 16, 16, 14, 11), + makeCuboidShape(0, 12, 11, 16, 16, 6), + makeCuboidShape(0, 14, 6, 16, 18, 1)) ; @@ -59,14 +65,18 @@ public class AllShapes { makeCuboidShape(0, 0, 0, 16, 2, 16), makeCuboidShape(1, 1, 1, 15, 15, 15), makeCuboidShape(0, 14, 0, 16, 16, 16)), - BASIN_BLOCK_SHAPE = makeCuboidShape(0, 0, 0, 16, 13, 16),//todo maybe + BASIN_BLOCK_SHAPE = makeCuboidShape(0, 0, 0, 16, 13, 16),//todo can be improved when someone finds the time :D CRUSHING_WHEEL_COLLISION_SHAPE = makeCuboidShape(0, 0, 0, 16, 22, 16), - MECHANICAL_PRESS_SHAPE = VoxelShapes.fullCube(),//todo maybe + MECHANICAL_PROCESSOR_SHAPE = VoxelShapes.fullCube(),//is full block so levers can be placed on the sides TURNTABLE_SHAPE = VoxelShapes.or( makeCuboidShape(1, 6, 1, 15, 8, 15), makeCuboidShape(5, 0, 5, 11, 6, 11)), CRATE_BLOCK_SHAPE = makeCuboidShape(1, 0, 1, 15, 14, 15), - LOGISTICS_TABLE_BASE = TABLE_POLE_SHAPE + LOGISTICS_TABLE_BASE = TABLE_POLE_SHAPE, + BELT_COLLISION_MASK = makeCuboidShape(0, 0, 0, 16, 19, 16), + SCHEMATICANNON_SHAPE = VoxelShapes.or( + makeCuboidShape(1, 0, 1, 15, 8, 15), + makeCuboidShape(0.5, 8, 0.5, 15.5, 11, 15.5)) ; @@ -78,7 +88,7 @@ public class AllShapes { LOGISTICAL_CASING_CAP = VoxelShaper.forDirectional(LOGISTICAL_CASING_CAP_SHAPE, Direction.UP), CART_ASSEMBLER = VoxelShaper.forHorizontalAxis(CART_ASSEMBLER_SHAPE, Direction.SOUTH), MECHANICAL_PISTON_HEAD = VoxelShaper.forDirectional(MECHANICAL_PISTON_HEAD_SHAPE_UP, Direction.UP), - MECHANICAL_PISTON = SHORT_CASING, + MECHANICAL_PISTON = SHORT_CASING_12_VOXEL, MECHANICAL_PISTON_EXTENDED = VoxelShaper.forDirectional(MECHANICAL_PISTON_EXTENDED_SHAPE_UP, Direction.UP), SMALL_GEAR = VoxelShaper.forDirectionalAxis(VoxelShapes.or(SMALL_GEAR_SHAPE, SIX_VOXEL_POLE.get(Direction.Axis.Y)), Direction.Axis.Y), LARGE_GEAR = VoxelShaper.forDirectionalAxis(VoxelShapes.or(LARGE_GEAR_SHAPE, SIX_VOXEL_POLE.get(Direction.Axis.Y)), Direction.Axis.Y), @@ -86,7 +96,8 @@ public class AllShapes { REDSTONE_BRIDGE = VoxelShaper.forHorizontal(VERTICAL_TABLET_SHAPE_SOUTH, Direction.SOUTH).withVerticalShapes(LOGISTICAL_CONTROLLER.get(Direction.UP)), LOGISTICAL_INDEX = REDSTONE_BRIDGE, PACKAGE_FUNNEL = VoxelShaper.forDirectional(PACKAGE_FUNNEL_SHAPE_UP, Direction.UP), - LOGISTICS_TABLE = VoxelShaper.forHorizontal(VoxelShapes.or(TABLE_POLE_SHAPE, LOGISTICS_TABLE_SLOPE_SOUTH), Direction.SOUTH) + LOGISTICS_TABLE = VoxelShaper.forHorizontal(VoxelShapes.or(TABLE_POLE_SHAPE, LOGISTICS_TABLE_SLOPE_SOUTH), Direction.SOUTH), + SCHEMATICS_TABLE = VoxelShaper.forDirectional(VoxelShapes.or(TABLE_POLE_SHAPE, SCHEMATICS_TABLE_SLOPE_SOUTH), Direction.SOUTH) ; 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 73ad591af..b043a6059 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java @@ -35,7 +35,7 @@ public class VoxelShaper { return forDirectionsWithRotation(shape, facing, Arrays.asList(Direction.SOUTH, Direction.EAST), new HorizontalRotationValues()); } - public static VoxelShaper forRotatedPillar(VoxelShape zShape) {//dunno what this was intended for + public static VoxelShaper forRotatedPillar(VoxelShape zShape) {//todo dunno what this was intended for VoxelShaper voxelShaper = new VoxelShaper(); for (Axis axis : Axis.values()) { Direction facing = axisAsFace(axis); @@ -71,7 +71,6 @@ public class VoxelShaper { VoxelShaper voxelShaper = new VoxelShaper(); for (Direction dir : directions) { voxelShaper.shapes.put(dir, rotate(shape, facing, dir, rotationValues)); - //voxelShaper.shapes.put(dir, rotatedCopy(shape, rotationValues.apply(dir))); } return voxelShaper; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java index d446f0d73..ac837c481 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java @@ -49,7 +49,7 @@ public class DrillBlock extends DirectionalKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.SHORT_CASING.get(state.get(FACING)); + return AllShapes.SHORT_CASING_12_VOXEL.get(state.get(FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java index 89c729d0c..e8ccfde1a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java @@ -9,6 +9,7 @@ import com.simibubi.create.modules.contraptions.base.KineticBlock; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; import net.minecraft.tileentity.TileEntity; @@ -45,7 +46,10 @@ public class MechanicalMixerBlock extends KineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.MECHANICAL_PRESS_SHAPE; + if (context.getEntity() instanceof PlayerEntity) + return AllShapes.SHORT_CASING_14_VOXEL.get(Direction.DOWN); + + return AllShapes.MECHANICAL_PROCESSOR_SHAPE; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java index b165983cd..59a100cd2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java @@ -22,6 +22,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.HorizontalBlock; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.StateContainer.Builder; @@ -44,7 +45,10 @@ public class MechanicalPressBlock extends HorizontalKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.MECHANICAL_PRESS_SHAPE; + if (context.getEntity() instanceof PlayerEntity) + return AllShapes.SHORT_CASING_14_VOXEL.get(Direction.DOWN); + + return AllShapes.MECHANICAL_PROCESSOR_SHAPE; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java index 623f9a614..a7534c611 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java @@ -82,7 +82,7 @@ public class SawBlock extends DirectionalAxisKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.SHORT_CASING.get(state.get(FACING)); + return AllShapes.SHORT_CASING_12_VOXEL.get(state.get(FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 330d3e976..50af383cf 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -8,6 +8,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.block.IWithoutBlockItem; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock; import com.simibubi.create.modules.contraptions.relays.belt.BeltMovementHandler.TransportedEntityInfo; @@ -55,7 +56,6 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt public static final IProperty SLOPE = EnumProperty.create("slope", Slope.class); public static final IProperty PART = EnumProperty.create("part", Part.class); public static final BooleanProperty CASING = BooleanProperty.create("casing"); - private final VoxelShape collisionMask = makeCuboidShape(0, 0, 0, 16, 19, 16);//todo review public BeltBlock() { super(Properties.from(Blocks.BROWN_WOOL)); @@ -288,7 +288,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt if (controller == null) return shape; if (controller.passengers == null || !controller.passengers.containsKey(context.getEntity())) { - return VoxelShapes.combine(collisionMask, shape, IBooleanFunction.AND); + return VoxelShapes.combine(AllShapes.BELT_COLLISION_MASK, shape, IBooleanFunction.AND); } return shape; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java index 8949f892d..86236a09d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.relays.belt; import static net.minecraft.block.Block.makeCuboidShape; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.VoxelShaper; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope; @@ -94,6 +95,8 @@ public class BeltShapes { SLOPE_ASC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_ASC_PART), Direction.SOUTH), SLOPE_ASC_START = VoxelShaper.forHorizontal(compose(SLOPE_ASC_PART, FLAT_END_PART), Direction.SOUTH); + private static final VoxelShaper + PARTIAL_CASING = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 5, 16, 11, 16), Direction.SOUTH); private static VoxelShape compose(VoxelShape southPart, VoxelShape northPart){ @@ -130,10 +133,6 @@ public class BeltShapes { return makeCuboidShape(1,3,0,15,13,16); } - private static final VoxelShape CASING_HORIZONTAL = makeCuboidShape(0, 0, 0, 16, 11, 16); - //todo still need to remove these two - private static final VoxelShaper CASING_TOP_END = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 0, 16, 11, 11), Direction.SOUTH); - public static VoxelShape getShape(BlockState state) { Direction facing = state.get(BeltBlock.HORIZONTAL_FACING); Axis axis = facing.getAxis(); @@ -170,7 +169,7 @@ public class BeltShapes { } - public static VoxelShape getCasingShape(BlockState state) {//todo + public static VoxelShape getCasingShape(BlockState state) { if (!state.get(BeltBlock.CASING)) return VoxelShapes.empty(); @@ -178,25 +177,23 @@ public class BeltShapes { Part part = state.get(BeltBlock.PART); Slope slope = state.get(BeltBlock.SLOPE); - if (slope == Slope.HORIZONTAL) - return CASING_HORIZONTAL; if (slope == Slope.VERTICAL) return VoxelShapes.empty(); - if (part != Part.MIDDLE) { - boolean upward = slope == Slope.UPWARD; - if (part == Part.START) - upward = !upward; - else - facing = facing.getOpposite(); - - return upward ? CASING_TOP_END.get(facing) : CASING_HORIZONTAL; + if (slope == Slope.HORIZONTAL) { + return AllShapes.SHORT_CASING_11_VOXEL.get(Direction.UP); } - if (slope == Slope.DOWNWARD) - facing = facing.getOpposite(); + if (part == Part.MIDDLE || part == Part.PULLEY) + return PARTIAL_CASING.get(slope == Slope.UPWARD ? facing : facing.getOpposite()); - return CASING_TOP_END.get(facing.getOpposite()); + if (part == Part.START) + return slope == Slope.UPWARD ? AllShapes.SHORT_CASING_11_VOXEL.get(Direction.UP) : PARTIAL_CASING.get(facing.getOpposite()); + if (part == Part.END) + return slope == Slope.DOWNWARD ? AllShapes.SHORT_CASING_11_VOXEL.get(Direction.UP) : PARTIAL_CASING.get(facing); + + //something went wrong + return VoxelShapes.fullCube(); } private static class VerticalBeltShaper extends VoxelShaper { diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java deleted file mode 100644 index 14bc2c021..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.simibubi.create.modules.economy; - -import com.simibubi.create.foundation.block.IWithoutBlockItem; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.HorizontalBlock; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.item.ItemStack; -import net.minecraft.state.StateContainer.Builder; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.World; -import net.minecraftforge.fml.network.NetworkHooks; - -public class ShopShelfBlock extends HorizontalBlock implements IWithoutBlockItem { - - public static final VoxelShape TOP_SHAPE = makeCuboidShape(0, 14, 0, 16, 16, 16);//todo review - - public static final VoxelShape BODY_SOUTH_SHAPE = makeCuboidShape(0, 0, 0, 16, 14, 14); - public static final VoxelShape BODY_NORTH_SHAPE = makeCuboidShape(0, 0, 2, 16, 14, 16); - public static final VoxelShape BODY_EAST_SHAPE = makeCuboidShape(0, 0, 0, 14, 14, 16); - public static final VoxelShape BODY_WEST_SHAPE = makeCuboidShape(2, 0, 0, 16, 14, 16); - - public ShopShelfBlock() { - super(Properties.from(Blocks.SPRUCE_PLANKS)); - } - - @Override - public boolean hasTileEntity(BlockState state) { - return true; - } - - @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return new ShopShelfTileEntity(); - } - - @Override - public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { - ShopShelfTileEntity te = (ShopShelfTileEntity) worldIn.getTileEntity(pos); - te.setOwner(placer.getUniqueID()); - worldIn.notifyBlockUpdate(pos, state, state, 2); - } - - @Override - public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, - BlockRayTraceResult hit) { - ShopShelfTileEntity te = (ShopShelfTileEntity) worldIn.getTileEntity(pos); - if (te == null) - return false; - if (!worldIn.isRemote) - NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer); - return true; - } - - @Override - protected void fillStateContainer(Builder builder) { - builder.add(HORIZONTAL_FACING); - super.fillStateContainer(builder); - } - - @Override - public BlockState getStateForPlacement(BlockItemUseContext context) { - return getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); - } - - @Override - public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - VoxelShape body = VoxelShapes.empty(); - switch (state.get(HORIZONTAL_FACING)) { - case EAST: - body = BODY_EAST_SHAPE; - break; - case NORTH: - body = BODY_NORTH_SHAPE; - break; - case SOUTH: - body = BODY_SOUTH_SHAPE; - break; - case WEST: - body = BODY_WEST_SHAPE; - break; - default: - break; - } - - return VoxelShapes.or(TOP_SHAPE, body); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java deleted file mode 100644 index e85d49bf6..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.simibubi.create.modules.economy; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.network.PacketBuffer; - -public class ShopShelfContainer extends Container { - - public ShopShelfContainer(int id, PlayerInventory inv, ShopShelfTileEntity te) { -// super(AllContainers.SHOP_SHELF.type, id); - super(null, id); - } - - public ShopShelfContainer(int id, PlayerInventory inv, PacketBuffer extraData) { -// super(AllContainers.SHOP_SHELF.type, id); - super(null, id); - } - - @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; - } - -} diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java deleted file mode 100644 index 93bbe3188..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.modules.economy; - -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; - -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.text.ITextComponent; - -public class ShopShelfScreen extends AbstractSimiContainerScreen { - - public ShopShelfScreen(ShopShelfContainer container, PlayerInventory inv, ITextComponent title) { - super(container, inv, title); - } - - @Override - protected void renderWindow(int mouseX, int mouseY, float partialTicks) { - renderTooltip("Hi", mouseX, mouseY); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java deleted file mode 100644 index e93e94a33..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.simibubi.create.modules.economy; - -import java.util.UUID; - -import com.simibubi.create.foundation.block.SyncedTileEntity; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; - -public class ShopShelfTileEntity extends SyncedTileEntity implements INamedContainerProvider { - - private UUID owner; - - public ShopShelfTileEntity() { - super(null); -// super(AllTileEntities.SHOP_SHELF.type); - } - - @Override - public void read(CompoundNBT compound) { - if (compound.contains("Owner")) - setOwner(NBTUtil.readUniqueId(compound.getCompound("Owner"))); - super.read(compound); - } - - @Override - public CompoundNBT write(CompoundNBT compound) { - if (getOwner() != null) - compound.put("Owner", NBTUtil.writeUniqueId(getOwner())); - return super.write(compound); - } - - public UUID getOwner() { - return owner; - } - - public void setOwner(UUID owner) { - this.owner = owner; - } - - public void sendToContainer(PacketBuffer buffer) { - buffer.writeUniqueId(getOwner()); - } - - @Override - public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { - return new ShopShelfContainer(id, inventory, this); - } - - @Override - public ITextComponent getDisplayName() { - return new StringTextComponent(getType().getRegistryName().toString()); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java index 777676558..cf00f3da4 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.schematics.block; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -13,6 +14,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; @@ -39,6 +42,16 @@ public class SchematicTableBlock extends HorizontalBlock { return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); } + @Override + public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return AllShapes.LOGISTICS_TABLE_BASE; + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return AllShapes.SCHEMATICS_TABLE.get(state.get(HORIZONTAL_FACING)); + } + @Override public boolean hasTileEntity(BlockState state) { return true; diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java index 7ad4639e0..4eda575f7 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.schematics.block; import com.simibubi.create.AllItems; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -14,6 +15,8 @@ import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; @@ -48,6 +51,11 @@ public class SchematicannonBlock extends Block { return false; } + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return AllShapes.SCHEMATICANNON_SHAPE; + } + @Override public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) { ((SchematicannonTileEntity) world.getTileEntity(pos)).findInventories(); From ac3f2ba85c8300a1099072b1f57a2b535886bf4d Mon Sep 17 00:00:00 2001 From: zelophed Date: Tue, 10 Dec 2019 17:45:42 +0100 Subject: [PATCH 6/6] finishing touches to refactor new shapes for cannon and schematic table viewing shapes for mixer and press now differ from regular shape to allow for levers being placed on their side entirely removed economy package Signed-off-by: Zelophed --- .../create/foundation/utility/AllShapes.java | 31 ++++-- .../foundation/utility/VoxelShaper.java | 3 +- .../contraptions/receivers/DrillBlock.java | 2 +- .../receivers/MechanicalMixerBlock.java | 6 +- .../receivers/MechanicalPressBlock.java | 6 +- .../contraptions/receivers/SawBlock.java | 2 +- .../contraptions/relays/belt/BeltBlock.java | 4 +- .../contraptions/relays/belt/BeltShapes.java | 33 +++--- .../modules/economy/ShopShelfBlock.java | 101 ------------------ .../modules/economy/ShopShelfContainer.java | 25 ----- .../modules/economy/ShopShelfScreen.java | 19 ---- .../modules/economy/ShopShelfTileEntity.java | 62 ----------- .../schematics/block/SchematicTableBlock.java | 13 +++ .../schematics/block/SchematicannonBlock.java | 8 ++ 14 files changed, 74 insertions(+), 241 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java delete mode 100644 src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java diff --git a/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java index b9f1cfa32..6a7c0663a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java @@ -4,6 +4,7 @@ import net.minecraft.block.Blocks; import net.minecraft.block.DirectionalBlock; import net.minecraft.block.PistonHeadBlock; import net.minecraft.util.Direction; +import net.minecraft.util.math.shapes.IBooleanFunction; import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.util.math.shapes.VoxelShapes; @@ -12,7 +13,9 @@ import static net.minecraft.block.Block.makeCuboidShape; public class AllShapes { public static final VoxelShaper - SHORT_CASING = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 12, 16), Direction.UP), + SHORT_CASING_14_VOXEL = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 14, 16), Direction.UP), + SHORT_CASING_12_VOXEL = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 12, 16), Direction.UP), + SHORT_CASING_11_VOXEL = VoxelShaper.forDirectional(makeCuboidShape(0, 0, 0, 16, 11, 16), Direction.UP), HARVESTER_BASE = VoxelShaper.forHorizontal(makeCuboidShape(0, 2, 0, 16, 14, 3), Direction.SOUTH), MOTOR_BLOCK = VoxelShaper.forHorizontal(makeCuboidShape(0, 3, 3, 16, 13, 13), Direction.EAST), FOUR_VOXEL_POLE = VoxelShaper.forDirectionalAxis(makeCuboidShape(6, 0, 6, 10, 16, 10), Direction.Axis.Y), @@ -37,7 +40,7 @@ public class AllShapes { makeCuboidShape(-2, 0, 1, 18, 13, 15)), MECHANICAL_PISTON_HEAD_SHAPE_UP = Blocks.PISTON_HEAD.getShape(Blocks.PISTON_HEAD.getStateContainer().getBaseState().with(DirectionalBlock.FACING, Direction.UP).with(PistonHeadBlock.SHORT, true), null, null, null), MECHANICAL_PISTON_EXTENDED_SHAPE_UP = VoxelShapes.or( - SHORT_CASING.get(Direction.UP), + SHORT_CASING_12_VOXEL.get(Direction.UP), FOUR_VOXEL_POLE.get(Direction.Axis.Y)), SMALL_GEAR_SHAPE = makeCuboidShape(2, 6, 2, 14, 10, 14), LARGE_GEAR_SHAPE = makeCuboidShape(0, 6, 0, 16, 10, 16), @@ -50,7 +53,11 @@ public class AllShapes { LOGISTICS_TABLE_SLOPE_SOUTH = VoxelShapes.or( makeCuboidShape(0, 10D, 15, 16, 14, 10.667), makeCuboidShape(0, 12, 10.667, 16, 16, 6.333), - makeCuboidShape(0, 14, 6.333, 16, 18, 2)) + makeCuboidShape(0, 14, 6.333, 16, 18, 2)), + SCHEMATICS_TABLE_SLOPE_SOUTH = VoxelShapes.or( + makeCuboidShape(0, 10, 16, 16, 14, 11), + makeCuboidShape(0, 12, 11, 16, 16, 6), + makeCuboidShape(0, 14, 6, 16, 18, 1)) ; @@ -59,14 +66,21 @@ public class AllShapes { makeCuboidShape(0, 0, 0, 16, 2, 16), makeCuboidShape(1, 1, 1, 15, 15, 15), makeCuboidShape(0, 14, 0, 16, 16, 16)), - BASIN_BLOCK_SHAPE = makeCuboidShape(0, 0, 0, 16, 13, 16),//todo maybe + BASIN_BLOCK_SHAPE = makeCuboidShape(0, 0, 0, 16, 13, 16),//todo can be improved when someone finds the time :D CRUSHING_WHEEL_COLLISION_SHAPE = makeCuboidShape(0, 0, 0, 16, 22, 16), - MECHANICAL_PRESS_SHAPE = VoxelShapes.fullCube(),//todo maybe + MECHANICAL_PROCESSOR_SHAPE = VoxelShapes.combineAndSimplify( + VoxelShapes.fullCube(), + makeCuboidShape(4, 0, 4, 12, 16, 12), + IBooleanFunction.ONLY_FIRST), TURNTABLE_SHAPE = VoxelShapes.or( makeCuboidShape(1, 6, 1, 15, 8, 15), makeCuboidShape(5, 0, 5, 11, 6, 11)), CRATE_BLOCK_SHAPE = makeCuboidShape(1, 0, 1, 15, 14, 15), - LOGISTICS_TABLE_BASE = TABLE_POLE_SHAPE + LOGISTICS_TABLE_BASE = TABLE_POLE_SHAPE, + BELT_COLLISION_MASK = makeCuboidShape(0, 0, 0, 16, 19, 16), + SCHEMATICANNON_SHAPE = VoxelShapes.or( + makeCuboidShape(1, 0, 1, 15, 8, 15), + makeCuboidShape(0.5, 8, 0.5, 15.5, 11, 15.5)) ; @@ -78,7 +92,7 @@ public class AllShapes { LOGISTICAL_CASING_CAP = VoxelShaper.forDirectional(LOGISTICAL_CASING_CAP_SHAPE, Direction.UP), CART_ASSEMBLER = VoxelShaper.forHorizontalAxis(CART_ASSEMBLER_SHAPE, Direction.SOUTH), MECHANICAL_PISTON_HEAD = VoxelShaper.forDirectional(MECHANICAL_PISTON_HEAD_SHAPE_UP, Direction.UP), - MECHANICAL_PISTON = SHORT_CASING, + MECHANICAL_PISTON = SHORT_CASING_12_VOXEL, MECHANICAL_PISTON_EXTENDED = VoxelShaper.forDirectional(MECHANICAL_PISTON_EXTENDED_SHAPE_UP, Direction.UP), SMALL_GEAR = VoxelShaper.forDirectionalAxis(VoxelShapes.or(SMALL_GEAR_SHAPE, SIX_VOXEL_POLE.get(Direction.Axis.Y)), Direction.Axis.Y), LARGE_GEAR = VoxelShaper.forDirectionalAxis(VoxelShapes.or(LARGE_GEAR_SHAPE, SIX_VOXEL_POLE.get(Direction.Axis.Y)), Direction.Axis.Y), @@ -86,7 +100,8 @@ public class AllShapes { REDSTONE_BRIDGE = VoxelShaper.forHorizontal(VERTICAL_TABLET_SHAPE_SOUTH, Direction.SOUTH).withVerticalShapes(LOGISTICAL_CONTROLLER.get(Direction.UP)), LOGISTICAL_INDEX = REDSTONE_BRIDGE, PACKAGE_FUNNEL = VoxelShaper.forDirectional(PACKAGE_FUNNEL_SHAPE_UP, Direction.UP), - LOGISTICS_TABLE = VoxelShaper.forHorizontal(VoxelShapes.or(TABLE_POLE_SHAPE, LOGISTICS_TABLE_SLOPE_SOUTH), Direction.SOUTH) + LOGISTICS_TABLE = VoxelShaper.forHorizontal(VoxelShapes.or(TABLE_POLE_SHAPE, LOGISTICS_TABLE_SLOPE_SOUTH), Direction.SOUTH), + SCHEMATICS_TABLE = VoxelShaper.forDirectional(VoxelShapes.or(TABLE_POLE_SHAPE, SCHEMATICS_TABLE_SLOPE_SOUTH), Direction.SOUTH) ; 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 73ad591af..b043a6059 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java @@ -35,7 +35,7 @@ public class VoxelShaper { return forDirectionsWithRotation(shape, facing, Arrays.asList(Direction.SOUTH, Direction.EAST), new HorizontalRotationValues()); } - public static VoxelShaper forRotatedPillar(VoxelShape zShape) {//dunno what this was intended for + public static VoxelShaper forRotatedPillar(VoxelShape zShape) {//todo dunno what this was intended for VoxelShaper voxelShaper = new VoxelShaper(); for (Axis axis : Axis.values()) { Direction facing = axisAsFace(axis); @@ -71,7 +71,6 @@ public class VoxelShaper { VoxelShaper voxelShaper = new VoxelShaper(); for (Direction dir : directions) { voxelShaper.shapes.put(dir, rotate(shape, facing, dir, rotationValues)); - //voxelShaper.shapes.put(dir, rotatedCopy(shape, rotationValues.apply(dir))); } return voxelShaper; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java index d446f0d73..ac837c481 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/DrillBlock.java @@ -49,7 +49,7 @@ public class DrillBlock extends DirectionalKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.SHORT_CASING.get(state.get(FACING)); + return AllShapes.SHORT_CASING_12_VOXEL.get(state.get(FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java index 89c729d0c..e8ccfde1a 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalMixerBlock.java @@ -9,6 +9,7 @@ import com.simibubi.create.modules.contraptions.base.KineticBlock; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItemUseContext; import net.minecraft.tileentity.TileEntity; @@ -45,7 +46,10 @@ public class MechanicalMixerBlock extends KineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.MECHANICAL_PRESS_SHAPE; + if (context.getEntity() instanceof PlayerEntity) + return AllShapes.SHORT_CASING_14_VOXEL.get(Direction.DOWN); + + return AllShapes.MECHANICAL_PROCESSOR_SHAPE; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java index b165983cd..59a100cd2 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/MechanicalPressBlock.java @@ -22,6 +22,7 @@ import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; import net.minecraft.block.HorizontalBlock; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BlockItemUseContext; import net.minecraft.item.ItemStack; import net.minecraft.state.StateContainer.Builder; @@ -44,7 +45,10 @@ public class MechanicalPressBlock extends HorizontalKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.MECHANICAL_PRESS_SHAPE; + if (context.getEntity() instanceof PlayerEntity) + return AllShapes.SHORT_CASING_14_VOXEL.get(Direction.DOWN); + + return AllShapes.MECHANICAL_PROCESSOR_SHAPE; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java index 623f9a614..a7534c611 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/SawBlock.java @@ -82,7 +82,7 @@ public class SawBlock extends DirectionalAxisKineticBlock @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - return AllShapes.SHORT_CASING.get(state.get(FACING)); + return AllShapes.SHORT_CASING_12_VOXEL.get(state.get(FACING)); } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java index 330d3e976..50af383cf 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltBlock.java @@ -8,6 +8,7 @@ import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.block.IWithTileEntity; import com.simibubi.create.foundation.block.IWithoutBlockItem; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.modules.contraptions.base.HorizontalKineticBlock; import com.simibubi.create.modules.contraptions.relays.belt.BeltMovementHandler.TransportedEntityInfo; @@ -55,7 +56,6 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt public static final IProperty SLOPE = EnumProperty.create("slope", Slope.class); public static final IProperty PART = EnumProperty.create("part", Part.class); public static final BooleanProperty CASING = BooleanProperty.create("casing"); - private final VoxelShape collisionMask = makeCuboidShape(0, 0, 0, 16, 19, 16);//todo review public BeltBlock() { super(Properties.from(Blocks.BROWN_WOOL)); @@ -288,7 +288,7 @@ public class BeltBlock extends HorizontalKineticBlock implements IWithoutBlockIt if (controller == null) return shape; if (controller.passengers == null || !controller.passengers.containsKey(context.getEntity())) { - return VoxelShapes.combine(collisionMask, shape, IBooleanFunction.AND); + return VoxelShapes.combine(AllShapes.BELT_COLLISION_MASK, shape, IBooleanFunction.AND); } return shape; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java index 8949f892d..86236a09d 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltShapes.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.relays.belt; import static net.minecraft.block.Block.makeCuboidShape; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.VoxelShaper; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope; @@ -94,6 +95,8 @@ public class BeltShapes { SLOPE_ASC_END = VoxelShaper.forHorizontal(compose(FLAT_END_PART, SLOPE_ASC_PART), Direction.SOUTH), SLOPE_ASC_START = VoxelShaper.forHorizontal(compose(SLOPE_ASC_PART, FLAT_END_PART), Direction.SOUTH); + private static final VoxelShaper + PARTIAL_CASING = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 5, 16, 11, 16), Direction.SOUTH); private static VoxelShape compose(VoxelShape southPart, VoxelShape northPart){ @@ -130,10 +133,6 @@ public class BeltShapes { return makeCuboidShape(1,3,0,15,13,16); } - private static final VoxelShape CASING_HORIZONTAL = makeCuboidShape(0, 0, 0, 16, 11, 16); - //todo still need to remove these two - private static final VoxelShaper CASING_TOP_END = VoxelShaper.forHorizontal(makeCuboidShape(0, 0, 0, 16, 11, 11), Direction.SOUTH); - public static VoxelShape getShape(BlockState state) { Direction facing = state.get(BeltBlock.HORIZONTAL_FACING); Axis axis = facing.getAxis(); @@ -170,7 +169,7 @@ public class BeltShapes { } - public static VoxelShape getCasingShape(BlockState state) {//todo + public static VoxelShape getCasingShape(BlockState state) { if (!state.get(BeltBlock.CASING)) return VoxelShapes.empty(); @@ -178,25 +177,23 @@ public class BeltShapes { Part part = state.get(BeltBlock.PART); Slope slope = state.get(BeltBlock.SLOPE); - if (slope == Slope.HORIZONTAL) - return CASING_HORIZONTAL; if (slope == Slope.VERTICAL) return VoxelShapes.empty(); - if (part != Part.MIDDLE) { - boolean upward = slope == Slope.UPWARD; - if (part == Part.START) - upward = !upward; - else - facing = facing.getOpposite(); - - return upward ? CASING_TOP_END.get(facing) : CASING_HORIZONTAL; + if (slope == Slope.HORIZONTAL) { + return AllShapes.SHORT_CASING_11_VOXEL.get(Direction.UP); } - if (slope == Slope.DOWNWARD) - facing = facing.getOpposite(); + if (part == Part.MIDDLE || part == Part.PULLEY) + return PARTIAL_CASING.get(slope == Slope.UPWARD ? facing : facing.getOpposite()); - return CASING_TOP_END.get(facing.getOpposite()); + if (part == Part.START) + return slope == Slope.UPWARD ? AllShapes.SHORT_CASING_11_VOXEL.get(Direction.UP) : PARTIAL_CASING.get(facing.getOpposite()); + if (part == Part.END) + return slope == Slope.DOWNWARD ? AllShapes.SHORT_CASING_11_VOXEL.get(Direction.UP) : PARTIAL_CASING.get(facing); + + //something went wrong + return VoxelShapes.fullCube(); } private static class VerticalBeltShaper extends VoxelShaper { diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java deleted file mode 100644 index 14bc2c021..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfBlock.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.simibubi.create.modules.economy; - -import com.simibubi.create.foundation.block.IWithoutBlockItem; - -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.Blocks; -import net.minecraft.block.HorizontalBlock; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.item.ItemStack; -import net.minecraft.state.StateContainer.Builder; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.util.math.shapes.VoxelShapes; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.World; -import net.minecraftforge.fml.network.NetworkHooks; - -public class ShopShelfBlock extends HorizontalBlock implements IWithoutBlockItem { - - public static final VoxelShape TOP_SHAPE = makeCuboidShape(0, 14, 0, 16, 16, 16);//todo review - - public static final VoxelShape BODY_SOUTH_SHAPE = makeCuboidShape(0, 0, 0, 16, 14, 14); - public static final VoxelShape BODY_NORTH_SHAPE = makeCuboidShape(0, 0, 2, 16, 14, 16); - public static final VoxelShape BODY_EAST_SHAPE = makeCuboidShape(0, 0, 0, 14, 14, 16); - public static final VoxelShape BODY_WEST_SHAPE = makeCuboidShape(2, 0, 0, 16, 14, 16); - - public ShopShelfBlock() { - super(Properties.from(Blocks.SPRUCE_PLANKS)); - } - - @Override - public boolean hasTileEntity(BlockState state) { - return true; - } - - @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { - return new ShopShelfTileEntity(); - } - - @Override - public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { - ShopShelfTileEntity te = (ShopShelfTileEntity) worldIn.getTileEntity(pos); - te.setOwner(placer.getUniqueID()); - worldIn.notifyBlockUpdate(pos, state, state, 2); - } - - @Override - public boolean onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, - BlockRayTraceResult hit) { - ShopShelfTileEntity te = (ShopShelfTileEntity) worldIn.getTileEntity(pos); - if (te == null) - return false; - if (!worldIn.isRemote) - NetworkHooks.openGui((ServerPlayerEntity) player, te, te::sendToContainer); - return true; - } - - @Override - protected void fillStateContainer(Builder builder) { - builder.add(HORIZONTAL_FACING); - super.fillStateContainer(builder); - } - - @Override - public BlockState getStateForPlacement(BlockItemUseContext context) { - return getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); - } - - @Override - public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - VoxelShape body = VoxelShapes.empty(); - switch (state.get(HORIZONTAL_FACING)) { - case EAST: - body = BODY_EAST_SHAPE; - break; - case NORTH: - body = BODY_NORTH_SHAPE; - break; - case SOUTH: - body = BODY_SOUTH_SHAPE; - break; - case WEST: - body = BODY_WEST_SHAPE; - break; - default: - break; - } - - return VoxelShapes.or(TOP_SHAPE, body); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java deleted file mode 100644 index e85d49bf6..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfContainer.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.simibubi.create.modules.economy; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.network.PacketBuffer; - -public class ShopShelfContainer extends Container { - - public ShopShelfContainer(int id, PlayerInventory inv, ShopShelfTileEntity te) { -// super(AllContainers.SHOP_SHELF.type, id); - super(null, id); - } - - public ShopShelfContainer(int id, PlayerInventory inv, PacketBuffer extraData) { -// super(AllContainers.SHOP_SHELF.type, id); - super(null, id); - } - - @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return true; - } - -} diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java deleted file mode 100644 index 93bbe3188..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfScreen.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.simibubi.create.modules.economy; - -import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; - -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.text.ITextComponent; - -public class ShopShelfScreen extends AbstractSimiContainerScreen { - - public ShopShelfScreen(ShopShelfContainer container, PlayerInventory inv, ITextComponent title) { - super(container, inv, title); - } - - @Override - protected void renderWindow(int mouseX, int mouseY, float partialTicks) { - renderTooltip("Hi", mouseX, mouseY); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java b/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java deleted file mode 100644 index e93e94a33..000000000 --- a/src/main/java/com/simibubi/create/modules/economy/ShopShelfTileEntity.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.simibubi.create.modules.economy; - -import java.util.UUID; - -import com.simibubi.create.foundation.block.SyncedTileEntity; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.nbt.NBTUtil; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.StringTextComponent; - -public class ShopShelfTileEntity extends SyncedTileEntity implements INamedContainerProvider { - - private UUID owner; - - public ShopShelfTileEntity() { - super(null); -// super(AllTileEntities.SHOP_SHELF.type); - } - - @Override - public void read(CompoundNBT compound) { - if (compound.contains("Owner")) - setOwner(NBTUtil.readUniqueId(compound.getCompound("Owner"))); - super.read(compound); - } - - @Override - public CompoundNBT write(CompoundNBT compound) { - if (getOwner() != null) - compound.put("Owner", NBTUtil.writeUniqueId(getOwner())); - return super.write(compound); - } - - public UUID getOwner() { - return owner; - } - - public void setOwner(UUID owner) { - this.owner = owner; - } - - public void sendToContainer(PacketBuffer buffer) { - buffer.writeUniqueId(getOwner()); - } - - @Override - public Container createMenu(int id, PlayerInventory inventory, PlayerEntity player) { - return new ShopShelfContainer(id, inventory, this); - } - - @Override - public ITextComponent getDisplayName() { - return new StringTextComponent(getType().getRegistryName().toString()); - } - -} diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java index 777676558..cf00f3da4 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableBlock.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.schematics.block; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -13,6 +14,8 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; @@ -39,6 +42,16 @@ public class SchematicTableBlock extends HorizontalBlock { return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()); } + @Override + public VoxelShape getCollisionShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return AllShapes.LOGISTICS_TABLE_BASE; + } + + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return AllShapes.SCHEMATICS_TABLE.get(state.get(HORIZONTAL_FACING)); + } + @Override public boolean hasTileEntity(BlockState state) { return true; diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java index 7ad4639e0..4eda575f7 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonBlock.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.schematics.block; import com.simibubi.create.AllItems; +import com.simibubi.create.foundation.utility.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -14,6 +15,8 @@ import net.minecraft.util.Direction; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockRayTraceResult; +import net.minecraft.util.math.shapes.ISelectionContext; +import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; import net.minecraft.world.IWorldReader; @@ -48,6 +51,11 @@ public class SchematicannonBlock extends Block { return false; } + @Override + public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + return AllShapes.SCHEMATICANNON_SHAPE; + } + @Override public void onNeighborChange(BlockState state, IWorldReader world, BlockPos pos, BlockPos neighbor) { ((SchematicannonTileEntity) world.getTileEntity(pos)).findInventories();