Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Using: CC: Tweaked, Plethora
- pastebin run uaq2nM4K
- pastebin get uaq2nM4K export
- ]]--
- if pcall(os.loadAPI, "jLib/jFuncs") then
- else
- shell.run("pastebin get kqBFGcfV jLib/jFuncs")
- os.loadAPI("jLib/jFuncs")
- end
- local recipeFileName = "jLib/MEExporterRecipes"
- if(fs.exists(recipeFileName)) then
- fs.delete(recipeFileName )
- end
- shell.run("pastebin get NBmGUktC " .. recipeFileName)
- local file = fs.open(recipeFileName, "r")
- local recipes = textutils.unserialize(file.readAll())
- local interface = peripheral.find("appliedenergistics2:interface")
- local function waitForCPU()
- while(true) do
- for _, cpu in pairs(interface.getCraftingCPUs()) do
- if(not cpu.busy) then
- return
- end
- end
- os.sleep(1)
- end
- end
- local function stackUpME(allItems)
- local allTasks = {}
- for _, listItem in pairs(allItems) do
- local aeItem = interface.findItem(listItem)
- if(aeItem == nil) then
- print("Missing " .. listItem.name .. " in ME System")
- return nil
- else
- local aeItemMeta = aeItem.getMetadata()
- if(aeItemMeta.count < listItem.count) then
- print("Crafting " .. listItem.count - aeItemMeta.count .. " " .. listItem.name .. "-" .. listItem.damage .. " in ME System")
- waitForCPU()
- local task = aeItem.craft(listItem.count - aeItemMeta.count)
- if(task.status() == "missing") then
- print("No materials!")
- return nil
- end
- table.insert(allTasks , task)
- end
- end
- end
- return allTasks
- end
- local function exportFromME(allItems)
- for _, listItem in pairs(allItems) do
- local aeItem = interface.findItem(listItem)
- if(aeItem == nil) then
- print("Missing " .. listItem.name .. " in ME System")
- else
- local aeItemMeta = aeItem.getMetadata()
- if(aeItemMeta.count < listItem.count) then
- print("Crafting not done, error. " .. listItem.count - aeItemMeta.count .. " " .. listItem.name .. "-" .. listItem.damage .. " in ME System")
- return
- else
- --print(string.format("%s: Got %s, Need %s", listItem.name, aeItemMeta.count, listItem.count))
- local toExport = listItem.count
- while (toExport > 0) do
- toExport = toExport - aeItem.export("left", 64)
- end
- end
- end
- end
- end
- local args = {...}
- if(args[1] == nil) then
- print("Need a recipe name as argument.")
- return
- end
- if(args[2] == nil) then
- args[2] = args[1]
- args[1] = 1
- end
- local allItems = recipes[args[2]]
- if(allItems == nil) then
- print("Could not find recipe " .. args[2])
- return
- end
- for _, item in pairs(allItems) do
- item.count = item.count * args[1]
- end
- local tasks = stackUpME(allItems)
- if(tasks) then
- local done = false
- while(not done) do
- os.sleep(1)
- done = true
- for _, task in pairs(tasks) do
- if(not task.isFinished()) then
- done = false
- end
- end
- end
- exportFromME(allItems)
- end
Add Comment
Please, Sign In to add comment