1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-28 00:12:16 +00:00

fix: wired modem direction

This commit is contained in:
Nikita Savyolov 2021-10-17 21:10:10 +03:00
parent 960d79803d
commit 67b7cd7a14
No known key found for this signature in database
GPG Key ID: 32C1EF023AFC184B
3 changed files with 7 additions and 27 deletions

View File

@ -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 ) public void onPlaced( World world, @Nonnull BlockPos pos, @Nonnull BlockState state, LivingEntity placer, @Nonnull ItemStack stack )
{ {
BlockEntity tile = world.getBlockEntity( pos ); BlockEntity tile = world.getBlockEntity( pos );
if( tile instanceof TileCable ) if( tile instanceof TileCable cable )
{ {
TileCable cable = (TileCable) tile;
if( cable.hasCable() ) if( cable.hasCable() )
{ {
cable.connectionsChanged(); cable.connectionsChanged();

View File

@ -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 ); world.playSound( null, pos, soundType.getPlaceSound(), SoundCategory.BLOCKS, (soundType.getVolume() + 1.0F) / 2.0F, soundType.getPitch() * 0.8F );
BlockEntity tile = world.getBlockEntity( pos ); BlockEntity tile = world.getBlockEntity( pos );
if( tile instanceof TileCable ) if( tile instanceof TileCable cable )
{ {
TileCable cable = (TileCable) tile;
cable.modemChanged(); cable.modemChanged();
cable.connectionsChanged(); cable.connectionsChanged();
} }

View File

@ -46,7 +46,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
private final IWiredNode node = cable.getNode(); private final IWiredNode node = cable.getNode();
private boolean peripheralAccessAllowed; private boolean peripheralAccessAllowed;
private boolean destroyed = false; private boolean destroyed = false;
private Direction modemDirection = Direction.NORTH;
private final WiredModemPeripheral modem = new WiredModemPeripheral( new ModemState( () -> TickScheduler.schedule( this ) ), cable ) private final WiredModemPeripheral modem = new WiredModemPeripheral( new ModemState( () -> TickScheduler.schedule( this ) ), cable )
{ {
@Nonnull @Nonnull
@ -60,7 +59,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Override @Override
public Vec3d getPosition() 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 ); 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; return TileCable.this;
} }
}; };
private boolean hasModemDirection = false;
private boolean connectionsFormed = false; private boolean connectionsFormed = false;
public TileCable( BlockEntityType<? extends TileCable> type, BlockPos pos, BlockState state ) public TileCable( BlockEntityType<? extends TileCable> type, BlockPos pos, BlockState state )
@ -176,8 +174,8 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Nonnull @Nonnull
private Direction getDirection() private Direction getDirection()
{ {
refreshDirection(); Direction direction = getMaybeDirection();
return modemDirection == null ? Direction.NORTH : modemDirection; return direction == null ? Direction.NORTH : direction;
} }
public boolean hasModem() public boolean hasModem()
@ -312,8 +310,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
return; return;
} }
refreshDirection();
if( modem.getModemState() if( modem.getModemState()
.pollChanged() ) .pollChanged() )
{ {
@ -327,7 +323,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
connectionsChanged(); connectionsChanged();
if( peripheralAccessAllowed ) if( peripheralAccessAllowed )
{ {
peripheral.attach( world, pos, modemDirection ); peripheral.attach( world, pos, getDirection() );
updateConnectedPeripherals(); updateConnectedPeripherals();
} }
} }
@ -360,20 +356,7 @@ public class TileCable extends TileGeneric implements IPeripheralTile
@Nullable @Nullable
private Direction getMaybeDirection() private Direction getMaybeDirection()
{ {
refreshDirection(); return getCachedState().get( BlockCable.MODEM ).getFacing();
return modemDirection;
}
private void refreshDirection()
{
if( hasModemDirection )
{
return;
}
hasModemDirection = true;
modemDirection = getCachedState().get( BlockCable.MODEM )
.getFacing();
} }
@Override @Override
@ -412,7 +395,6 @@ public class TileCable extends TileGeneric implements IPeripheralTile
{ {
super.setCachedState( state ); super.setCachedState( state );
if( state != null ) return; if( state != null ) return;
hasModemDirection = false;
if( !world.isClient ) if( !world.isClient )
{ {
world.getBlockTickScheduler() world.getBlockTickScheduler()