From d2258ff497db6514b9320dfb9e198dd63e9bef83 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Thu, 15 Oct 2015 17:41:59 +0200 Subject: [PATCH] fix #3079 --- buildcraft_resources/changelog/7.1.11 | 1 + .../transport/pipes/PipeItemsEmzuli.java | 52 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/buildcraft_resources/changelog/7.1.11 b/buildcraft_resources/changelog/7.1.11 index 321bb0ef..8e90b3e4 100644 --- a/buildcraft_resources/changelog/7.1.11 +++ b/buildcraft_resources/changelog/7.1.11 @@ -1,4 +1,5 @@ Bugs fixed: +* [#3079] Emzuli pipe's round-robin extraction behaving incorrectly (asie) * [#3075] Rare crash in AIRobotGoAndLinkToDock (asie) * Robot unstucking issues (asie) diff --git a/common/buildcraft/transport/pipes/PipeItemsEmzuli.java b/common/buildcraft/transport/pipes/PipeItemsEmzuli.java index e059bfb4..a5a41faa 100644 --- a/common/buildcraft/transport/pipes/PipeItemsEmzuli.java +++ b/common/buildcraft/transport/pipes/PipeItemsEmzuli.java @@ -17,6 +17,7 @@ import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -88,13 +89,10 @@ public class PipeItemsEmzuli extends PipeItemsWood implements IGuiReturnHandler */ @Override public ItemStack[] checkExtract(IInventory inventory, boolean doRemove, ForgeDirection from) { - if (activeFlags.isEmpty()) { return null; } - incrementFilter(); - if (filters.getStackInSlot(currentFilter % filterCount) == null || !activeFlags.get(currentFilter % filterCount)) { return null; } @@ -110,26 +108,36 @@ public class PipeItemsEmzuli extends PipeItemsWood implements IGuiReturnHandler } @Override - public ItemStack checkExtractGeneric(net.minecraft.inventory.ISidedInventory inventory, boolean doRemove, ForgeDirection from) { - for (int i : inventory.getAccessibleSlotsFromSide(from.ordinal())) { - ItemStack stack = inventory.getStackInSlot(i); - if (stack != null && stack.stackSize > 0) { - ItemStack filter = getCurrentFilter(); - if (filter == null) { - return null; - } - if (!StackHelper.isMatchingItemOrList(stack, filter)) { - continue; - } - if (!inventory.canExtractItem(i, stack, from.ordinal())) { - continue; - } - if (doRemove) { - int stackSize = (int) Math.floor(battery.useEnergy(10, stack.stackSize * 10, false) / 10); + public ItemStack checkExtractGeneric(ISidedInventory inventory, boolean doRemove, ForgeDirection from) { + if (inventory == null) { + return null; + } - return inventory.decrStackSize(i, stackSize); + ItemStack filter = getCurrentFilter(); + if (filter == null) { + return null; + } + + for (int k : inventory.getAccessibleSlotsFromSide(from.ordinal())) { + ItemStack slot = inventory.getStackInSlot(k); + + if (slot != null && slot.stackSize > 0 && inventory.canExtractItem(k, slot, from.ordinal())) { + if (!StackHelper.isMatchingItemOrList(slot, filter)) { + continue; + } + + if (doRemove) { + int maxStackSize = slot.stackSize; + int stackSize = Math.min(maxStackSize, battery.getEnergyStored() / 10); + int energyUsed = (int) (stackSize * 10 * speedMultiplier); + battery.useEnergy(energyUsed, energyUsed, false); + + // Only increment the filter position after a successful extraction + incrementFilter(); + + return inventory.decrStackSize(k, stackSize); } else { - return stack; + return slot; } } } @@ -226,6 +234,6 @@ public class PipeItemsEmzuli extends PipeItemsWood implements IGuiReturnHandler } private ItemStack getCurrentFilter() { - return filters.getStackInSlot(currentFilter % filters.getSizeInventory()); + return filters.getStackInSlot(currentFilter % filterCount); } }