mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Made sink slot optional when specifying source slot in transposer.transferItem
(#1425).
This commit is contained in:
parent
36002da462
commit
7760077202
@ -12,7 +12,7 @@ trait InventoryTransfer extends traits.WorldAware with traits.SideRestricted {
|
||||
// Return None on success, else Some("failure reason")
|
||||
def onTransferContents(): Option[String]
|
||||
|
||||
@Callback(doc = """function(sourceSide:number, sinkSide:number[, count:number[, sourceSlot:number, sinkSlot:number]]):number -- Transfer some items between two inventories.""")
|
||||
@Callback(doc = """function(sourceSide:number, sinkSide:number[, count:number[, sourceSlot:number[, sinkSlot:number]]]):number -- Transfer some items between two inventories.""")
|
||||
def transferItem(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val sourceSide = checkSideForAction(args, 0)
|
||||
val sourcePos = position.offset(sourceSide)
|
||||
@ -26,9 +26,9 @@ trait InventoryTransfer extends traits.WorldAware with traits.SideRestricted {
|
||||
case _ =>
|
||||
if (args.count > 3) {
|
||||
val sourceSlot = args.checkSlot(InventoryUtils.inventoryAt(sourcePos).getOrElse(throw new IllegalArgumentException("no inventory")), 3)
|
||||
val sinkSlot = args.checkSlot(InventoryUtils.inventoryAt(sinkPos).getOrElse(throw new IllegalArgumentException("no inventory")), 4)
|
||||
val sinkSlot = args.optSlot(InventoryUtils.inventoryAt(sinkPos).getOrElse(throw new IllegalArgumentException("no inventory")), 4, -1)
|
||||
|
||||
result(InventoryUtils.transferBetweenInventoriesSlotsAt(sourcePos, sourceSide.getOpposite, sourceSlot, sinkPos, Option(sinkSide.getOpposite), sinkSlot, count))
|
||||
result(InventoryUtils.transferBetweenInventoriesSlotsAt(sourcePos, sourceSide.getOpposite, sourceSlot, sinkPos, Option(sinkSide.getOpposite), if (sinkSlot < 0) None else Option(sinkSlot), count))
|
||||
}
|
||||
else result(InventoryUtils.transferBetweenInventoriesAt(sourcePos, sourceSide.getOpposite, sinkPos, Option(sinkSide.getOpposite), count))
|
||||
}
|
||||
|
@ -249,9 +249,15 @@ object InventoryUtils {
|
||||
/**
|
||||
* Like <tt>transferBetweenInventories</tt> but moving between specific slots.
|
||||
*/
|
||||
def transferBetweenInventoriesSlots(source: IInventory, sourceSide: ForgeDirection, sourceSlot: Int, sink: IInventory, sinkSide: Option[ForgeDirection], sinkSlot: Int, limit: Int = 64) =
|
||||
extractFromInventorySlot(
|
||||
insertIntoInventorySlot(_, sink, sinkSide, sinkSlot, limit), source, sourceSide, sourceSlot, limit)
|
||||
def transferBetweenInventoriesSlots(source: IInventory, sourceSide: ForgeDirection, sourceSlot: Int, sink: IInventory, sinkSide: Option[ForgeDirection], sinkSlot: Option[Int], limit: Int = 64) =
|
||||
sinkSlot match {
|
||||
case Some(explicitSinkSlot) =>
|
||||
extractFromInventorySlot(
|
||||
insertIntoInventorySlot(_, sink, sinkSide, explicitSinkSlot, limit), source, sourceSide, sourceSlot, limit)
|
||||
case _ =>
|
||||
extractFromInventorySlot(
|
||||
insertIntoInventory(_, sink, sinkSide, limit), source, sourceSide, sourceSlot, limit)
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for calling <tt>transferBetweenInventories</tt> on inventories
|
||||
@ -266,7 +272,7 @@ object InventoryUtils {
|
||||
* Utility method for calling <tt>transferBetweenInventoriesSlots</tt> on inventories
|
||||
* in the world.
|
||||
*/
|
||||
def transferBetweenInventoriesSlotsAt(sourcePos: BlockPosition, sourceSide: ForgeDirection, sourceSlot: Int, sinkPos: BlockPosition, sinkSide: Option[ForgeDirection], sinkSlot: Int, limit: Int = 64) =
|
||||
def transferBetweenInventoriesSlotsAt(sourcePos: BlockPosition, sourceSide: ForgeDirection, sourceSlot: Int, sinkPos: BlockPosition, sinkSide: Option[ForgeDirection], sinkSlot: Option[Int], limit: Int = 64) =
|
||||
inventoryAt(sourcePos).exists(sourceInventory =>
|
||||
inventoryAt(sinkPos).exists(sinkInventory =>
|
||||
transferBetweenInventoriesSlots(sourceInventory, sourceSide, sourceSlot, sinkInventory, sinkSide, sinkSlot, limit)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user