Discharge cable on shock. Closes #2178
This commit is contained in:
parent
a0644ac434
commit
dc1e459ad6
1 changed files with 15 additions and 11 deletions
|
@ -102,9 +102,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
|
||||||
|
|
||||||
public BooleanProperty getProperty(Direction facing) {
|
public BooleanProperty getProperty(Direction facing) {
|
||||||
switch (facing) {
|
switch (facing) {
|
||||||
case EAST:
|
case WEST:
|
||||||
return EAST;
|
|
||||||
case WEST:
|
|
||||||
return WEST;
|
return WEST;
|
||||||
case NORTH:
|
case NORTH:
|
||||||
return NORTH;
|
return NORTH;
|
||||||
|
@ -120,18 +118,18 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockState makeConnections(World world, BlockPos pos) {
|
private BlockState makeConnections(World world, BlockPos pos) {
|
||||||
Boolean down = canConnectTo(world, pos.offset(Direction.DOWN, 1), Direction.UP);
|
Boolean down = canConnectTo(world, pos.down());
|
||||||
Boolean up = canConnectTo(world, pos.up(), Direction.DOWN);
|
Boolean up = canConnectTo(world, pos.up());
|
||||||
Boolean north = canConnectTo(world, pos.north(), Direction.SOUTH);
|
Boolean north = canConnectTo(world, pos.north());
|
||||||
Boolean east = canConnectTo(world, pos.east(), Direction.WEST);
|
Boolean east = canConnectTo(world, pos.east());
|
||||||
Boolean south = canConnectTo(world, pos.south(), Direction.NORTH);
|
Boolean south = canConnectTo(world, pos.south());
|
||||||
Boolean west = canConnectTo(world, pos.west(), Direction.WEST);
|
Boolean west = canConnectTo(world, pos.west());
|
||||||
|
|
||||||
return this.getDefaultState().with(DOWN, down).with(UP, up).with(NORTH, north).with(EAST, east)
|
return this.getDefaultState().with(DOWN, down).with(UP, up).with(NORTH, north).with(EAST, east)
|
||||||
.with(SOUTH, south).with(WEST, west);
|
.with(SOUTH, south).with(WEST, west);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Boolean canConnectTo(WorldAccess world, BlockPos pos, Direction facing) {
|
private Boolean canConnectTo(WorldAccess world, BlockPos pos) {
|
||||||
BlockEntity blockEntity = world.getBlockEntity(pos);
|
BlockEntity blockEntity = world.getBlockEntity(pos);
|
||||||
if (blockEntity != null && (Energy.valid(blockEntity) || blockEntity instanceof CableBlockEntity)) {
|
if (blockEntity != null && (Energy.valid(blockEntity) || blockEntity instanceof CableBlockEntity)) {
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
|
@ -152,6 +150,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block
|
// Block
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
|
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
|
||||||
ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND);
|
ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND);
|
||||||
|
@ -199,16 +198,18 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
|
||||||
.with(WATERLOGGED, context.getWorld().getFluidState(context.getBlockPos()).getFluid() == Fluids.WATER);
|
.with(WATERLOGGED, context.getWorld().getFluidState(context.getBlockPos()).getFluid() == Fluids.WATER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public BlockState getStateForNeighborUpdate(BlockState ourState, Direction ourFacing, BlockState otherState,
|
public BlockState getStateForNeighborUpdate(BlockState ourState, Direction ourFacing, BlockState otherState,
|
||||||
WorldAccess worldIn, BlockPos ourPos, BlockPos otherPos) {
|
WorldAccess worldIn, BlockPos ourPos, BlockPos otherPos) {
|
||||||
if (ourState.get(WATERLOGGED)) {
|
if (ourState.get(WATERLOGGED)) {
|
||||||
worldIn.getFluidTickScheduler().schedule(ourPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
|
worldIn.getFluidTickScheduler().schedule(ourPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
|
||||||
}
|
}
|
||||||
Boolean value = canConnectTo(worldIn, otherPos, ourFacing.getOpposite());
|
Boolean value = canConnectTo(worldIn, otherPos);
|
||||||
return ourState.with(getProperty(ourFacing), value);
|
return ourState.with(getProperty(ourFacing), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext shapeContext) {
|
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext shapeContext) {
|
||||||
if (state.get(COVERED)) {
|
if (state.get(COVERED)) {
|
||||||
|
@ -217,6 +218,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
|
||||||
return cableShapeUtil.getShape(state);
|
return cableShapeUtil.getShape(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
|
public void onEntityCollision(BlockState state, World worldIn, BlockPos pos, Entity entityIn) {
|
||||||
super.onEntityCollision(state, worldIn, pos, entityIn);
|
super.onEntityCollision(state, worldIn, pos, entityIn);
|
||||||
|
@ -245,6 +247,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
|
||||||
entityIn.setOnFireFor(1);
|
entityIn.setOnFireFor(1);
|
||||||
}
|
}
|
||||||
entityIn.damage(new ElectrialShockSource(), 1F);
|
entityIn.damage(new ElectrialShockSource(), 1F);
|
||||||
|
blockEntityCable.setEnergy(0d);
|
||||||
}
|
}
|
||||||
if (TechRebornConfig.uninsulatedElectrocutionSound) {
|
if (TechRebornConfig.uninsulatedElectrocutionSound) {
|
||||||
worldIn.playSound(null, entityIn.getX(), entityIn.getY(), entityIn.getZ(), ModSounds.CABLE_SHOCK, SoundCategory.BLOCKS,
|
worldIn.playSound(null, entityIn.getX(), entityIn.getY(), entityIn.getZ(), ModSounds.CABLE_SHOCK, SoundCategory.BLOCKS,
|
||||||
|
@ -265,6 +268,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
|
||||||
return !state.get(COVERED) && Waterloggable.super.canFillWithFluid(view, pos, state, fluid);
|
return !state.get(COVERED) && Waterloggable.super.canFillWithFluid(view, pos, state, fluid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public FluidState getFluidState(BlockState state) {
|
public FluidState getFluidState(BlockState state) {
|
||||||
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
|
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue