couple changes to the new gauge blocks to fit in with voxel shape refactor
Signed-off-by: Zelophed <zefren1@googlemail.com>
This commit is contained in:
parent
81e1eab7e9
commit
c857349b40
3 changed files with 40 additions and 33 deletions
|
@ -4,10 +4,13 @@ import net.minecraft.block.Blocks;
|
||||||
import net.minecraft.block.DirectionalBlock;
|
import net.minecraft.block.DirectionalBlock;
|
||||||
import net.minecraft.block.PistonHeadBlock;
|
import net.minecraft.block.PistonHeadBlock;
|
||||||
import net.minecraft.util.Direction;
|
import net.minecraft.util.Direction;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.math.shapes.IBooleanFunction;
|
import net.minecraft.util.math.shapes.IBooleanFunction;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
import net.minecraft.util.math.shapes.VoxelShapes;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static net.minecraft.block.Block.makeCuboidShape;
|
import static net.minecraft.block.Block.makeCuboidShape;
|
||||||
|
|
||||||
public class AllShapes {
|
public class AllShapes {
|
||||||
|
@ -57,7 +60,10 @@ public class AllShapes {
|
||||||
SCHEMATICS_TABLE_SLOPE_SOUTH = VoxelShapes.or(
|
SCHEMATICS_TABLE_SLOPE_SOUTH = VoxelShapes.or(
|
||||||
makeCuboidShape(0, 10, 16, 16, 14, 11),
|
makeCuboidShape(0, 10, 16, 16, 14, 11),
|
||||||
makeCuboidShape(0, 12, 11, 16, 16, 6),
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,10 @@ public class VoxelShaper {
|
||||||
return Direction.getFacingFromAxis(AxisDirection.POSITIVE, axis);
|
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<Direction> directions, Function<Direction, Vec3d> rotationValues){
|
protected static VoxelShaper forDirectionsWithRotation(VoxelShape shape, Direction facing, Iterable<Direction> directions, Function<Direction, Vec3d> rotationValues){
|
||||||
VoxelShaper voxelShaper = new VoxelShaper();
|
VoxelShaper voxelShaper = new VoxelShaper();
|
||||||
for (Direction dir : directions) {
|
for (Direction dir : directions) {
|
||||||
|
@ -114,7 +118,7 @@ public class VoxelShaper {
|
||||||
public Vec3d apply(Direction direction) {
|
public Vec3d apply(Direction direction) {
|
||||||
return new Vec3d(
|
return new Vec3d(
|
||||||
direction == Direction.UP ? 0 : (Direction.Plane.VERTICAL.test(direction) ? 180 : 90),
|
direction == Direction.UP ? 0 : (Direction.Plane.VERTICAL.test(direction) ? 180 : 90),
|
||||||
Direction.Plane.VERTICAL.test(direction) ? 0 : (int) -direction.getHorizontalAngle(),
|
-horizontalAngleFromDirection(direction),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -125,7 +129,7 @@ public class VoxelShaper {
|
||||||
public Vec3d apply(Direction direction) {
|
public Vec3d apply(Direction direction) {
|
||||||
return new Vec3d(
|
return new Vec3d(
|
||||||
0,
|
0,
|
||||||
-direction.getHorizontalAngle(),
|
-horizontalAngleFromDirection(direction),
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,11 @@
|
||||||
package com.simibubi.create.modules.contraptions.relays.gauge;
|
package com.simibubi.create.modules.contraptions.relays.gauge;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.simibubi.create.foundation.block.RenderUtilityBlock;
|
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.ColorHelper;
|
||||||
import com.simibubi.create.foundation.utility.Lang;
|
import com.simibubi.create.foundation.utility.Lang;
|
||||||
import com.simibubi.create.foundation.utility.VecHelper;
|
import com.simibubi.create.foundation.utility.VecHelper;
|
||||||
import com.simibubi.create.foundation.utility.VoxelShaper;
|
|
||||||
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
import com.simibubi.create.modules.contraptions.base.DirectionalAxisKineticBlock;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.Blocks;
|
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.Vec3d;
|
||||||
import net.minecraft.util.math.shapes.ISelectionContext;
|
import net.minecraft.util.math.shapes.ISelectionContext;
|
||||||
import net.minecraft.util.math.shapes.VoxelShape;
|
import net.minecraft.util.math.shapes.VoxelShape;
|
||||||
import net.minecraft.util.math.shapes.VoxelShapes;
|
|
||||||
import net.minecraft.world.IBlockReader;
|
import net.minecraft.world.IBlockReader;
|
||||||
import net.minecraft.world.IWorldReader;
|
import net.minecraft.world.IWorldReader;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
public class GaugeBlock extends DirectionalAxisKineticBlock {
|
public class GaugeBlock extends DirectionalAxisKineticBlock {
|
||||||
|
|
||||||
protected Type type;
|
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 {
|
public enum Type implements IStringSerializable {
|
||||||
SPEED, STRESS;
|
SPEED, STRESS;
|
||||||
|
|
||||||
|
@ -169,21 +157,7 @@ public class GaugeBlock extends DirectionalAxisKineticBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
|
||||||
Direction facing = state.get(FACING);
|
return AllShapes.GAUGE.get(state.get(FACING), state.get(AXIS_ALONG_FIRST_COORDINATE));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Head extends RenderUtilityBlock {
|
public static class Head extends RenderUtilityBlock {
|
||||||
|
|
Loading…
Reference in a new issue