Abstracted code
This commit is contained in:
@@ -43,64 +43,48 @@ public class CableBlock extends Block {
|
||||
@Override
|
||||
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock,
|
||||
WireOrientation wireOrientation, boolean notify) {
|
||||
boolean north = world.getBlockState(pos.north()).getBlock() instanceof CableBlock;
|
||||
boolean south = world.getBlockState(pos.south()).getBlock() instanceof CableBlock;
|
||||
boolean east = world.getBlockState(pos.east()).getBlock() instanceof CableBlock;
|
||||
boolean west = world.getBlockState(pos.west()).getBlock() instanceof CableBlock;
|
||||
boolean up = world.getBlockState(pos.up()).getBlock() instanceof CableBlock;
|
||||
boolean down = world.getBlockState(pos.down()).getBlock() instanceof CableBlock;
|
||||
|
||||
world.setBlockState(pos, state
|
||||
.with(NORTH, north)
|
||||
.with(SOUTH, south)
|
||||
.with(EAST, east)
|
||||
.with(WEST, west)
|
||||
.with(UP, up)
|
||||
.with(DOWN, down), 2);
|
||||
updateStates(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
boolean north = world.getBlockState(pos.north()).getBlock() instanceof CableBlock;
|
||||
boolean south = world.getBlockState(pos.south()).getBlock() instanceof CableBlock;
|
||||
boolean east = world.getBlockState(pos.east()).getBlock() instanceof CableBlock;
|
||||
boolean west = world.getBlockState(pos.west()).getBlock() instanceof CableBlock;
|
||||
boolean up = world.getBlockState(pos.up()).getBlock() instanceof CableBlock;
|
||||
boolean down = world.getBlockState(pos.down()).getBlock() instanceof CableBlock;
|
||||
|
||||
world.setBlockState(pos, state
|
||||
.with(NORTH, north)
|
||||
.with(SOUTH, south)
|
||||
.with(EAST, east)
|
||||
.with(WEST, west)
|
||||
.with(UP, up)
|
||||
.with(DOWN, down), 2);
|
||||
updateStates(world, pos, state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
VoxelShape shape = Block.createCuboidShape(6, 6, 6, 10, 10, 10);
|
||||
|
||||
boolean north = state.get(NORTH);
|
||||
boolean south = state.get(SOUTH);
|
||||
boolean east = state.get(EAST);
|
||||
boolean west = state.get(WEST);
|
||||
boolean up = state.get(UP);
|
||||
boolean down = state.get(DOWN);
|
||||
|
||||
if (north || (south && !east && !west && !up && !down))
|
||||
if (state.get(NORTH))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 0, 10, 10, 6));
|
||||
if (south || (north && !east && !west && !up && !down))
|
||||
if (state.get(SOUTH))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 10, 10, 10, 16));
|
||||
if (east || (!north && !south && west && !up && !down))
|
||||
if (state.get(EAST))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(10, 6, 6, 16, 10, 10));
|
||||
if (west || (!north && !south && east && !up && !down))
|
||||
if (state.get(WEST))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(0, 6, 6, 6, 10, 10));
|
||||
if (up || (down && !north && !south && !east && !west))
|
||||
if (state.get(UP))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 6, 6, 10, 16, 10));
|
||||
if (down || (up && !north && !south && !east && !west))
|
||||
if (state.get(DOWN))
|
||||
shape = VoxelShapes.union(shape, Block.createCuboidShape(6, 0, 6, 10, 6, 10));
|
||||
|
||||
return shape;
|
||||
}
|
||||
|
||||
private void updateStates(World world, BlockPos pos, BlockState state) {
|
||||
boolean north = world.getBlockState(pos.north()).getBlock() instanceof CableBlock;
|
||||
boolean south = world.getBlockState(pos.south()).getBlock() instanceof CableBlock;
|
||||
boolean east = world.getBlockState(pos.east()).getBlock() instanceof CableBlock;
|
||||
boolean west = world.getBlockState(pos.west()).getBlock() instanceof CableBlock;
|
||||
boolean up = world.getBlockState(pos.up()).getBlock() instanceof CableBlock;
|
||||
boolean down = world.getBlockState(pos.down()).getBlock() instanceof CableBlock;
|
||||
|
||||
world.setBlockState(pos, state
|
||||
.with(NORTH, north || (south && !east && !west && !up && !down))
|
||||
.with(SOUTH, south || (north && !east && !west && !up && !down))
|
||||
.with(EAST, east || (!north && !south && west && !up && !down))
|
||||
.with(WEST, west || (!north && !south && east && !up && !down))
|
||||
.with(UP, up || (down && !north && !south && !east && !west))
|
||||
.with(DOWN, down || (up && !north && !south && !east && !west)), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,18 +4,9 @@
|
||||
|
||||
{ "when": { "up": "true" }, "apply": { "model": "redstone-rewired:block/cable_up" } },
|
||||
{ "when": { "down": "true" }, "apply": { "model": "redstone-rewired:block/cable_down" } },
|
||||
|
||||
{ "when": { "north": "false", "south": "false", "east": "false", "west": "false", "up": "true", "down": "false" }, "apply": { "model": "redstone-rewired:block/cable_down" } },
|
||||
{ "when": { "north": "false", "south": "false", "east": "false", "west": "false", "up": "false", "down": "true" }, "apply": { "model": "redstone-rewired:block/cable_up" } },
|
||||
|
||||
{ "when": { "north": "true" }, "apply": { "model": "redstone-rewired:block/cable_north" } },
|
||||
{ "when": { "south": "true" }, "apply": { "model": "redstone-rewired:block/cable_south" } },
|
||||
{ "when": { "east": "true" }, "apply": { "model": "redstone-rewired:block/cable_east" } },
|
||||
{ "when": { "west": "true" }, "apply": { "model": "redstone-rewired:block/cable_west" } },
|
||||
|
||||
{ "when": { "north": "true", "south": "false", "east": "false", "west": "false", "up": "false", "down": "false" }, "apply": { "model": "redstone-rewired:block/cable_south" } },
|
||||
{ "when": { "north": "false", "south": "true", "east": "false", "west": "false", "up": "false", "down": "false" }, "apply": { "model": "redstone-rewired:block/cable_north" } },
|
||||
{ "when": { "north": "false", "south": "false", "east": "true", "west": "false", "up": "false", "down": "false" }, "apply": { "model": "redstone-rewired:block/cable_west" } },
|
||||
{ "when": { "north": "false", "south": "false", "east": "false", "west": "true", "up": "false", "down": "false" }, "apply": { "model": "redstone-rewired:block/cable_east" } }
|
||||
{ "when": { "west": "true" }, "apply": { "model": "redstone-rewired:block/cable_west" } }
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user