From b2aa390ae17074ce4432192984eab082656d7d8a Mon Sep 17 00:00:00 2001 From: SquidDev Date: Mon, 16 Apr 2018 15:47:32 +0100 Subject: [PATCH] Split up modem and connection invalidation --- .../shared/peripheral/common/BlockCable.java | 5 +++-- .../shared/peripheral/common/ItemCable.java | 10 ++++++---- .../shared/peripheral/modem/TileCable.java | 19 +++++++------------ .../peripheral/modem/TileWiredModemFull.java | 7 +++---- 4 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java index f0e04a4db..1bc836837 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/BlockCable.java @@ -332,7 +332,8 @@ public class BlockCable extends BlockPeripheralBase item = PeripheralItemFactory.create( PeripheralType.Cable, null, 1 ); } - cable.networkChanged(); + cable.modemChanged(); + cable.connectionsChanged(); if( !world.isRemote && !player.capabilities.isCreativeMode ) dropItem( world, pos, item ); return false; @@ -382,7 +383,7 @@ public class BlockCable extends BlockPeripheralBase TileCable cable = (TileCable) tile; if( cable.getPeripheralType() != PeripheralType.WiredModem ) { - cable.networkChanged(); + cable.connectionsChanged(); } } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java index 792fe47b9..f056532b7 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/common/ItemCable.java @@ -98,8 +98,8 @@ public class ItemCable extends ItemPeripheralBase TileEntity tile = world.getTileEntity( pos ); if( tile != null && tile instanceof TileCable ) { - TileCable cable = (TileCable)tile; - cable.networkChanged(); + TileCable cable = (TileCable) tile; + cable.connectionsChanged(); } return EnumActionResult.SUCCESS; } @@ -131,7 +131,8 @@ public class ItemCable extends ItemPeripheralBase if( tile != null && tile instanceof TileCable ) { TileCable cable = (TileCable)tile; - cable.networkChanged(); + cable.modemChanged(); + cable.connectionsChanged(); } return EnumActionResult.SUCCESS; } @@ -153,7 +154,8 @@ public class ItemCable extends ItemPeripheralBase if( tile != null && tile instanceof TileCable ) { TileCable cable = (TileCable)tile; - cable.networkChanged(); + cable.modemChanged(); + cable.connectionsChanged(); } return EnumActionResult.SUCCESS; } diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java index 64f0dcd37..f3e9f658c 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileCable.java @@ -291,7 +291,8 @@ public class TileCable extends TileModemBase ((BlockGeneric) getBlockType()).dropItem( getWorld(), getPos(), PeripheralItemFactory.create( PeripheralType.WiredModem, getLabel(), 1 ) ); setLabel( null ); setBlockState( getBlockState().withProperty( BlockCable.Properties.MODEM, BlockCableModemVariant.None ) ); - networkChanged(); + modemChanged(); + connectionsChanged(); break; } @@ -474,19 +475,17 @@ public class TileCable extends TileModemBase { if( !m_connectionsFormed ) { - networkChanged(); + connectionsChanged(); if( m_peripheralAccessAllowed ) m_node.invalidate(); m_connectionsFormed = true; } } } - public void networkChanged() + public void connectionsChanged() { if( getWorld().isRemote ) return; - if( modemChanged() ) m_node.invalidate(); - IBlockState state = getBlockState(); World world = getWorld(); BlockPos current = getPos(); @@ -511,11 +510,9 @@ public class TileCable extends TileModemBase } } - private boolean modemChanged() + public void modemChanged() { - if( getWorld().isRemote ) return false; - - boolean requiresUpdate = false; + if( getWorld().isRemote ) return; PeripheralType type = getPeripheralType(); if( type == PeripheralType.Cable ) @@ -526,12 +523,10 @@ public class TileCable extends TileModemBase if( type != PeripheralType.WiredModemWithCable && m_peripheralAccessAllowed ) { m_peripheralAccessAllowed = false; - requiresUpdate = true; + m_node.invalidate(); markDirty(); updateAnim(); } - - return requiresUpdate; } // private stuff diff --git a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWiredModemFull.java b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWiredModemFull.java index 3acb04fbd..a10aa947d 100644 --- a/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWiredModemFull.java +++ b/src/main/java/dan200/computercraft/shared/peripheral/modem/TileWiredModemFull.java @@ -293,7 +293,8 @@ public class TileWiredModemFull extends TilePeripheralBase if( !m_connectionsFormed ) { - networkChanged(); + connectionsChanged(); + if( m_peripheralAccessAllowed ) node.invalidate(); m_connectionsFormed = true; } } @@ -301,7 +302,7 @@ public class TileWiredModemFull extends TilePeripheralBase super.update(); } - private void networkChanged() + private void connectionsChanged() { if( getWorld().isRemote ) return; @@ -318,8 +319,6 @@ public class TileWiredModemFull extends TilePeripheralBase // If we can connect to it then do so node.connectTo( element.getNode() ); } - - node.invalidate(); } // private stuff