From 10eab71f3285bdf11409ff8b7d8878255bc9eb58 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Mon, 15 Sep 2014 14:28:23 -0500 Subject: [PATCH] Fix a bug where IInventories that change size may appear to contain items that were present in removed portion of the inventory. --- me/storage/MEMonitorIInventory.java | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/me/storage/MEMonitorIInventory.java b/me/storage/MEMonitorIInventory.java index 93144f154..92c68fbb2 100644 --- a/me/storage/MEMonitorIInventory.java +++ b/me/storage/MEMonitorIInventory.java @@ -3,6 +3,7 @@ package appeng.me.storage; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; +import java.util.NavigableMap; import java.util.Map.Entry; import java.util.TreeMap; @@ -164,12 +165,15 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit { boolean changed = false; - LinkedList changes = new LinkedList(); - + LinkedList changes = new LinkedList(); + + int high = 0; list.resetStatus(); for (ItemSlot is : adaptor) { - CachedItemStack old = memory.get( is.slot ); + CachedItemStack old = memory.get( is.slot ); + high = Math.max( high, is.slot ); + ItemStack newIS = is == null || is.isExtractable == false && mode == StorageFilter.EXTACTABLE_ONLY ? null : is.getItemStack(); ItemStack oldIS = old == null ? null : old.itemStack; @@ -215,8 +219,22 @@ public class MEMonitorIInventory implements IMEInventory, IMEMonit changed = true; } } - } - + } + + // detect dropped items; should fix non IISided Inventory Changes. + NavigableMap end = memory.tailMap( high, false ); + if ( ! end.isEmpty() ) + { + for ( CachedItemStack cis : end.values() ) + { + IAEItemStack a = cis.aeStack.copy(); + a.setStackSize( - a.getStackSize() ); + changes.add( a ); + changed = true; + } + end.clear(); + } + if ( !changes.isEmpty() ) postDiffrence( changes );