From e425a8e370a9f4f1e7e32e51dbb273c0e7bc44aa Mon Sep 17 00:00:00 2001 From: CrazyPants Date: Thu, 30 Oct 2014 11:12:13 +0800 Subject: [PATCH] Transceiver item buffers would allow multiple non-stackable items of the same type --- ReleaseNotes.txt | 1 + .../transceiver/ServerChannelRegister.java | 14 ++++++------- .../machine/transceiver/TileTransceiver.java | 4 ++-- src/main/java/crazypants/util/ItemUtil.java | 20 +++++++++++++++++-- 4 files changed, 28 insertions(+), 11 deletions(-) diff --git a/ReleaseNotes.txt b/ReleaseNotes.txt index b6a566bf..9ee422d5 100644 --- a/ReleaseNotes.txt +++ b/ReleaseNotes.txt @@ -12,6 +12,7 @@ Changes Bugs - #1162 Infinite Broken-Spawner exploit with Twilight Forest - #1170 Dimensional Transceiver liquid related crash +- Transceiver item buffers would allow multiple non-stackable items of the same type ------------------------------------------------------ diff --git a/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java b/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java index dea75102..077ed80e 100644 --- a/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java +++ b/src/main/java/crazypants/enderio/machine/transceiver/ServerChannelRegister.java @@ -216,13 +216,13 @@ public class ServerChannelRegister extends ChannelRegister { private ItemStack sendItem(TileTransceiver from, int slot, ItemStack contents, TileTransceiver to) { SlotDefinition sd = to.getSlotDefinition(); - //try merging into existing stacks - - boolean recieverHasItem = false; // Only allow 1 stack per item type - for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot && !recieverHasItem; i++) { + //try merging into existing stacks + + boolean sendComplete = false; // Only allow 1 stack per item type + for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot && !sendComplete; i++) { ItemStack existing = to.getStackInSlot(i); - if(ItemUtil.areStackTypesEqual(existing, contents)) { - recieverHasItem = true; + if(ItemUtil.areStacksEqual(existing, contents)) { + sendComplete = true; int numCanMerge = existing.getMaxStackSize() - existing.stackSize; numCanMerge = Math.min(numCanMerge, contents.stackSize); ItemStack remaining; @@ -243,7 +243,7 @@ public class ServerChannelRegister extends ChannelRegister { } } } - if(!recieverHasItem) { + if(!sendComplete) { //then fill empty stack for (int i = sd.minOutputSlot; i <= sd.maxOutputSlot; i++) { ItemStack existing = to.getStackInSlot(i); diff --git a/src/main/java/crazypants/enderio/machine/transceiver/TileTransceiver.java b/src/main/java/crazypants/enderio/machine/transceiver/TileTransceiver.java index 5a26cf0f..9ea22e99 100644 --- a/src/main/java/crazypants/enderio/machine/transceiver/TileTransceiver.java +++ b/src/main/java/crazypants/enderio/machine/transceiver/TileTransceiver.java @@ -479,7 +479,7 @@ public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluid if(slotDefinition.isInputSlot(slot)) { for (int i = slotDefinition.getMinInputSlot(); i <= slotDefinition.getMaxInputSlot(); i++) { if(i != slot) { - if(ItemUtil.areStackTypesEqual(itemstack, getStackInSlot(i))) { + if(ItemUtil.areStacksEqual(itemstack, getStackInSlot(i))) { return false; } } @@ -487,7 +487,7 @@ public class TileTransceiver extends AbstractPoweredTaskEntity implements IFluid } else if(slotDefinition.isOutputSlot(slot)) { for (int i = slotDefinition.getMinOutputSlot(); i <= slotDefinition.getMaxOutputSlot(); i++) { if(i != slot) { - if(ItemUtil.areStackTypesEqual(itemstack, getStackInSlot(i))) { + if(ItemUtil.areStacksEqual(itemstack, getStackInSlot(i))) { return false; } } diff --git a/src/main/java/crazypants/util/ItemUtil.java b/src/main/java/crazypants/util/ItemUtil.java index 7297c5fb..890c4084 100644 --- a/src/main/java/crazypants/util/ItemUtil.java +++ b/src/main/java/crazypants/util/ItemUtil.java @@ -164,14 +164,30 @@ public class ItemUtil { return inv; } + /** + * Checks if items, damage and NBT are equal and the items are stackable. + * @param s1 + * @param s2 + * @return + */ + public static boolean areStackMergable(ItemStack s1, ItemStack s2) { + if(s1 == null || s2 == null || !s1.isStackable() || !s2.isStackable()) { + return false; + } + if(!s1.isItemEqual(s2)) { + return false; + } + return ItemStack.areItemStackTagsEqual(s1, s2); + } + /** * Checks if items, damage and NBT are equal. * @param s1 * @param s2 * @return */ - public static boolean areStackTypesEqual(ItemStack s1, ItemStack s2) { - if(s1 == null || s2 == null || !s1.isStackable() || !s2.isStackable()) { + public static boolean areStacksEqual(ItemStack s1, ItemStack s2) { + if(s1 == null || s2 == null) { return false; } if(!s1.isItemEqual(s2)) {