diff --git a/me/cache/GridStorageCache.java b/me/cache/GridStorageCache.java index 2269a7a5a..0d53f5083 100644 --- a/me/cache/GridStorageCache.java +++ b/me/cache/GridStorageCache.java @@ -2,6 +2,7 @@ package appeng.me.cache; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedList; import appeng.api.networking.IGrid; import appeng.api.networking.IGridHost; @@ -35,7 +36,8 @@ public class GridStorageCache implements IStorageGrid public SetMultimap interests = HashMultimap.create(); - final HashSet cellContainers = new HashSet(); + final HashSet activeCellContainers = new HashSet(); + final HashSet inactiveCellContainers = new HashSet(); final public IGrid myGrid; private NetworkInventoryHandler myItemNetwork; @@ -57,15 +59,31 @@ public class GridStorageCache implements IStorageGrid fluidMonitor.onTick(); } - @Override - public void removeNode(IGridNode node, IGridHost machine) + private void addCell(IGridNode node, ICellContainer cc) { - if ( machine instanceof ICellContainer ) + if ( node.isActive() && inactiveCellContainers.contains( cc ) ) { - ICellContainer cc = (ICellContainer) machine; - cellContainers.remove( cc ); + inactiveCellContainers.remove( cc ); + activeCellContainers.add( cc ); - myGrid.postEvent( new MENetworkCellArrayUpdate() ); + for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) + { + postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); + } + + for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) + { + postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); + } + } + } + + private void rmvCell(IGridNode node, ICellContainer cc) + { + if ( node.isActive() && activeCellContainers.contains( cc ) ) + { + inactiveCellContainers.add( cc ); + activeCellContainers.remove( cc ); for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) { @@ -77,6 +95,43 @@ public class GridStorageCache implements IStorageGrid postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); } } + } + + @MENetworkEventSubscribe + public void cellUpdate(MENetworkCellArrayUpdate ev) + { + myItemNetwork = null; + myFluidNetwork = null; + + LinkedList ll = new LinkedList(); + ll.addAll( inactiveCellContainers ); + ll.addAll( activeCellContainers ); + + for (ICellContainer cc : ll) + { + IGridNode node = cc.getActionableNode(); + + if ( node.isActive() ) + addCell( node, cc ); + else + rmvCell( node, cc ); + } + + itemMonitor.forceUpdate(); + fluidMonitor.forceUpdate(); + } + + @Override + public void removeNode(IGridNode node, IGridHost machine) + { + if ( machine instanceof ICellContainer ) + { + ICellContainer cc = (ICellContainer) machine; + + myGrid.postEvent( new MENetworkCellArrayUpdate() ); + rmvCell( node, cc ); + inactiveCellContainers.remove( cc ); + } if ( machine instanceof IStackWatcherHost ) { @@ -95,19 +150,10 @@ public class GridStorageCache implements IStorageGrid if ( machine instanceof ICellContainer ) { ICellContainer cc = (ICellContainer) machine; - cellContainers.add( cc ); + inactiveCellContainers.add( cc ); myGrid.postEvent( new MENetworkCellArrayUpdate() ); - - for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.ITEMS )) - { - postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); - } - - for (IMEInventoryHandler h : cc.getCellArray( StorageChannel.FLUIDS )) - { - postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( new ItemList() ), new MachineSource( cc ) ); - } + addCell( node, cc ); } if ( machine instanceof IStackWatcherHost ) @@ -127,7 +173,7 @@ public class GridStorageCache implements IStorageGrid { case FLUIDS: myFluidNetwork = new NetworkInventoryHandler( StorageChannel.FLUIDS, security ); - for (ICellContainer cc : cellContainers) + for (ICellContainer cc : activeCellContainers) { for (IMEInventoryHandler h : cc.getCellArray( chan )) myFluidNetwork.addNewStorage( h ); @@ -135,7 +181,7 @@ public class GridStorageCache implements IStorageGrid break; case ITEMS: myItemNetwork = new NetworkInventoryHandler( StorageChannel.ITEMS, security ); - for (ICellContainer cc : cellContainers) + for (ICellContainer cc : activeCellContainers) { for (IMEInventoryHandler h : cc.getCellArray( chan )) myItemNetwork.addNewStorage( h ); @@ -177,16 +223,6 @@ public class GridStorageCache implements IStorageGrid } } - @MENetworkEventSubscribe - public void cellUpdate(MENetworkCellArrayUpdate ev) - { - myItemNetwork = null; - myFluidNetwork = null; - - itemMonitor.forceUpdate(); - fluidMonitor.forceUpdate(); - } - public IMEInventoryHandler getItemInventoryHandler() { if ( myItemNetwork == null ) diff --git a/parts/CableBusContainer.java b/parts/CableBusContainer.java index e18799b8e..93caa5365 100644 --- a/parts/CableBusContainer.java +++ b/parts/CableBusContainer.java @@ -643,8 +643,6 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer public void readFromNBT(NBTTagCompound data) { - fc.readFromNBT( data ); - for (int x = 0; x < 7; x++) { ForgeDirection side = ForgeDirection.getOrientation( x ); @@ -678,6 +676,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer else removePart( side, false ); } + + fc.readFromNBT( data ); } public List getDrops(List drops)