Storage Cache now announces changes for cell containers as they are added and removed.

This commit is contained in:
AlgorithmX2 2014-02-13 20:27:04 -06:00
parent bceff8e902
commit 3d09f6918f
2 changed files with 68 additions and 32 deletions

View file

@ -2,6 +2,7 @@ package appeng.me.cache;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import appeng.api.networking.IGrid; import appeng.api.networking.IGrid;
import appeng.api.networking.IGridHost; import appeng.api.networking.IGridHost;
@ -35,7 +36,8 @@ public class GridStorageCache implements IStorageGrid
public SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create(); public SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
final HashSet<ICellContainer> cellContainers = new HashSet(); final HashSet<ICellContainer> activeCellContainers = new HashSet();
final HashSet<ICellContainer> inactiveCellContainers = new HashSet();
final public IGrid myGrid; final public IGrid myGrid;
private NetworkInventoryHandler<IAEItemStack> myItemNetwork; private NetworkInventoryHandler<IAEItemStack> myItemNetwork;
@ -57,15 +59,31 @@ public class GridStorageCache implements IStorageGrid
fluidMonitor.onTick(); fluidMonitor.onTick();
} }
@Override private void addCell(IGridNode node, ICellContainer cc)
public void removeNode(IGridNode node, IGridHost machine)
{ {
if ( machine instanceof ICellContainer ) if ( node.isActive() && inactiveCellContainers.contains( cc ) )
{ {
ICellContainer cc = (ICellContainer) machine; inactiveCellContainers.remove( cc );
cellContainers.remove( cc ); activeCellContainers.add( cc );
myGrid.postEvent( new MENetworkCellArrayUpdate() ); for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
{
postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( new ItemList<IAEItemStack>() ), new MachineSource( cc ) );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
{
postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( new ItemList<IAEFluidStack>() ), new MachineSource( cc ) );
}
}
}
private void rmvCell(IGridNode node, ICellContainer cc)
{
if ( node.isActive() && activeCellContainers.contains( cc ) )
{
inactiveCellContainers.add( cc );
activeCellContainers.remove( cc );
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS )) for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
{ {
@ -77,6 +95,43 @@ public class GridStorageCache implements IStorageGrid
postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( new ItemList<IAEFluidStack>() ), new MachineSource( cc ) ); postChanges( StorageChannel.FLUIDS, -1, h.getAvailableItems( new ItemList<IAEFluidStack>() ), new MachineSource( cc ) );
} }
} }
}
@MENetworkEventSubscribe
public void cellUpdate(MENetworkCellArrayUpdate ev)
{
myItemNetwork = null;
myFluidNetwork = null;
LinkedList<ICellContainer> 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 ) if ( machine instanceof IStackWatcherHost )
{ {
@ -95,19 +150,10 @@ public class GridStorageCache implements IStorageGrid
if ( machine instanceof ICellContainer ) if ( machine instanceof ICellContainer )
{ {
ICellContainer cc = (ICellContainer) machine; ICellContainer cc = (ICellContainer) machine;
cellContainers.add( cc ); inactiveCellContainers.add( cc );
myGrid.postEvent( new MENetworkCellArrayUpdate() ); myGrid.postEvent( new MENetworkCellArrayUpdate() );
addCell( node, cc );
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( StorageChannel.ITEMS ))
{
postChanges( StorageChannel.ITEMS, 1, h.getAvailableItems( new ItemList<IAEItemStack>() ), new MachineSource( cc ) );
}
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( StorageChannel.FLUIDS ))
{
postChanges( StorageChannel.FLUIDS, 1, h.getAvailableItems( new ItemList<IAEFluidStack>() ), new MachineSource( cc ) );
}
} }
if ( machine instanceof IStackWatcherHost ) if ( machine instanceof IStackWatcherHost )
@ -127,7 +173,7 @@ public class GridStorageCache implements IStorageGrid
{ {
case FLUIDS: case FLUIDS:
myFluidNetwork = new NetworkInventoryHandler<IAEFluidStack>( StorageChannel.FLUIDS, security ); myFluidNetwork = new NetworkInventoryHandler<IAEFluidStack>( StorageChannel.FLUIDS, security );
for (ICellContainer cc : cellContainers) for (ICellContainer cc : activeCellContainers)
{ {
for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( chan )) for (IMEInventoryHandler<IAEFluidStack> h : cc.getCellArray( chan ))
myFluidNetwork.addNewStorage( h ); myFluidNetwork.addNewStorage( h );
@ -135,7 +181,7 @@ public class GridStorageCache implements IStorageGrid
break; break;
case ITEMS: case ITEMS:
myItemNetwork = new NetworkInventoryHandler<IAEItemStack>( StorageChannel.ITEMS, security ); myItemNetwork = new NetworkInventoryHandler<IAEItemStack>( StorageChannel.ITEMS, security );
for (ICellContainer cc : cellContainers) for (ICellContainer cc : activeCellContainers)
{ {
for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( chan )) for (IMEInventoryHandler<IAEItemStack> h : cc.getCellArray( chan ))
myItemNetwork.addNewStorage( h ); 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<IAEItemStack> getItemInventoryHandler() public IMEInventoryHandler<IAEItemStack> getItemInventoryHandler()
{ {
if ( myItemNetwork == null ) if ( myItemNetwork == null )

View file

@ -643,8 +643,6 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
public void readFromNBT(NBTTagCompound data) public void readFromNBT(NBTTagCompound data)
{ {
fc.readFromNBT( data );
for (int x = 0; x < 7; x++) for (int x = 0; x < 7; x++)
{ {
ForgeDirection side = ForgeDirection.getOrientation( x ); ForgeDirection side = ForgeDirection.getOrientation( x );
@ -678,6 +676,8 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
else else
removePart( side, false ); removePart( side, false );
} }
fc.readFromNBT( data );
} }
public List getDrops(List drops) public List getDrops(List drops)