mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-16 18:55:03 -04:00
generator.insert no longer throws if slot was empty (never should have); cleaned and patched up refuel.lua a little
This commit is contained in:
parent
7c6837c7ae
commit
b73f39c443
@ -29,7 +29,7 @@ class UpgradeGenerator(val owner: TileEntity) extends ManagedComponent {
|
||||
val count = if (args.count > 0) args.checkInteger(0) else 64
|
||||
val player = context.player
|
||||
val stack = player.inventory.getStackInSlot(context.selectedSlot)
|
||||
if (stack == null) throw new IllegalArgumentException("selected slot is empty")
|
||||
if (stack == null) return result(Unit, "selected slot is empty")
|
||||
if (!TileEntityFurnace.isItemFuel(stack)) {
|
||||
return result(Unit, "selected slot does not contain fuel")
|
||||
}
|
||||
|
@ -4,49 +4,54 @@ local component = require("component")
|
||||
local robot = require("robot")
|
||||
local shell = require("shell")
|
||||
|
||||
local args = shell.parse(...)
|
||||
-- Not using shell.parse to allow `refuel 1 -10`, the -10 would be
|
||||
-- parsed as an option otherwise.
|
||||
local args = {...}
|
||||
|
||||
local function printUsage()
|
||||
print("Usages:")
|
||||
print("'refuel' to get the current fuel count")
|
||||
print("'refuel <slot> [amount]' to refuel [amount] from that specific slot,\n or try to completely fill it")
|
||||
print("'refuel all' to refuel from all slots")
|
||||
print("refuel")
|
||||
print(" Gets the current fuel count.")
|
||||
print("refuel <slot> [amount]")
|
||||
print(" Refuel the specified number of items (default")
|
||||
print(" as many as possible) from the specified slot.")
|
||||
print("refuel all")
|
||||
print(" Refuel from all slots.")
|
||||
end
|
||||
|
||||
if component.isAvailable("generator") then
|
||||
local g = component.generator
|
||||
if #args == 0 then
|
||||
print("Current Number of items in generator: "..g.count())
|
||||
print("Current number of items in generator: "..g.count())
|
||||
elseif tonumber(args[1]) ~= nil then
|
||||
print("Refuelling from slot"..args[1].."...")
|
||||
robot.select(tonumber(args[1]))
|
||||
local success, msg
|
||||
if tonumber(args[2]) ~= nil then
|
||||
if tonumber(args[2]) > 0 then
|
||||
success, msg = g.insert(tonumber(args[2]))
|
||||
elseif tonumber(args[2]) < 0 then
|
||||
success = g.remove(math.abs(tonumber(args[2])))
|
||||
if not (success == true) then msg = "Could not remove item, generator is empty" end
|
||||
local slot = tonumber(args[1])
|
||||
local count = tonumber(args[2]) or 64
|
||||
robot.select(slot)
|
||||
if count > 0 then
|
||||
io.write("Refueling from slot "..slot.."... ")
|
||||
local success, msg = g.insert(count)
|
||||
if success then
|
||||
print("success.")
|
||||
else
|
||||
msg = "You can't insert 0 of an item!"
|
||||
print("failed: "..msg)
|
||||
end
|
||||
else
|
||||
success, msg = g.insert()
|
||||
end
|
||||
if success then
|
||||
print("Success.")
|
||||
else
|
||||
print("Error: "..msg)
|
||||
end
|
||||
elseif count < 0 then
|
||||
io.write("Ejecting into slot "..slot.."... ")
|
||||
if g.remove(-count) then
|
||||
print("success.")
|
||||
else
|
||||
print("failed.")
|
||||
end
|
||||
end -- else: ignore zero
|
||||
robot.select(1)
|
||||
elseif string.lower(args[1]) == "all" then
|
||||
io.write("Refuelling from all slots...")
|
||||
io.write("Refueling from all slots... ")
|
||||
for i = 1, 16 do
|
||||
robot.select(i)
|
||||
g.insert()
|
||||
end
|
||||
robot.select(1)
|
||||
print("Done.")
|
||||
print("done.")
|
||||
else
|
||||
printUsage()
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user