From b051b10c1841bb8f8a371f523279e039ddc0117d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= Date: Sat, 24 Jan 2015 22:35:19 +0100 Subject: [PATCH] Fix InventoryUtils.insertIntoInventory According to the documentation inventory_controller.suckFromSlot, robot.suck and friends try to put the sucked item into the selected slot, and only if it's occupied try others. However the implementation first tried to merge the stack with existing stacks in the inventory, and only if it failed put into the selected slot. This commit fixes it. --- src/main/scala/li/cil/oc/util/InventoryUtils.scala | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/scala/li/cil/oc/util/InventoryUtils.scala b/src/main/scala/li/cil/oc/util/InventoryUtils.scala index fcf6557b9..e8e82e10d 100644 --- a/src/main/scala/li/cil/oc/util/InventoryUtils.scala +++ b/src/main/scala/li/cil/oc/util/InventoryUtils.scala @@ -155,6 +155,12 @@ object InventoryUtils { var remaining = limit val range = slots.getOrElse(0 until inventory.getSizeInventory) + val stackSize = stack.stackSize + if ((inventory.getStackInSlot(range.head) == null) && insertIntoInventorySlot(stack, inventory, side, range.head, remaining, simulate)) { + remaining -= stackSize - stack.stackSize + success = true + } + val shouldTryMerge = !stack.isItemStackDamageable && stack.getMaxStackSize > 1 && inventory.getInventoryStackLimit > 1 if (shouldTryMerge) { for (slot <- range) { @@ -166,7 +172,7 @@ object InventoryUtils { } } - for (slot <- range) { + for (slot <- range.tail) { val stackSize = stack.stackSize if ((inventory.getStackInSlot(slot) == null) && insertIntoInventorySlot(stack, inventory, side, slot, remaining, simulate)) { remaining -= stackSize - stack.stackSize