diff --git a/src/main/java/appeng/me/cache/GridStorageCache.java b/src/main/java/appeng/me/cache/GridStorageCache.java index 923158862..b67eb4004 100644 --- a/src/main/java/appeng/me/cache/GridStorageCache.java +++ b/src/main/java/appeng/me/cache/GridStorageCache.java @@ -70,7 +70,6 @@ public class GridStorageCache implements IStorageGrid private final Map, NetworkInventoryHandler> storageNetworks; private final Map, NetworkMonitor> storageMonitors; private MECraftingInventory localCache = null; - private final Int2ObjectMap extractableItemPriorityMap = new Int2ObjectOpenHashMap<>(); private int localDepth; public GridStorageCache( final IGrid g ) @@ -86,7 +85,6 @@ public class GridStorageCache implements IStorageGrid public void onUpdateTick() { this.localCache = null; - this.extractableItemPriorityMap.clear(); this.storageMonitors.forEach( ( channel, monitor ) -> monitor.onTick() ); } @@ -176,19 +174,6 @@ public class GridStorageCache implements IStorageGrid public MECraftingInventory getExtractableList( IActionSource src ) { - if( src instanceof MachineSource ) - { - if( src.machine().isPresent() ) - { - IActionHost machine = src.machine().get(); - if( machine instanceof IInterfaceHost ) - { - extractableItemPriorityMap.putIfAbsent( ( (IPriorityHost) machine ).getPriority(), new MECraftingInventory( getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), src, false, false, false ) ); - return extractableItemPriorityMap.get( ( (IPriorityHost) machine ).getPriority() ); - } - } - } - if( localCache == null ) { localCache = new MECraftingInventory( getInventory( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) ), src, false, false, false ); @@ -205,12 +190,13 @@ public class GridStorageCache implements IStorageGrid final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource(); - this.storageMonitors.forEach( ( channel, monitor ) -> { - for( final IMEInventoryHandler h : cc.getCellArray( channel ) ) - { - tracker.postChanges( channel, 1, h, actionSrc ); - } - } ); + this.storageMonitors.forEach( ( channel, monitor ) -> + { + for( final IMEInventoryHandler h : cc.getCellArray( channel ) ) + { + tracker.postChanges( channel, 1, h, actionSrc ); + } + } ); } return tracker; @@ -225,12 +211,13 @@ public class GridStorageCache implements IStorageGrid final IActionSource actionSrc = cc instanceof IActionHost ? new MachineSource( (IActionHost) cc ) : new BaseActionSource(); - this.storageMonitors.forEach( ( channel, monitor ) -> { - for( final IMEInventoryHandler h : cc.getCellArray( channel ) ) - { - tracker.postChanges( channel, -1, h, actionSrc ); - } - } ); + this.storageMonitors.forEach( ( channel, monitor ) -> + { + for( final IMEInventoryHandler h : cc.getCellArray( channel ) ) + { + tracker.postChanges( channel, -1, h, actionSrc ); + } + } ); } return tracker; diff --git a/src/main/java/appeng/util/inv/AdaptorItemHandler.java b/src/main/java/appeng/util/inv/AdaptorItemHandler.java index 5828dc0be..c9cdc9eaf 100644 --- a/src/main/java/appeng/util/inv/AdaptorItemHandler.java +++ b/src/main/java/appeng/util/inv/AdaptorItemHandler.java @@ -19,14 +19,13 @@ package appeng.util.inv; -import java.util.Iterator; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.items.IItemHandler; - import appeng.api.config.FuzzyMode; import appeng.util.InventoryAdaptor; import appeng.util.Platform; +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; + +import java.util.Iterator; public class AdaptorItemHandler extends InventoryAdaptor @@ -60,13 +59,13 @@ public class AdaptorItemHandler extends InventoryAdaptor if( destination != null ) { - ItemStack extracted = this.itemHandler.extractItem( slot, amount, true ); - if( extracted.isEmpty() ) + if( !destination.canInsert( is ) ) { - continue; + break; } - if( !destination.canInsert( extracted ) ) + ItemStack extracted = this.itemHandler.extractItem( slot, amount, true ); + if( extracted.isEmpty() ) { continue; } @@ -109,21 +108,20 @@ public class AdaptorItemHandler extends InventoryAdaptor final ItemStack is = this.itemHandler.getStackInSlot( slot ); if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) ) { - ItemStack extracted = this.itemHandler.extractItem( slot, amount, true ); + if( destination != null ) + { + if( !destination.canInsert( is ) ) + { + break; + } + } + ItemStack extracted = this.itemHandler.extractItem( slot, amount, true ); if( extracted.isEmpty() ) { continue; } - if( destination != null ) - { - if( !destination.canInsert( extracted ) ) - { - continue; - } - } - if( rv.isEmpty() ) { // Use the first stack as a template for the result @@ -163,13 +161,13 @@ public class AdaptorItemHandler extends InventoryAdaptor if( destination != null ) { - ItemStack simulated = this.itemHandler.extractItem( slot, amount, true ); - if( simulated.isEmpty() ) + if( !destination.canInsert( is ) ) { continue; } - if( !destination.canInsert( simulated ) ) + ItemStack simulated = this.itemHandler.extractItem( slot, amount, true ); + if( simulated.isEmpty() ) { continue; } @@ -177,6 +175,10 @@ public class AdaptorItemHandler extends InventoryAdaptor // Attempt extracting it extracted = this.itemHandler.extractItem( slot, amount, false ); + if( !extracted.isEmpty() ) + { + return extracted; + } } return extracted; @@ -196,15 +198,16 @@ public class AdaptorItemHandler extends InventoryAdaptor continue; } + if( destination != null && !destination.canInsert( is ) ) + { + continue; + } + // Attempt extracting it extracted = this.itemHandler.extractItem( slot, amount, true ); - - if( !extracted.isEmpty() && destination != null ) + if( !extracted.isEmpty() ) { - if( !destination.canInsert( extracted ) ) - { - extracted = ItemStack.EMPTY; // Keep on looking... - } + return extracted; } }