voxel
This commit is contained in:
parent
ead8d12c6e
commit
6beb4911ac
|
@ -22,6 +22,7 @@ import net.minecraft.util.hit.BlockHitResult;
|
|||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
@ -35,19 +36,18 @@ public class GlowstoneWireBlock extends Block{
|
|||
public static final EnumProperty<GlowWireConnection> WIRE_CONNECTION_WEST;
|
||||
|
||||
// Locally defined DIRECTION <-> WIRE_CONNECTION_DIRECTION
|
||||
public static final Map<Direction, EnumProperty<GlowWireConnection>> DIRECTION_TO_WIRE_CONNECTION_PROPERTY;
|
||||
public static final Map<Direction, EnumProperty<GlowWireConnection>> DIRECTION_TO_WIRE_CONNECTION;
|
||||
|
||||
// Determines the hitbox for our block
|
||||
public static final VoxelShape DOT_SHAPE;
|
||||
public static final VoxelShape DOT_VOXELSHAPE;
|
||||
private static final Map<Direction, VoxelShape> field_24414;
|
||||
private static final Map<Direction, VoxelShape> field_24415;
|
||||
|
||||
// Full sided state
|
||||
private BlockState FULL_STATE;
|
||||
|
||||
public GlowstoneWireBlock(Settings settings) {
|
||||
super(settings);
|
||||
// Set these properties to be none as start, so we start with a dot
|
||||
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WIRE_CONNECTION_NORTH, GlowWireConnection.NONE)).with(WIRE_CONNECTION_EAST, GlowWireConnection.NONE)).with(WIRE_CONNECTION_SOUTH, GlowWireConnection.NONE)).with(WIRE_CONNECTION_WEST, GlowWireConnection.NONE)));
|
||||
this.FULL_STATE = (BlockState)((BlockState)((BlockState)((BlockState)this.getDefaultState().with(WIRE_CONNECTION_NORTH, GlowWireConnection.SIDE)).with(WIRE_CONNECTION_EAST, GlowWireConnection.SIDE)).with(WIRE_CONNECTION_SOUTH, GlowWireConnection.SIDE)).with(WIRE_CONNECTION_WEST, GlowWireConnection.SIDE);
|
||||
}
|
||||
|
||||
// Make sure out block has the properties for us to manage
|
||||
|
@ -81,28 +81,41 @@ public class GlowstoneWireBlock extends Block{
|
|||
Iterator<Direction> dirItr = Direction.Type.HORIZONTAL.iterator();
|
||||
while(dirItr.hasNext()){
|
||||
Direction dir = dirItr.next();
|
||||
if(world.getBlockState(pos.offset(dir)).isOf(this) && !state.get(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(dir)).isBroken())
|
||||
state = state.with(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(dir), determineConnection(world, pos, dir));
|
||||
if(world.getBlockState(pos.offset(dir)).isOf(this) && !state.get(DIRECTION_TO_WIRE_CONNECTION.get(dir)).isBroken())
|
||||
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(dir), determineConnection(world, pos, dir));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
private GlowWireConnection determineConnection(WorldAccess world, BlockPos pos, Direction direction){
|
||||
if(world.getBlockState(pos.offset(direction).up()).isOf(this))
|
||||
if(!world.getBlockState(pos.offset(direction).up()).get(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(direction.getOpposite())).isBroken())
|
||||
if(!world.getBlockState(pos.offset(direction).up()).get(DIRECTION_TO_WIRE_CONNECTION.get(direction.getOpposite())).isBroken())
|
||||
return GlowWireConnection.UP;
|
||||
if(world.getBlockState(pos.offset(direction).down()).isOf(this))
|
||||
if(!world.getBlockState(pos.offset(direction).down()).get(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(direction.getOpposite())).isBroken())
|
||||
if(!world.getBlockState(pos.offset(direction).down()).get(DIRECTION_TO_WIRE_CONNECTION.get(direction.getOpposite())).isBroken())
|
||||
return GlowWireConnection.SIDE;
|
||||
if(world.getBlockState(pos.offset(direction)).isOf(this))
|
||||
if(!world.getBlockState(pos.offset(direction)).get(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(direction.getOpposite())).isBroken()) {
|
||||
if(!world.getBlockState(pos.offset(direction)).get(DIRECTION_TO_WIRE_CONNECTION.get(direction.getOpposite())).isBroken()) {
|
||||
return GlowWireConnection.SIDE;
|
||||
}
|
||||
return GlowWireConnection.NONE;
|
||||
}
|
||||
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return DOT_SHAPE;
|
||||
VoxelShape voxelShape = DOT_VOXELSHAPE;
|
||||
Iterator var3 = Direction.Type.HORIZONTAL.iterator();
|
||||
|
||||
while(var3.hasNext()) {
|
||||
Direction direction = (Direction)var3.next();
|
||||
GlowWireConnection wireConnection = state.get(DIRECTION_TO_WIRE_CONNECTION.get(direction));
|
||||
if (wireConnection == GlowWireConnection.SIDE) {
|
||||
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)field_24414.get(direction));
|
||||
} else if (wireConnection == GlowWireConnection.UP) {
|
||||
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)field_24415.get(direction));
|
||||
}
|
||||
}
|
||||
|
||||
return voxelShape;
|
||||
}
|
||||
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
|
@ -141,7 +154,6 @@ public class GlowstoneWireBlock extends Block{
|
|||
}
|
||||
}
|
||||
|
||||
// This needs to be fixed, it should notify it's neighbors that it shouldn't be connected to me anymore
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
|
||||
if(player.abilities.allowModifyWorld)
|
||||
|
@ -149,8 +161,8 @@ public class GlowstoneWireBlock extends Block{
|
|||
Iterator<Direction> dirItr = Direction.Type.HORIZONTAL.iterator();
|
||||
while(dirItr.hasNext()){
|
||||
Direction dir = dirItr.next();
|
||||
if(state.get(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(dir)).isConnected())
|
||||
state = state.with(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(dir), GlowWireConnection.BROKE);
|
||||
if(state.get(DIRECTION_TO_WIRE_CONNECTION.get(dir)).isConnected())
|
||||
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(dir), GlowWireConnection.BROKE);
|
||||
}
|
||||
world.setBlockState(pos, state);
|
||||
world.updateNeighborsAlways(pos, this);
|
||||
|
@ -161,8 +173,8 @@ public class GlowstoneWireBlock extends Block{
|
|||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState newState, WorldAccess world, BlockPos pos, BlockPos posFrom) {
|
||||
if (direction != Direction.DOWN && direction != Direction.UP && !state.get(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(direction)).isBroken())
|
||||
state = state.with(DIRECTION_TO_WIRE_CONNECTION_PROPERTY.get(direction), determineConnection(world, pos, direction));
|
||||
if (direction != Direction.DOWN && direction != Direction.UP && !state.get(DIRECTION_TO_WIRE_CONNECTION.get(direction)).isBroken())
|
||||
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(direction), determineConnection(world, pos, direction));
|
||||
return state;
|
||||
}
|
||||
|
||||
|
@ -185,9 +197,11 @@ public class GlowstoneWireBlock extends Block{
|
|||
WIRE_CONNECTION_SOUTH = EnumProperty.of("south", GlowWireConnection.class);
|
||||
WIRE_CONNECTION_WEST = EnumProperty.of("west", GlowWireConnection.class);
|
||||
|
||||
DIRECTION_TO_WIRE_CONNECTION_PROPERTY = Maps.newEnumMap((Map)ImmutableMap.of(Direction.NORTH, WIRE_CONNECTION_NORTH, Direction.EAST, WIRE_CONNECTION_EAST, Direction.SOUTH, WIRE_CONNECTION_SOUTH, Direction.WEST, WIRE_CONNECTION_WEST));
|
||||
DIRECTION_TO_WIRE_CONNECTION = Maps.newEnumMap((Map)ImmutableMap.of(Direction.NORTH, WIRE_CONNECTION_NORTH, Direction.EAST, WIRE_CONNECTION_EAST, Direction.SOUTH, WIRE_CONNECTION_SOUTH, Direction.WEST, WIRE_CONNECTION_WEST));
|
||||
|
||||
DOT_SHAPE = Block.createCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D);
|
||||
|
||||
DOT_VOXELSHAPE = Block.createCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D);
|
||||
field_24414 = Maps.newEnumMap((Map)ImmutableMap.of(Direction.NORTH, Block.createCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 1.0D, 13.0D), Direction.SOUTH, Block.createCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 1.0D, 16.0D), Direction.EAST, Block.createCuboidShape(3.0D, 0.0D, 3.0D, 16.0D, 1.0D, 13.0D), Direction.WEST, Block.createCuboidShape(0.0D, 0.0D, 3.0D, 13.0D, 1.0D, 13.0D)));
|
||||
field_24415 = Maps.newEnumMap((Map)ImmutableMap.of(Direction.NORTH, VoxelShapes.union((VoxelShape)field_24414.get(Direction.NORTH), Block.createCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 16.0D, 1.0D)), Direction.SOUTH, VoxelShapes.union((VoxelShape)field_24414.get(Direction.SOUTH), Block.createCuboidShape(3.0D, 0.0D, 15.0D, 13.0D, 16.0D, 16.0D)), Direction.EAST, VoxelShapes.union((VoxelShape)field_24414.get(Direction.EAST), Block.createCuboidShape(15.0D, 0.0D, 3.0D, 16.0D, 16.0D, 13.0D)), Direction.WEST, VoxelShapes.union((VoxelShape)field_24414.get(Direction.WEST), Block.createCuboidShape(0.0D, 0.0D, 3.0D, 1.0D, 16.0D, 13.0D))));
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue