Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Using: CC: Tweaked, Plethora
- pastebin run sBTwAePK
- pastebin get sBTwAePK startup
- ]]--
- if pcall(os.loadAPI, "jLib/jFuncs") then
- else
- shell.run("pastebin get kqBFGcfV jLib/jFuncs")
- os.loadAPI("jLib/jFuncs")
- end
- if(fs.exists("jLib/ExternalCrafterRecipes")) then
- fs.delete("jLib/ExternalCrafterRecipes")
- end
- shell.run("pastebin get a2DA84Hg jLib/ExternalCrafterRecipes")
- local inputChest = peripheral.wrap("back")
- local self = peripheral.wrap("left").getInventory()
- local file = fs.open("jLib/ExternalCrafterRecipes", "r")
- local recipes = textutils.unserialize(file.readAll())
- local function containsRecipe(items, recipe)
- local needed = {}
- for _, material in pairs(recipe) do
- table.insert(needed, {["name"] = material.name, ["damage"] = material.damage, ["nbtHash"] = material.nbtHash, ["checked"] = false})
- end
- local lItems = jFuncs.tableClone(items)
- local ret = {}
- for _, material in pairs(needed) do
- for i, item in pairs(lItems) do
- if(item.name == material.name and item.damage == material.damage and item.nbtHash == material.nbtHash and not material.checked and item.count > 0) then
- table.insert(ret, { ["slot"] = i })
- material.checked = true
- item.count = item.count - 1
- end
- end
- end
- for _, material in pairs(needed) do
- if(not material.checked) then
- return nil
- end
- end
- return ret
- end
- local function firstValidRecipe(items)
- local valid = nil
- for i, recipe in pairs(recipes) do
- valid = containsRecipe(items, recipe)
- if(valid ~= nil) then
- return i
- end
- end
- return nil
- end
- local function getFirst(toGet)
- local allItems = inputChest.list()
- for i, item in pairs(allItems) do
- if(item.name == toGet.name and item.damage == toGet.damage and item.nbtHash == toGet.nbtHash) then
- return i
- end
- end
- return nil
- end
- local function pullRecipe(recipe)
- local slot
- for i, material in pairs(recipe) do
- slot = getFirst(material)
- self.pullItems("back", slot, 1, math.floor(i + i/3 - 1/3))
- end
- end
- local function pushItems()
- for i, _ in pairs(self.list()) do
- self.pushItems("top", i)
- end
- end
- while (true) do
- local allItems = inputChest.list()
- local recipeIndex = firstValidRecipe(allItems)
- if(recipeIndex ~= nil) then
- print("Pulling recipe: " .. recipeIndex)
- pullRecipe(recipes[recipeIndex])
- turtle.craft()
- pushItems()
- else
- os.sleep(1)
- end
- end
Add Comment
Please, Sign In to add comment