pp = require("cc.pretty") require("recipes") sfx = require("sfx") require("pathfinding") use_machine = require("machines") require("inventory") keep_stocked = { kelp = 10, flint = 10 } goHome() print("known recipes:\n") for k,_ in pairs(recipes) do write(k) write(", ") end write("\nchoose one: ") function completion(partial) list = {} for k,_ in pairs(recipes) do if string.sub(k, 1, #partial) == partial then table.insert(list, string.sub(k, #partial + 1)) end end return list end input = splitString(read(nil, nil, completion)) target_product = input[1] copies = input[2] or 1 if recipes[target_product] == nil then print("I don't know how to make that, sorry") return end -- pp.pretty_print(ingredientsOf(recipes[target_product])) -- pp.pretty_print(recipes) function doRecipe(recipe) inited = false for i = 1, recipe.repeats do for _, step in pairs(recipe.steps) do if inited then selectItem(recipe.intermediate, true) else inited = true selectItem(recipe.base, false) end use_machine[step.machine](step.extra_items) -- read() end end goHome() for i = 1, 16 do if turtle.getItemCount(i) ~= 0 then turtle.select(i) turtle.drop() end end turtle.select(1) end todo = {} for i = 1,copies do table.insert(todo, recipes[target_product]) end function listUncraftable(ingredients) wait_for = {} if len(ingredients) == 0 then return wait_for end for name, count in pairs(ingredients) do print("missing", count, name) if recipes[name] == nil then wait_for[name] = count end end return wait_for end function tryCreating(recipe) ingredients = ingredientsOf(recipe) missing_ingredients = getMissing(ingredients) if len(missing_ingredients) == 0 then todo[#todo] = nil turtle.select(1) -- todo exclude deploy_tool too and make it get its own tool if recipe.steps[1].machine ~= "craft" then for item, count in pairs(ingredients) do takeItems(item, count) end end doRecipe(current_recipe) return nil end return missing_ingredients end while #todo > 0 do -- for item, _count in pairs(getMissing(keep_stocked)) do -- print("creating", item, "to keep stock up") -- tryCreating(recipes[item]) -- end current_recipe = todo[#todo] -- ingredients = ingredientsOf(current_recipe) pp.pretty_print(ingredients) missing_ingredients = tryCreating(current_recipe) if missing_ingredients then wait_for = listUncraftable(missing_ingredients) while len(wait_for) > 0 do for name,count in pairs(wait_for) do print("please supply", count, name, "manually") end print("press return to continue, q to quit") sfx.fail() if read() == "q" then return end missing_ingredients = getMissing(ingredients) wait_for = listUncraftable(missing_ingredients) end for name, count in pairs(missing_ingredients) do if recipes[name] then print("first making", count, name) table.insert(todo, recipes[name]) end end end end print("done!") sfx.success()