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.
This commit is contained in:
Kővágó, Zoltán 2015-01-24 22:35:19 +01:00
parent dbf99cdf4e
commit b051b10c18

View File

@ -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