Fixed some storage bus related crashes.

Fixed an issue where the storage might access inventories that have been removed from the world.
Fixed an issue caused by refactoring.
This commit is contained in:
AlgorithmX2 2014-07-23 23:20:16 -05:00
parent 42b6647ec3
commit 2b6cca0267
5 changed files with 22 additions and 14 deletions

View file

@ -25,13 +25,13 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
public AccessRestriction myAccess = AccessRestriction.READ_WRITE; public AccessRestriction myAccess = AccessRestriction.READ_WRITE;
public IPartitionList<T> myPartitionList = new DefaultPriorityList<T>(); public IPartitionList<T> myPartitionList = new DefaultPriorityList<T>();
public MEInventoryHandler(IMEInventory<T> i, StorageChannel channel ) { public MEInventoryHandler(IMEInventory<T> i, StorageChannel channel) {
this.channel = channel; this.channel = channel;
if ( i instanceof IMEInventoryHandler ) if ( i instanceof IMEInventoryHandler )
internal = (IMEInventoryHandler<T>) i; internal = (IMEInventoryHandler<T>) i;
else else
internal = new MEPassthru<T>( i ); internal = new MEPassthru<T>( i, channel );
monitor = internal instanceof IMEMonitor ? (IMEMonitor<T>) internal : null; monitor = internal instanceof IMEMonitor ? (IMEMonitor<T>) internal : null;
} }

View file

@ -79,6 +79,8 @@ public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonit
else else
out = adaptor.addItems( input.getItemStack() ); out = adaptor.addItems( input.getItemStack() );
onTick();
if ( out == null ) if ( out == null )
return null; return null;
@ -127,8 +129,8 @@ public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonit
@Override @Override
public IItemList<IAEItemStack> getAvailableItems(IItemList out) public IItemList<IAEItemStack> getAvailableItems(IItemList out)
{ {
for (ItemSlot is : adaptor) for (CachedItemStack is : memory.values())
out.addStorage( is.getAEItemStack() ); out.addStorage( is.aeStack );
return out; return out;
} }
@ -149,6 +151,9 @@ public class MEMonitorIInventory implements IMEInventory<IAEItemStack>, IMEMonit
// better then doing construction from scratch :3 // better then doing construction from scratch :3
IAEItemStack o = request.copy(); IAEItemStack o = request.copy();
o.setStackSize( out.stackSize ); o.setStackSize( out.stackSize );
onTick();
return o; return o;
} }

View file

@ -20,13 +20,11 @@ public class MEMonitorPassthu<T extends IAEStack<T>> extends MEPassthru<T> imple
HashMap<IMEMonitorHandlerReceiver<T>, Object> listeners = new HashMap(); HashMap<IMEMonitorHandlerReceiver<T>, Object> listeners = new HashMap();
IMEMonitor<T> monitor; IMEMonitor<T> monitor;
StorageChannel channel;
public BaseActionSource changeSource; public BaseActionSource changeSource;
public MEMonitorPassthu(IMEInventory<T> i, StorageChannel channel ) { public MEMonitorPassthu(IMEInventory<T> i, StorageChannel channel) {
super( i ); super( i, channel );
this.channel = channel;
if ( i instanceof IMEMonitor ) if ( i instanceof IMEMonitor )
monitor = (IMEMonitor<T>) i; monitor = (IMEMonitor<T>) i;
} }
@ -38,13 +36,15 @@ public class MEMonitorPassthu<T extends IAEStack<T>> extends MEPassthru<T> imple
monitor.removeListener( this ); monitor.removeListener( this );
monitor = null; monitor = null;
IItemList<T> before = getInternal() == null ? channel.createList() : getInternal().getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); IItemList<T> before = getInternal() == null ? channel.createList() : getInternal()
.getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) );
super.setInternal( i ); super.setInternal( i );
if ( i instanceof IMEMonitor ) if ( i instanceof IMEMonitor )
monitor = (IMEMonitor<T>) i; monitor = (IMEMonitor<T>) i;
IItemList<T> after = getInternal() == null ? channel.createList() : getInternal().getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); IItemList<T> after = getInternal() == null ? channel.createList() : getInternal()
.getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) );
if ( monitor != null ) if ( monitor != null )
monitor.addListener( this, monitor ); monitor.addListener( this, monitor );

View file

@ -13,13 +13,15 @@ public class MEPassthru<T extends IAEStack<T>> implements IMEInventoryHandler<T>
{ {
private IMEInventory<T> internal; private IMEInventory<T> internal;
final protected StorageChannel channel;
protected IMEInventory<T> getInternal() protected IMEInventory<T> getInternal()
{ {
return internal; return internal;
} }
public MEPassthru( IMEInventory<T> i ) { public MEPassthru(IMEInventory<T> i, StorageChannel channel) {
this.channel = channel;
setInternal( i ); setInternal( i );
} }

View file

@ -152,9 +152,6 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
private void resetCache(boolean fullReset) private void resetCache(boolean fullReset)
{ {
if ( monitor != null )
monitor.onTick();
if ( host == null || host.getTile() == null || host.getTile().getWorldObj() == null ) if ( host == null || host.getTile() == null || host.getTile().getWorldObj() == null )
return; return;
@ -168,6 +165,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC
handlerHash = 0; handlerHash = 0;
IMEInventory<IAEItemStack> out = getInternalHandler(); IMEInventory<IAEItemStack> out = getInternalHandler();
if ( monitor != null )
monitor.onTick();
IItemList<IAEItemStack> after = AEApi.instance().storage().createItemList(); IItemList<IAEItemStack> after = AEApi.instance().storage().createItemList();
if ( out != null ) if ( out != null )
after = out.getAvailableItems( after ); after = out.getAvailableItems( after );