From c857349b407c095e117ca1f351a5ebfb639a176e Mon Sep 17 00:00:00 2001 From: zelophed Date: Tue, 10 Dec 2019 23:40:12 +0100 Subject: [PATCH] couple changes to the new gauge blocks to fit in with voxel shape refactor Signed-off-by: Zelophed --- .../create/foundation/utility/AllShapes.java | 31 ++++++++++++++++- .../foundation/utility/VoxelShaper.java | 8 +++-- .../contraptions/relays/gauge/GaugeBlock.java | 34 +++---------------- 3 files changed, 40 insertions(+), 33 deletions(-) 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 6a7c0663a..cbccfe65e 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java +++ b/src/main/java/com/simibubi/create/foundation/utility/AllShapes.java @@ -4,10 +4,13 @@ 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 { @@ -57,7 +60,10 @@ public class AllShapes { 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)) + 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 ; @@ -105,5 +111,28 @@ public class AllShapes { ; + 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 b043a6059..bc33bc158 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/VoxelShaper.java @@ -67,6 +67,10 @@ public class VoxelShaper { return Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis); } + 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) { @@ -114,7 +118,7 @@ public class VoxelShaper { 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(), + -horizontalAngleFromDirection(direction), 0 ); } @@ -125,7 +129,7 @@ public class VoxelShaper { public Vec3d apply(Direction direction) { return new Vec3d( 0, - -direction.getHorizontalAngle(), + -horizontalAngleFromDirection(direction), 0 ); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java index 7caa46e6b..c878cb573 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/gauge/GaugeBlock.java @@ -1,14 +1,11 @@ package com.simibubi.create.modules.contraptions.relays.gauge; -import java.util.Random; - import com.simibubi.create.foundation.block.RenderUtilityBlock; +import com.simibubi.create.foundation.utility.AllShapes; import com.simibubi.create.foundation.utility.ColorHelper; import com.simibubi.create.foundation.utility.Lang; import com.simibubi.create.foundation.utility.VecHelper; -import com.simibubi.create.foundation.utility.VoxelShaper; import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock; - import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -28,25 +25,16 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; 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.IWorldReader; import net.minecraft.world.World; +import java.util.Random; + public class GaugeBlock extends DirectionalAxisKineticBlock { protected Type type; - protected VoxelShape LOG = makeCuboidShape(1, 2, 2, 15, 14, 14); - protected VoxelShaper PLATE = VoxelShaper.forDirectional(makeCuboidShape(0, 1, 0, 16, 15, 2)); - - protected VoxelShaper ON_WALL_HORIZONTAL = VoxelShaper - .forHorizontal(VoxelShapes.or(PLATE.get(Direction.SOUTH), LOG)); - protected VoxelShaper ON_WALL_VERTICAL = VoxelShaper - .forHorizontal(VoxelShapes.or(makeCuboidShape(1, 0, 0, 15, 16, 2), makeCuboidShape(2, 1, 2, 14, 15, 14))); - protected VoxelShaper ON_GROUND = VoxelShaper.forHorizontalAxis(VoxelShapes.or(PLATE.get(Direction.UP), LOG)); - protected VoxelShaper ON_CEILING = VoxelShaper.forHorizontalAxis(VoxelShapes.or(PLATE.get(Direction.DOWN), LOG)); - public enum Type implements IStringSerializable { SPEED, STRESS; @@ -169,21 +157,7 @@ public class GaugeBlock extends DirectionalAxisKineticBlock { @Override public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { - Direction facing = state.get(FACING); - Axis axis = getRotationAxis(state); - - if (facing.getAxis().isHorizontal()) { - if (axis.isHorizontal()) - return ON_WALL_HORIZONTAL.get(facing); - return ON_WALL_VERTICAL.get(facing); - } - - axis = axis == Axis.X ? Axis.Z : Axis.X; - if (facing == Direction.UP) - return ON_GROUND.get(axis); - if (facing == Direction.DOWN) - return ON_CEILING.get(axis); - return VoxelShapes.empty(); + return AllShapes.GAUGE.get(state.get(FACING), state.get(AXIS_ALONG_FIRST_COORDINATE)); } public static class Head extends RenderUtilityBlock {