Update the input itemstack in insertIntoInventorySlot even during simulation.

Only the Trade Upgrade is using this right now.
This commit is contained in:
Vexatos 2017-05-13 16:40:29 +02:00
parent d781eb3c62
commit f01cde3906

View File

@ -79,7 +79,8 @@ object InventoryUtils {
* <p/>
* This will return <tt>true</tt> if <em>at least</em> one item could be
* inserted into the slot. It will return <tt>false</tt> if the passed
* stack did not change.
* stack did not change. Note that it will also change the stack
* when called with <tt>simulate = true</tt>.
* <p/>
* This takes care of handling special cases such as sided inventories,
* maximum inventory and item stack sizes.
@ -89,15 +90,7 @@ object InventoryUtils {
*/
def insertIntoInventorySlot(stack: ItemStack, inventory: IItemHandler, slot: Int, limit: Int = 64, simulate: Boolean = false): Boolean =
(stack != null && limit > 0 && stack.stackSize > 0) && {
val amount = math.min(stack.stackSize, limit)
if (simulate) {
val toInsert = stack.copy()
toInsert.stackSize = amount
inventory.insertItem(slot, toInsert, simulate) match {
case remaining: ItemStack => remaining.stackSize < amount
case _ => true
}
} else {
val amount = stack.stackSize min limit
val toInsert = stack.splitStack(amount)
inventory.insertItem(slot, toInsert, simulate) match {
case remaining: ItemStack =>
@ -107,7 +100,6 @@ object InventoryUtils {
case _ => true
}
}
}
def insertIntoInventorySlot(stack: ItemStack, inventory: IInventory, side: Option[EnumFacing], slot: Int, limit: Int, simulate: Boolean): Boolean =
insertIntoInventorySlot(stack, asItemHandler(inventory, side.orNull), slot, limit, simulate)
@ -140,7 +132,7 @@ object InventoryUtils {
def extractFromInventorySlot(consumer: (ItemStack) => Unit, inventory: IItemHandler, slot: Int, limit: Int = 64): Boolean = {
val stack = inventory.getStackInSlot(slot)
(stack != null && limit > 0 && stack.stackSize > 0) && {
var amount = math.min(stack.getMaxStackSize, math.min(stack.stackSize, limit))
var amount = stack.getMaxStackSize min stack.stackSize min limit
inventory.extractItem(slot, amount, true) match {
case extracted: ItemStack =>
amount = extracted.stackSize