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..cbccfe65e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java @@ -0,0 +1,138 @@ +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.Vec3d; +import net.minecraft.util.math.shapes.IBooleanFunction; +import net.minecraft.util.math.shapes.VoxelShape; +import net.minecraft.util.math.shapes.VoxelShapes; + +import java.util.Arrays; + +import static net.minecraft.block.Block.makeCuboidShape; + +public class AllShapes { + + public static final VoxelShaper + 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), + 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_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), + 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)), + 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)), + GAUGE_SHAPE_UP = VoxelShapes.or( + makeCuboidShape(1, 0, 0, 15, 2, 16),//plate + makeCuboidShape(2, 2, 1, 14, 14, 15))//log + + ; + + 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 can be improved when someone finds the time :D + CRUSHING_WHEEL_COLLISION_SHAPE = makeCuboidShape(0, 0, 0, 16, 22, 16), + 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, + 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)) + + ; + + + + + 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_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), + 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), + SCHEMATICS_TABLE = VoxelShaper.forDirectional(VoxelShapes.or(TABLE_POLE_SHAPE, SCHEMATICS_TABLE_SLOPE_SOUTH), Direction.SOUTH) + + ; + + public static final GaugeShaper GAUGE = GaugeShaper.make(); + + + public static class GaugeShaper extends VoxelShaper { + + private VoxelShaper axisFalse, axisTrue; + + private static GaugeShaper make(){ + GaugeShaper shaper = new GaugeShaper(); + shaper.axisFalse = forDirectional(AllShapes.GAUGE_SHAPE_UP, Direction.UP); + shaper.axisTrue = forDirectional(rotatedCopy(AllShapes.GAUGE_SHAPE_UP, new Vec3d(0, 90, 0)), Direction.UP); + //shapes for X axis need to be swapped + Arrays.asList(Direction.EAST, Direction.WEST).forEach(direction -> { + VoxelShape mem = shaper.axisFalse.get(direction); + shaper.axisFalse.withShape(shaper.axisTrue.get(direction), direction); + shaper.axisTrue.withShape(mem, direction); + }); + return shaper; + } + + public VoxelShape get(Direction direction, boolean axisAlong) { + return (axisAlong ? axisTrue : axisFalse).get(direction); + } + } +} 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..bc33bc158 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; @@ -25,68 +27,83 @@ 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){ + return forDirectionsWithRotation(shape, facing, Direction.Plane.HORIZONTAL, new HorizontalRotationValues()); } - 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){ + return forDirectionsWithRotation(shape, facing, Arrays.asList(Direction.SOUTH, Direction.EAST), new HorizontalRotationValues()); } - public static VoxelShaper forRotatedPillar(VoxelShape zShape) { + 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); - 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) { - 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)); - } - return voxelShaper; + public static VoxelShaper forDirectional(VoxelShape shape, Direction facing){ + return forDirectionsWithRotation(shape, facing, Arrays.asList(Direction.values()), new DefaultRotationValues()); + } + + 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, 180, 0)); + shapes.put(Direction.DOWN, rotatedCopy(upShape, new Vec3d(180, 0, 0))); return this; } - private static Direction axisAsFace(Axis axis) { + 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 rotX, int rotY) { + protected static float horizontalAngleFromDirection(Direction direction){ + return (float)((Math.max(direction.getHorizontalIndex(), 0) & 3) * 90); + } + + 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)); + } + 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); 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, 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, (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)); @@ -95,4 +112,27 @@ 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), + -horizontalAngleFromDirection(direction), + 0 + ); + } + } + + protected static class HorizontalRotationValues implements Function { + @Override + public Vec3d apply(Direction direction) { + return new Vec3d( + 0, + -horizontalAngleFromDirection(direction), + 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 db6b7972f..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShapers.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.simibubi.create.foundation.utility; - -import net.minecraft.block.Block; - -public class VoxelShapers { - - public static final VoxelShaper SHORT_CASING = VoxelShaper - .forDirectional(Block.makeCuboidShape(0, 0, 0, 16, 16, 12)); - -} 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; + 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 c4015e7b8..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 @@ -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_12_VOXEL.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..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); 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 4b7e5b0a6..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; @@ -9,53 +10,163 @@ 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; 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 = 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, 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, 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); + + 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){ + 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); + } 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) { @@ -66,54 +177,37 @@ 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(); } - protected static VoxelShape createSlope(Direction facing) { - return VoxelShapes.or(createHalfSlope(facing.getOpposite(), false), createHalfSlope(facing, true)); - } + private static class VerticalBeltShaper extends VoxelShaper { - 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; + public static VoxelShaper make(VoxelShape southBeltShape){ + 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/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 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/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 1adee5cb9..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 @@ -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.AllShapes; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -31,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; @@ -48,9 +49,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 +113,20 @@ 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; } } 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();