|
|
|
@ -326,8 +326,9 @@ end
|
|
|
|
|
|
|
|
|
|
---accepts a recipe table
|
|
|
|
|
---@param search string search for an craftable item
|
|
|
|
|
---@param amount number how many items to craft
|
|
|
|
|
---@return boolean
|
|
|
|
|
local function craft_item(search)
|
|
|
|
|
local function craft_item(search, amount)
|
|
|
|
|
search = string.lower(search) -- convert to unified lowercase
|
|
|
|
|
|
|
|
|
|
local matches = {}
|
|
|
|
@ -374,8 +375,13 @@ local function craft_item(search)
|
|
|
|
|
|
|
|
|
|
local recipe = recipes[selected]
|
|
|
|
|
|
|
|
|
|
print('Trying to craft ' .. recipe.result)
|
|
|
|
|
print('Trying to craft ' .. amount .. 'x ' .. recipe.result)
|
|
|
|
|
|
|
|
|
|
local repeating = false
|
|
|
|
|
|
|
|
|
|
local count = math.ceil(amount / recipe.count)
|
|
|
|
|
|
|
|
|
|
for _ = 1, count do
|
|
|
|
|
local available_items = read_chest_contents()
|
|
|
|
|
if not available_items then
|
|
|
|
|
print('Not facing a chest')
|
|
|
|
@ -402,39 +408,39 @@ local function craft_item(search)
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if not repeating then
|
|
|
|
|
if not confirm() then
|
|
|
|
|
print('Operation cancelled')
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- print('\nCrafting in order:')
|
|
|
|
|
-- for i, rec in ipairs(crafting_order) do
|
|
|
|
|
-- print(i, rec.result)
|
|
|
|
|
-- end
|
|
|
|
|
|
|
|
|
|
-- if not confirm() then
|
|
|
|
|
-- print('Operation cancelled')
|
|
|
|
|
-- return false
|
|
|
|
|
-- end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- proceed to crafting the things
|
|
|
|
|
local steps = #crafting_order
|
|
|
|
|
for i, rec in ipairs(crafting_order) do
|
|
|
|
|
print('Step #' .. i .. ' - ' .. rec.result)
|
|
|
|
|
print('Step ' .. i .. '/' .. steps .. ' - ' .. rec.result)
|
|
|
|
|
if not craft_single_recipe(rec, 1) then
|
|
|
|
|
print('Unexpected error')
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
repeating = true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local target = ...
|
|
|
|
|
local target, amount = ...
|
|
|
|
|
|
|
|
|
|
if not target then
|
|
|
|
|
print("Usage: craft <item>")
|
|
|
|
|
print("Usage: craft <item> [count]")
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
craft_item(target)
|
|
|
|
|
if not amount then
|
|
|
|
|
amount = 1
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
craft_item(target, amount)
|
|
|
|
|
|
|
|
|
|