mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-09 15:25:56 -04:00
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).
This commit is contained in:
parent
83ce705a99
commit
931a04c61b
@ -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 {
|
||||
* <p/>
|
||||
* This returns <tt>true</tt> 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 <tt>insertIntoInventory</tt> on an inventory
|
||||
|
Loading…
x
Reference in New Issue
Block a user