diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java index 6388751e5..11a3a1312 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/BlockCable.java @@ -232,9 +232,8 @@ public class BlockCable extends BlockGeneric implements Waterloggable public void onPlaced( World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack ) { BlockEntity tile = world.getBlockEntity( pos ); - if( tile instanceof TileCable ) + if( tile instanceof TileCable cable ) { - TileCable cable = (TileCable) tile; if( cable.hasCable() ) { cable.connectionsChanged(); diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java index 8e6cc47e7..eb86b95f5 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/ItemBlockCable.java @@ -56,9 +56,8 @@ public abstract class ItemBlockCable extends BlockItem world.playSound( null, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F ); BlockEntity tile = world.getBlockEntity( pos ); - if( tile instanceof TileCable ) + if( tile instanceof TileCable cable ) { - TileCable cable = (TileCable) tile; cable.modemChanged(); cable.connectionsChanged(); } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java index 9795fa1ef..077486c8e 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/wired/TileCable.java @@ -46,7 +46,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile private final IWiredNode node = cable.getNode(); private boolean peripheralAccessAllowed; private boolean destroyed = false; - private Direction modemDirection = Direction.NORTH; private final WiredModemPeripheral modem = new WiredModemPeripheral( new ModemState( () -> TickScheduler.schedule( this ) ), cable ) { @Nonnull @@ -60,7 +59,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile @Override public Vec3d getPosition() { - BlockPos pos = getPos().offset( modemDirection ); + BlockPos pos = getPos().offset( getDirection() ); return new Vec3d( pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5 ); } @@ -71,7 +70,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile return TileCable.this; } }; - private boolean hasModemDirection = false; private boolean connectionsFormed = false; public TileCable( BlockEntityType type, BlockPos pos, BlockState state ) @@ -176,8 +174,8 @@ public class TileCable extends TileGeneric implements IPeripheralTile @Nonnull private Direction getDirection() { - refreshDirection(); - return modemDirection == null ? Direction.NORTH : modemDirection; + Direction direction = getMaybeDirection(); + return direction == null ? Direction.NORTH : direction; } public boolean hasModem() @@ -312,8 +310,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile return; } - refreshDirection(); - if( modem.getModemState() .pollChanged() ) { @@ -327,7 +323,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile connectionsChanged(); if( peripheralAccessAllowed ) { - peripheral.attach( world, pos, modemDirection ); + peripheral.attach( world, pos, getDirection() ); updateConnectedPeripherals(); } } @@ -360,20 +356,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile @Nullable private Direction getMaybeDirection() { - refreshDirection(); - return modemDirection; - } - - private void refreshDirection() - { - if( hasModemDirection ) - { - return; - } - - hasModemDirection = true; - modemDirection = getCachedState().get( BlockCable.MODEM ) - .getFacing(); + return getCachedState().get( BlockCable.MODEM ).getFacing(); } @Override @@ -412,7 +395,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile { super.setCachedState( state ); if( state != null ) return; - hasModemDirection = false; if( !world.isClient ) { world.getBlockTickScheduler()