|
|
|
@ -4,14 +4,20 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
import com.google.common.collect.UnmodifiableIterator;
|
|
|
|
|
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
|
import net.minecraft.block.ShapeContext;
|
|
|
|
|
import net.minecraft.entity.EquipmentSlot;
|
|
|
|
|
import net.minecraft.entity.LivingEntity;
|
|
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
|
|
|
|
import net.minecraft.item.ItemPlacementContext;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.state.StateManager;
|
|
|
|
|
import net.minecraft.state.property.EnumProperty;
|
|
|
|
|
import net.minecraft.util.ActionResult;
|
|
|
|
@ -40,14 +46,20 @@ public class GlowstoneWireBlock extends Block{
|
|
|
|
|
|
|
|
|
|
// Determines the hitbox for our block
|
|
|
|
|
public static final VoxelShape DOT_VOXELSHAPE;
|
|
|
|
|
private static final Map<Direction, VoxelShape> field_24414;
|
|
|
|
|
private static final Map<Direction, VoxelShape> field_24415;
|
|
|
|
|
private static final Map<Direction, VoxelShape> DIRECTION_HITBOX, UP_HITBOX;
|
|
|
|
|
private final Map<BlockState, VoxelShape> STATE_TO_VOXELSHAPE = Maps.newHashMap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
|
|
|
|
|
UnmodifiableIterator stateItr = this.getStateManager().getStates().iterator();
|
|
|
|
|
while(stateItr.hasNext()) {
|
|
|
|
|
BlockState state = (BlockState)stateItr.next();
|
|
|
|
|
this.STATE_TO_VOXELSHAPE.put(state, determineVoxelShape(state));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Make sure out block has the properties for us to manage
|
|
|
|
@ -56,20 +68,6 @@ public class GlowstoneWireBlock extends Block{
|
|
|
|
|
builder.add(WIRE_CONNECTION_NORTH, WIRE_CONNECTION_EAST, WIRE_CONNECTION_SOUTH, WIRE_CONNECTION_WEST);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean isFullyConnected(BlockState state) {
|
|
|
|
|
return ((GlowWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() &&
|
|
|
|
|
((GlowWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() &&
|
|
|
|
|
((GlowWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() &&
|
|
|
|
|
((GlowWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean isNotConnected(BlockState state) {
|
|
|
|
|
return !((GlowWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() &&
|
|
|
|
|
!((GlowWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() &&
|
|
|
|
|
!((GlowWireConnection)state.get(WIRE_CONNECTION_EAST)).isConnected() &&
|
|
|
|
|
!((GlowWireConnection)state.get(WIRE_CONNECTION_WEST)).isConnected();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static boolean hasConnection(BlockState state) {
|
|
|
|
|
return ((GlowWireConnection)state.get(WIRE_CONNECTION_NORTH)).isConnected() ||
|
|
|
|
|
((GlowWireConnection)state.get(WIRE_CONNECTION_SOUTH)).isConnected() ||
|
|
|
|
@ -81,40 +79,52 @@ 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.get(dir)).isBroken())
|
|
|
|
|
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(dir), determineConnection(world, pos, dir));
|
|
|
|
|
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.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.get(direction.getOpposite())).isBroken())
|
|
|
|
|
if((world.getBlockState(pos.offset(direction).up()).isOf(this) && world.isAir(pos.up()))) // If offset+up is me && if up is air
|
|
|
|
|
if(!world.getBlockState(pos.offset(direction).up()).get(DIRECTION_TO_WIRE_CONNECTION.get(direction.getOpposite())).isBroken()) //if offset+up is not broken
|
|
|
|
|
if(world.getBlockState(pos.offset(direction)).hasSidedTransparency())
|
|
|
|
|
return GlowWireConnection.SIDE;
|
|
|
|
|
else
|
|
|
|
|
return GlowWireConnection.UP;
|
|
|
|
|
if(world.getBlockState(pos.offset(direction).down()).isOf(this) && world.isAir(pos.offset(direction))) // if offset+down is me && if offset is air
|
|
|
|
|
if(!world.getBlockState(pos.offset(direction).down()).get(DIRECTION_TO_WIRE_CONNECTION.get(direction.getOpposite())).isBroken()) //if offset+down is not broken
|
|
|
|
|
return GlowWireConnection.SIDE;
|
|
|
|
|
if(world.getBlockState(pos.offset(direction)).isOf(this))
|
|
|
|
|
if(!world.getBlockState(pos.offset(direction)).get(DIRECTION_TO_WIRE_CONNECTION.get(direction.getOpposite())).isBroken()) {
|
|
|
|
|
if(world.getBlockState(pos.offset(direction)).isOf(this)) // if offset is me
|
|
|
|
|
if(!world.getBlockState(pos.offset(direction)).get(DIRECTION_TO_WIRE_CONNECTION.get(direction.getOpposite())).isBroken()) // if offset is not broken
|
|
|
|
|
return GlowWireConnection.SIDE;
|
|
|
|
|
}
|
|
|
|
|
return GlowWireConnection.NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
|
|
|
|
return STATE_TO_VOXELSHAPE.get(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public VoxelShape determineVoxelShape(BlockState state){
|
|
|
|
|
VoxelShape voxelShape = DOT_VOXELSHAPE;
|
|
|
|
|
Iterator var3 = Direction.Type.HORIZONTAL.iterator();
|
|
|
|
|
|
|
|
|
|
while(var3.hasNext()) {
|
|
|
|
|
Direction direction = (Direction)var3.next();
|
|
|
|
|
|
|
|
|
|
Iterator dirItr1 = Direction.Type.HORIZONTAL.iterator();
|
|
|
|
|
while(dirItr1.hasNext()) {
|
|
|
|
|
Direction direction = (Direction)dirItr1.next();
|
|
|
|
|
GlowWireConnection wireConnection = state.get(DIRECTION_TO_WIRE_CONNECTION.get(direction));
|
|
|
|
|
if (wireConnection == GlowWireConnection.SIDE) {
|
|
|
|
|
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)field_24414.get(direction));
|
|
|
|
|
if(state.equals(this.getDefaultState().with(DIRECTION_TO_WIRE_CONNECTION.get(direction), GlowWireConnection.SIDE))) {
|
|
|
|
|
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)DIRECTION_HITBOX.get(direction));
|
|
|
|
|
return VoxelShapes.union(voxelShape, DIRECTION_HITBOX.get(direction.getOpposite()));
|
|
|
|
|
} else if (state.equals(this.getDefaultState().with(DIRECTION_TO_WIRE_CONNECTION.get(direction), GlowWireConnection.UP))) {
|
|
|
|
|
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)UP_HITBOX.get(direction));
|
|
|
|
|
return VoxelShapes.union(voxelShape, DIRECTION_HITBOX.get(direction.getOpposite()));
|
|
|
|
|
} else if (wireConnection == GlowWireConnection.SIDE) {
|
|
|
|
|
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)DIRECTION_HITBOX.get(direction));
|
|
|
|
|
} else if (wireConnection == GlowWireConnection.UP) {
|
|
|
|
|
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)field_24415.get(direction));
|
|
|
|
|
voxelShape = VoxelShapes.union(voxelShape, (VoxelShape)UP_HITBOX.get(direction));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return voxelShape;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -140,7 +150,7 @@ public class GlowstoneWireBlock extends Block{
|
|
|
|
|
default:
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public BlockState mirror(BlockState state, BlockMirror mirror) {
|
|
|
|
@ -152,9 +162,10 @@ public class GlowstoneWireBlock extends Block{
|
|
|
|
|
default:
|
|
|
|
|
return super.mirror(state, mirror);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
// Place block check disconnect (if block block connection)
|
|
|
|
|
@Override // For each link, set to break and update the blocks around me (above and below)
|
|
|
|
|
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit){
|
|
|
|
|
if(player.abilities.allowModifyWorld)
|
|
|
|
|
if(hasConnection(state) && !player.hasStackEquipped(EquipmentSlot.MAINHAND)) {
|
|
|
|
@ -162,34 +173,53 @@ public class GlowstoneWireBlock extends Block{
|
|
|
|
|
while(dirItr.hasNext()){
|
|
|
|
|
Direction dir = dirItr.next();
|
|
|
|
|
if(state.get(DIRECTION_TO_WIRE_CONNECTION.get(dir)).isConnected())
|
|
|
|
|
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(dir), GlowWireConnection.BROKE);
|
|
|
|
|
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(dir), GlowWireConnection.BROKE);
|
|
|
|
|
}
|
|
|
|
|
world.setBlockState(pos, state);
|
|
|
|
|
world.updateNeighborsAlways(pos, this);
|
|
|
|
|
// These call neighborUpdate not getStateForNeighborUpdate!!
|
|
|
|
|
//world.updateNeighborsAlways(pos, this); // Update those around me
|
|
|
|
|
world.updateNeighbors(pos.down(), this); // Update those below me
|
|
|
|
|
world.updateNeighbors(pos.up(), this); // Update those above me
|
|
|
|
|
return ActionResult.SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
return ActionResult.PASS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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.get(direction)).isBroken())
|
|
|
|
|
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(direction), determineConnection(world, pos, direction));
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Override // Get the state I should place in, and update those around me (above/below) as needed
|
|
|
|
|
public BlockState getPlacementState(ItemPlacementContext ctx){
|
|
|
|
|
return determineState(ctx.getWorld(), this.getDefaultState(), ctx.getBlockPos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onPlaced(World world, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack itemStack) {
|
|
|
|
|
world.updateNeighbors(pos.offset(Direction.UP), state.getBlock());
|
|
|
|
|
world.updateNeighbors(pos.offset(Direction.DOWN), state.getBlock());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // This causes w/e issue that tracks deal with.
|
|
|
|
|
public void onBroken(WorldAccess world, BlockPos pos, BlockState state) {
|
|
|
|
|
world.updateNeighbors(pos.offset(Direction.UP), state.getBlock());
|
|
|
|
|
world.updateNeighbors(pos.offset(Direction.DOWN), state.getBlock());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override // Called when I get told to update, so I should see what/why I need to update. I also use this to determine if I need to be drop or not.
|
|
|
|
|
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block block, BlockPos fromPos, boolean notify) {
|
|
|
|
|
if (!world.isClient && !state.canPlaceAt(world, pos)) {
|
|
|
|
|
dropStacks(state, world, pos);
|
|
|
|
|
world.removeBlock(pos, false);
|
|
|
|
|
if (!world.isClient) {
|
|
|
|
|
if(!state.canPlaceAt(world, pos)) {
|
|
|
|
|
dropStacks(state, world, pos);
|
|
|
|
|
world.removeBlock(pos, false);
|
|
|
|
|
this.onBroken(world, pos, state);
|
|
|
|
|
} else {
|
|
|
|
|
Iterator<Direction> dirItr = Direction.Type.HORIZONTAL.iterator();
|
|
|
|
|
while(dirItr.hasNext()){
|
|
|
|
|
Direction dir = dirItr.next();
|
|
|
|
|
if(!state.get(DIRECTION_TO_WIRE_CONNECTION.get(dir)).isBroken())
|
|
|
|
|
state = state.with(DIRECTION_TO_WIRE_CONNECTION.get(dir), determineConnection(world, pos, dir));
|
|
|
|
|
}
|
|
|
|
|
world.setBlockState(pos, state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
WIRE_CONNECTION_NORTH = EnumProperty.of("north", GlowWireConnection.class);
|
|
|
|
@ -197,11 +227,27 @@ 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 = 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_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))));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DIRECTION_HITBOX = 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))
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
UP_HITBOX = Maps.newEnumMap((Map)ImmutableMap.of(
|
|
|
|
|
Direction.NORTH, VoxelShapes.union((VoxelShape)DIRECTION_HITBOX.get(Direction.NORTH), Block.createCuboidShape(3.0D, 0.0D, 0.0D, 13.0D, 16.0D, 1.0D)),
|
|
|
|
|
Direction.SOUTH, VoxelShapes.union((VoxelShape)DIRECTION_HITBOX.get(Direction.SOUTH), Block.createCuboidShape(3.0D, 0.0D, 15.0D, 13.0D, 16.0D, 16.0D)),
|
|
|
|
|
Direction.EAST, VoxelShapes.union((VoxelShape)DIRECTION_HITBOX.get(Direction.EAST), Block.createCuboidShape(15.0D, 0.0D, 3.0D, 16.0D, 16.0D, 13.0D)),
|
|
|
|
|
Direction.WEST, VoxelShapes.union((VoxelShape)DIRECTION_HITBOX.get(Direction.WEST), Block.createCuboidShape(0.0D, 0.0D, 3.0D, 1.0D, 16.0D, 13.0D)))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|