mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Update the input itemstack in insertIntoInventorySlot even during simulation.
Only the Trade Upgrade is using this right now.
This commit is contained in:
parent
d781eb3c62
commit
f01cde3906
@ -79,7 +79,8 @@ object InventoryUtils {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* This will return <tt>true</tt> if <em>at least</em> one item could be
|
* 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
|
* 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/>
|
* <p/>
|
||||||
* This takes care of handling special cases such as sided inventories,
|
* This takes care of handling special cases such as sided inventories,
|
||||||
* maximum inventory and item stack sizes.
|
* 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 =
|
def insertIntoInventorySlot(stack: ItemStack, inventory: IItemHandler, slot: Int, limit: Int = 64, simulate: Boolean = false): Boolean =
|
||||||
(stack != null && limit > 0 && stack.stackSize > 0) && {
|
(stack != null && limit > 0 && stack.stackSize > 0) && {
|
||||||
val amount = math.min(stack.stackSize, limit)
|
val amount = stack.stackSize min 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 toInsert = stack.splitStack(amount)
|
val toInsert = stack.splitStack(amount)
|
||||||
inventory.insertItem(slot, toInsert, simulate) match {
|
inventory.insertItem(slot, toInsert, simulate) match {
|
||||||
case remaining: ItemStack =>
|
case remaining: ItemStack =>
|
||||||
@ -107,7 +100,6 @@ object InventoryUtils {
|
|||||||
case _ => true
|
case _ => true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
def insertIntoInventorySlot(stack: ItemStack, inventory: IInventory, side: Option[EnumFacing], slot: Int, limit: Int, simulate: Boolean): Boolean =
|
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)
|
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 = {
|
def extractFromInventorySlot(consumer: (ItemStack) => Unit, inventory: IItemHandler, slot: Int, limit: Int = 64): Boolean = {
|
||||||
val stack = inventory.getStackInSlot(slot)
|
val stack = inventory.getStackInSlot(slot)
|
||||||
(stack != null && limit > 0 && stack.stackSize > 0) && {
|
(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 {
|
inventory.extractItem(slot, amount, true) match {
|
||||||
case extracted: ItemStack =>
|
case extracted: ItemStack =>
|
||||||
amount = extracted.stackSize
|
amount = extracted.stackSize
|
||||||
|
Loading…
x
Reference in New Issue
Block a user