From 931a04c61b254ca3ae2128d3d66b8af3b8151fcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 29 Aug 2015 15:55:38 +0200 Subject: [PATCH] Taking into account ISidedInventory.getAccessibleSlotsFromSide in InventoryUtils, because some inventories are... special. E.g. AgriCraft's Analyzer has getInventorySize = 2, but there are no slots 0 and 1, only slots 36 and 37 (or so; anyway, something way out of the range of to be expected valid indices). --- src/main/scala/li/cil/oc/util/InventoryUtils.scala | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/scala/li/cil/oc/util/InventoryUtils.scala b/src/main/scala/li/cil/oc/util/InventoryUtils.scala index 35a691e66..c2f21a5ec 100644 --- a/src/main/scala/li/cil/oc/util/InventoryUtils.scala +++ b/src/main/scala/li/cil/oc/util/InventoryUtils.scala @@ -155,7 +155,10 @@ object InventoryUtils { (stack != null && limit > 0) && { var success = false var remaining = limit - val range = slots.getOrElse(0 until inventory.getSizeInventory) + val range = slots.getOrElse(inventory match { + case sided: ISidedInventory => sided.getAccessibleSlotsFromSide(side.getOrElse(ForgeDirection.UNKNOWN).ordinal).toIterable + case _ => 0 until inventory.getSizeInventory + }) if (range.nonEmpty) { // This is a special case for inserting with an explicit ordering, @@ -204,8 +207,13 @@ object InventoryUtils { *

* This returns true if at least one item was extracted. */ - def extractFromInventory(consumer: (ItemStack) => Unit, inventory: IInventory, side: ForgeDirection, limit: Int = 64) = - (0 until inventory.getSizeInventory).exists(slot => extractFromInventorySlot(consumer, inventory, side, slot, limit)) + def extractFromInventory(consumer: (ItemStack) => Unit, inventory: IInventory, side: ForgeDirection, limit: Int = 64) = { + val range = inventory match { + case sided: ISidedInventory => sided.getAccessibleSlotsFromSide(side.ordinal).toIterable + case _ => 0 until inventory.getSizeInventory + } + range.exists(slot => extractFromInventorySlot(consumer, inventory, side, slot, limit)) + } /** * Utility method for calling insertIntoInventory on an inventory