mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-09 15:25:56 -04:00
generator fixes and change in behavior
1. insert now puts a single container back in the inventory. this is not fully ic2 fuel cell compatible, you'll lose fuel cells. :) 2. remove requires container if fuel has container type 3. count returns 2nd value, the item name closes #3391
This commit is contained in:
parent
4a50b50725
commit
41a6b8ac96
@ -53,6 +53,8 @@ class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends pr
|
||||
if (!TileEntityFurnace.isItemFuel(stack)) {
|
||||
return result(Unit, "selected slot does not contain fuel")
|
||||
}
|
||||
val container = stack.getItem().getContainerItem(stack)
|
||||
var consumedCount = 0
|
||||
inventory match {
|
||||
case Some(existingStack) =>
|
||||
if (!existingStack.isItemEqual(stack) ||
|
||||
@ -63,38 +65,79 @@ class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends pr
|
||||
if (space <= 0) {
|
||||
return result(Unit, "queue is full")
|
||||
}
|
||||
val moveCount = math.min(stack.stackSize, math.min(space, count))
|
||||
existingStack.stackSize += moveCount
|
||||
stack.stackSize -= moveCount
|
||||
consumedCount = math.min(stack.stackSize, math.min(space, count))
|
||||
existingStack.stackSize += consumedCount
|
||||
stack.stackSize -= consumedCount
|
||||
case _ =>
|
||||
inventory = Some(stack.splitStack(math.min(stack.stackSize, count)))
|
||||
consumedCount = math.min(stack.stackSize, count)
|
||||
inventory = Some(stack.splitStack(consumedCount))
|
||||
}
|
||||
if (stack.stackSize > 0) host.mainInventory.setInventorySlotContents(host.selectedSlot, stack)
|
||||
else host.mainInventory.setInventorySlotContents(host.selectedSlot, null)
|
||||
if (consumedCount > 0 && container != null) {
|
||||
container.stackSize = consumedCount
|
||||
}
|
||||
if (stack.stackSize > 0) {
|
||||
host.mainInventory.setInventorySlotContents(host.selectedSlot, stack)
|
||||
}
|
||||
if (stack.stackSize == 0 || container != null) {
|
||||
host.mainInventory.setInventorySlotContents(host.selectedSlot, container)
|
||||
}
|
||||
|
||||
result(true)
|
||||
}
|
||||
|
||||
@Callback(doc = """function():number -- Get the size of the item stack in the generator's queue.""")
|
||||
def count(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
inventory match {
|
||||
case Some(stack) => result(stack.stackSize)
|
||||
case Some(stack) => result(stack.stackSize, stack.getItem.getItemStackDisplayName(stack))
|
||||
case _ => result(0)
|
||||
}
|
||||
}
|
||||
|
||||
@Callback()
|
||||
def clear(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
inventory = None
|
||||
remainingTicks = 0
|
||||
result(true)
|
||||
}
|
||||
|
||||
@Callback(doc = """function([count:number]):boolean -- Tries to remove items from the generator's queue.""")
|
||||
def remove(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
val count = args.optInteger(0, Int.MaxValue)
|
||||
var selectSlotContainer: ItemStack = null
|
||||
inventory match {
|
||||
case Some(stack) =>
|
||||
val removedStack = stack.splitStack(math.min(count, stack.stackSize))
|
||||
val success = host.player.inventory.addItemStackToInventory(removedStack)
|
||||
stack.stackSize += removedStack.stackSize
|
||||
if (success && stack.stackSize <= 0) {
|
||||
inventory = None
|
||||
val moveCount = Option(stack.getItem().getContainerItem(stack)) match {
|
||||
case Some(fuelContainer) =>
|
||||
// if the fuel requires a container, we can only refill containers
|
||||
Option(host.mainInventory.getStackInSlot(host.selectedSlot)) match {
|
||||
case Some(selectedStack) if selectedStack.getItem() == fuelContainer.getItem() =>
|
||||
selectSlotContainer = selectedStack.copy() // keep a copy in case we have to put it back
|
||||
1 // refill one container
|
||||
case _ => 0 // container required
|
||||
}
|
||||
case _ => count
|
||||
}
|
||||
result(success)
|
||||
case _ => result(false)
|
||||
if (moveCount == 0) {
|
||||
result(false, "fuel requires container in the selected slot")
|
||||
} else {
|
||||
val removedStack = stack.splitStack(math.min(moveCount, stack.stackSize))
|
||||
if (selectSlotContainer != null) {
|
||||
host.mainInventory.decrStackSize(host.selectedSlot, 1)
|
||||
}
|
||||
val success = host.player.inventory.addItemStackToInventory(removedStack)
|
||||
stack.stackSize += removedStack.stackSize
|
||||
if (success) {
|
||||
if (stack.stackSize <= 0) {
|
||||
inventory = None
|
||||
}
|
||||
result(true)
|
||||
} else {
|
||||
// if we decremented the container, we need to put it back
|
||||
host.mainInventory.setInventorySlotContents(host.selectedSlot, selectSlotContainer)
|
||||
result(false, "no inventory space available for fuel")
|
||||
}
|
||||
}
|
||||
case _ => result(false, "queue is empty")
|
||||
}
|
||||
}
|
||||
|
||||
@ -108,13 +151,10 @@ class UpgradeGenerator(val host: EnvironmentHost with internal.Agent) extends pr
|
||||
val stack = inventory.get
|
||||
remainingTicks = TileEntityFurnace.getItemBurnTime(stack)
|
||||
if (remainingTicks > 0) {
|
||||
// If not we probably have a container item now (e.g. bucket after lava bucket).
|
||||
updateClient()
|
||||
stack.stackSize -= 1
|
||||
if (stack.stackSize <= 0) {
|
||||
if (stack.getItem.hasContainerItem(stack))
|
||||
inventory = Option(stack.getItem.getContainerItem(stack))
|
||||
else
|
||||
// do not put container in inventory (we left the container when fuel was inserted)
|
||||
inventory = None
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user