From 2b6cca026793478b6adffa8137b25df07edb5b2b Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Wed, 23 Jul 2014 23:20:16 -0500 Subject: [PATCH] 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. --- me/storage/MEInventoryHandler.java | 4 ++-- me/storage/MEMonitorIInventory.java | 9 +++++++-- me/storage/MEMonitorPassthu.java | 12 ++++++------ me/storage/MEPassthru.java | 4 +++- parts/misc/PartStorageBus.java | 7 ++++--- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/me/storage/MEInventoryHandler.java b/me/storage/MEInventoryHandler.java index 0e56e166e..0b05c57fc 100644 --- a/me/storage/MEInventoryHandler.java +++ b/me/storage/MEInventoryHandler.java @@ -25,13 +25,13 @@ public class MEInventoryHandler> implements IMEInventoryHa public AccessRestriction myAccess = AccessRestriction.READ_WRITE; public IPartitionList myPartitionList = new DefaultPriorityList(); - public MEInventoryHandler(IMEInventory i, StorageChannel channel ) { + public MEInventoryHandler(IMEInventory i, StorageChannel channel) { this.channel = channel; if ( i instanceof IMEInventoryHandler ) internal = (IMEInventoryHandler) i; else - internal = new MEPassthru( i ); + internal = new MEPassthru( i, channel ); monitor = internal instanceof IMEMonitor ? (IMEMonitor) internal : null; } diff --git a/me/storage/MEMonitorIInventory.java b/me/storage/MEMonitorIInventory.java index f4e4dcbb7..e4874111f 100644 --- a/me/storage/MEMonitorIInventory.java +++ b/me/storage/MEMonitorIInventory.java @@ -79,6 +79,8 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit else out = adaptor.addItems( input.getItemStack() ); + onTick(); + if ( out == null ) return null; @@ -127,8 +129,8 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit @Override public IItemList getAvailableItems(IItemList out) { - for (ItemSlot is : adaptor) - out.addStorage( is.getAEItemStack() ); + for (CachedItemStack is : memory.values()) + out.addStorage( is.aeStack ); return out; } @@ -149,6 +151,9 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit // better then doing construction from scratch :3 IAEItemStack o = request.copy(); o.setStackSize( out.stackSize ); + + onTick(); + return o; } diff --git a/me/storage/MEMonitorPassthu.java b/me/storage/MEMonitorPassthu.java index 7af29a52f..6e8cf6d81 100644 --- a/me/storage/MEMonitorPassthu.java +++ b/me/storage/MEMonitorPassthu.java @@ -20,13 +20,11 @@ public class MEMonitorPassthu> extends MEPassthru imple HashMap, Object> listeners = new HashMap(); IMEMonitor monitor; - StorageChannel channel; public BaseActionSource changeSource; - public MEMonitorPassthu(IMEInventory i, StorageChannel channel ) { - super( i ); - this.channel = channel; + public MEMonitorPassthu(IMEInventory i, StorageChannel channel) { + super( i, channel ); if ( i instanceof IMEMonitor ) monitor = (IMEMonitor) i; } @@ -38,13 +36,15 @@ public class MEMonitorPassthu> extends MEPassthru imple monitor.removeListener( this ); monitor = null; - IItemList before = getInternal() == null ? channel.createList() : getInternal().getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); + IItemList before = getInternal() == null ? channel.createList() : getInternal() + .getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); super.setInternal( i ); if ( i instanceof IMEMonitor ) monitor = (IMEMonitor) i; - IItemList after = getInternal() == null ? channel.createList() : getInternal().getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); + IItemList after = getInternal() == null ? channel.createList() : getInternal() + .getAvailableItems( new ItemListIgnoreCrafting( channel.createList() ) ); if ( monitor != null ) monitor.addListener( this, monitor ); diff --git a/me/storage/MEPassthru.java b/me/storage/MEPassthru.java index 0b1503978..7e0756ad6 100644 --- a/me/storage/MEPassthru.java +++ b/me/storage/MEPassthru.java @@ -13,13 +13,15 @@ public class MEPassthru> implements IMEInventoryHandler { private IMEInventory internal; + final protected StorageChannel channel; protected IMEInventory getInternal() { return internal; } - public MEPassthru( IMEInventory i ) { + public MEPassthru(IMEInventory i, StorageChannel channel) { + this.channel = channel; setInternal( i ); } diff --git a/parts/misc/PartStorageBus.java b/parts/misc/PartStorageBus.java index 9f218c9b8..bea1317e2 100644 --- a/parts/misc/PartStorageBus.java +++ b/parts/misc/PartStorageBus.java @@ -152,9 +152,6 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC private void resetCache(boolean fullReset) { - if ( monitor != null ) - monitor.onTick(); - if ( host == null || host.getTile() == null || host.getTile().getWorldObj() == null ) return; @@ -168,6 +165,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC handlerHash = 0; IMEInventory out = getInternalHandler(); + + if ( monitor != null ) + monitor.onTick(); + IItemList after = AEApi.instance().storage().createItemList(); if ( out != null ) after = out.getAvailableItems( after );