mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-04-11 21:33:15 +00:00
Allow craft program to craft unlimited items (#807)
This commit is contained in:
parent
0f6db63020
commit
f8074636bc
@ -1,5 +1,5 @@
|
||||
craft is a program for Crafty Turtles. Craft will craft a stack of items using the current inventory.
|
||||
|
||||
ex:
|
||||
"craft" will craft as many items as possible
|
||||
"craft all" will craft as many items as possible
|
||||
"craft 5" will craft at most 5 times
|
||||
|
@ -9,20 +9,19 @@ if not turtle.craft then
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
local nLimit = nil
|
||||
if #tArgs < 1 then
|
||||
local nLimit = tonumber(tArgs[1])
|
||||
|
||||
if not nLimit and tArgs[1] ~= "all" then
|
||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||
print("Usage: " .. programName .. " [number]")
|
||||
print("Usage: " .. programName .. " all|<number>")
|
||||
return
|
||||
else
|
||||
nLimit = tonumber(tArgs[1])
|
||||
end
|
||||
|
||||
local nCrafted = 0
|
||||
local nOldCount = turtle.getItemCount(turtle.getSelectedSlot())
|
||||
if turtle.craft(nLimit) then
|
||||
local nNewCount = turtle.getItemCount(turtle.getSelectedSlot())
|
||||
if nOldCount <= nLimit then
|
||||
if not nLimit or nOldCount <= nLimit then
|
||||
nCrafted = nNewCount
|
||||
else
|
||||
nCrafted = nOldCount - nNewCount
|
||||
|
@ -19,7 +19,14 @@ describe("The craft program", function()
|
||||
stub(_G, "turtle", { craft = function() end })
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua"))
|
||||
:matches { ok = true, output = "Usage: /rom/programs/turtle/craft.lua [number]\n", error = "" }
|
||||
:matches { ok = true, output = "Usage: /rom/programs/turtle/craft.lua all|<number>\n", error = "" }
|
||||
end)
|
||||
|
||||
it("displays its usage when given incorrect arguments", function()
|
||||
stub(_G, "turtle", { craft = function() end })
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua a"))
|
||||
:matches { ok = true, output = "Usage: /rom/programs/turtle/craft.lua all|<number>\n", error = "" }
|
||||
end)
|
||||
|
||||
it("crafts multiple items", function()
|
||||
@ -52,7 +59,7 @@ describe("The craft program", function()
|
||||
:matches { ok = true, output = "1 item crafted\n", error = "" }
|
||||
end)
|
||||
|
||||
it("crafts no items", function()
|
||||
it("crafts no items", function()
|
||||
local item_count = 2
|
||||
stub(_G, "turtle", {
|
||||
craft = function()
|
||||
@ -66,4 +73,17 @@ describe("The craft program", function()
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua 1"))
|
||||
:matches { ok = true, output = "No items crafted\n", error = "" }
|
||||
end)
|
||||
|
||||
it("crafts all items", function()
|
||||
stub(_G, "turtle", {
|
||||
craft = function()
|
||||
return true
|
||||
end,
|
||||
getItemCount = function() return 17 end,
|
||||
getSelectedSlot = function() return 1 end,
|
||||
})
|
||||
|
||||
expect(capture(stub, "/rom/programs/turtle/craft.lua all"))
|
||||
:matches { ok = true, output = "17 items crafted\n", error = "" }
|
||||
end)
|
||||
end)
|
||||
|
Loading…
x
Reference in New Issue
Block a user