SHOW:
|
|
- or go back to the newest paste.
| 1 | local trashListChest = peripheral.wrap("back")
| |
| 2 | local aeNetwork = peripheral.wrap("right")
| |
| 3 | local craftListChest = peripheral.wrap("top")
| |
| 4 | local alwaysCraftListChest = peripheral.wrap("left")
| |
| 5 | - | local loopCounter = 0 |
| 5 | + | local loopCounter = 3601 |
| 6 | - | local delayCrafting = {}
|
| 6 | + | |
| 7 | function processTrash () | |
| 8 | if unexpected_condition then error() end | |
| 9 | - | for i,data in pairs(craftListChest.getAllStacks()) do |
| 9 | + | trash_list = {}
|
| 10 | - | if delayCrafting[tostring(data["id"]..data["dmg"])] ~= nil then |
| 10 | + | for i,data in pairs(trashListChest.getAllStacks(false)) do |
| 11 | - | delayCrafting[tostring(data["id"]..data["dmg"])] = delayCrafting[tostring(data["id"]..data["dmg"])] - 1 |
| 11 | + | data_stack = {["id"] = data.id, ["dmg"] = data.dmg}
|
| 12 | - | if delayCrafting[tostring(data["id"]..data["dmg"])] < 0 then |
| 12 | + | network_item = aeNetwork.getItemDetail(data_stack, false) |
| 13 | - | delayCrafting[tostring(data["id"]..data["dmg"])] = nil |
| 13 | + | if network_item ~= nil and data_stack ~= nil and data ~= nil then |
| 14 | while network_item.qty > ( data.qty * 1000 ) do | |
| 15 | if trash_list[data.display_name] == nil then | |
| 16 | - | if data["maxSize"] == 1 then |
| 16 | + | trash_list[data.display_name] = aeNetwork.exportItem(data_stack, "up", math.min(network_item.qty - ( data.qty * 1000 ), data.max_size)).size |
| 17 | - | data["maxSize"] = 5 |
| 17 | + | |
| 18 | trash_list[data.display_name] = trash_list[data.display_name] + aeNetwork.exportItem(data_stack, "up", math.min(network_item.qty - ( data.qty * 1000 ), data.max_size)).size | |
| 19 | - | if ( ( data["qty"] * data["maxSize"] ) - aeNetwork.countOfItemType(data["id"], data["dmg"]) ) > 0 then |
| 19 | + | |
| 20 | - | print("Crafting:"..data["maxSize"].." x "..data["id"])
|
| 20 | + | |
| 21 | - | aeNetwork.requestCrafting({ ["id"] = data["id"], ["dmg"] = data["dmg"], ["qty"] = ( ( data["qty"] * data["maxSize"] ) - aeNetwork.countOfItemType(data["id"], data["dmg"]) ) })
|
| 21 | + | network_item = aeNetwork.getItemDetail(data_stack, false) |
| 22 | if ( network_item == nil ) then | |
| 23 | break | |
| 24 | - | if data["id"] > 400 then |
| 24 | + | |
| 25 | - | delayCrafting[tostring(data["id"]..data["dmg"])] = 300 |
| 25 | + | |
| 26 | - | print("Delaying future crafting due to complexity")
|
| 26 | + | |
| 27 | end | |
| 28 | if trash_list ~= nil then | |
| 29 | print("Cleaned out:")
| |
| 30 | for name,i in pairs(trash_list) do | |
| 31 | - | loopCounter = loopCounter + 1 |
| 31 | + | |
| 32 | - | if loopCounter > 30 then |
| 32 | + | |
| 33 | - | trashList = {}
|
| 33 | + | |
| 34 | - | for i,data in pairs(trashListChest.getAllStacks()) do |
| 34 | + | end |
| 35 | - | while aeNetwork.countOfItemType(data["id"], data["dmg"]) > ( data["qty"] * 1000 ) do |
| 35 | + | |
| 36 | - | print("trying to delete item:"..data["name"])
|
| 36 | + | function processCrafting () |
| 37 | - | local status, outputData = pcall( function () return aeNetwork.extractItem({ ["id"] = data["id"], ["dmg"] = data["dmg"], ["qty"] = math.min(aeNetwork.countOfItemType(data["id"], data["dmg"]) - ( data["qty"] * 1000 ), data["maxSize"]) }, "up") end )
|
| 37 | + | if unexpected_condition then error() end |
| 38 | - | if not status then |
| 38 | + | for i,data in pairs(craftListChest.getAllStacks(false)) do |
| 39 | - | print("Error")
|
| 39 | + | data_stack = {["id"] = data.id, ["dmg"] = data.dmg}
|
| 40 | network_item = aeNetwork.getItemDetail(data_stack, false) | |
| 41 | if network_item ~= nil and data_stack ~= nil and data ~= nil then | |
| 42 | - | if trashList[data["name"]] == nil then |
| 42 | + | if data["max_size"] == 1 then |
| 43 | - | trashList[data["name"]] = outputData |
| 43 | + | data["max_size"] = 5 |
| 44 | end | |
| 45 | - | trashList[data["name"]] = trashList[data["name"]] + outputData |
| 45 | + | if ( ( data.qty * data.max_size ) - network_item.qty ) > 0 then |
| 46 | print("Crafting:"..((data.qty * data.max_size) - network_item.qty ).." x "..data.display_name)
| |
| 47 | - | print("success")
|
| 47 | + | aeNetwork.requestCrafting(network_item, ( data.qty * data.max_size ) - network_item.qty) |
| 48 | sleep(1) | |
| 49 | loopCounter = loopCounter + 1 | |
| 50 | end | |
| 51 | end | |
| 52 | - | for name,i in pairs(trashList) do |
| 52 | + | |
| 53 | end | |
| 54 | ||
| 55 | - | loopCounter = 0 |
| 55 | + | function processAlwaysCraft () |
| 56 | if unexpected_condition then error() end | |
| 57 | - | print("sleep then loop")
|
| 57 | + | for i,data in pairs(alwaysCraftListChest.getAllStacks(false)) do |
| 58 | - | sleep(1) |
| 58 | + | data_stack = {["id"] = data.id, ["dmg"] = data.dmg}
|
| 59 | network_item = aeNetwork.getItemDetail(data_stack, false) | |
| 60 | if network_item ~= nil and data_stack ~= nil and data ~= nil then | |
| 61 | print("Crafting:"..data.qty.." x "..data.display_name)
| |
| 62 | aeNetwork.requestCrafting(network_item, ( data.qty ) ) | |
| 63 | sleep(1) | |
| 64 | loopCounter = loopCounter + 1 | |
| 65 | end | |
| 66 | end | |
| 67 | end | |
| 68 | ||
| 69 | while true do | |
| 70 | if pcall(processTrash) then | |
| 71 | sleep(30) | |
| 72 | loopCounter = loopCounter + 30 | |
| 73 | else | |
| 74 | print("Error trashing, trying to run again...")
| |
| 75 | sleep(1) | |
| 76 | loopCounter = loopCounter + 1 | |
| 77 | end | |
| 78 | if loopCounter >= 3600 then | |
| 79 | if pcall(processCrafting) then | |
| 80 | loopCounter = 0 | |
| 81 | else | |
| 82 | print("Error crafting, trying to run again...")
| |
| 83 | end | |
| 84 | end | |
| 85 | if pcall(processAlwaysCraft) then | |
| 86 | else | |
| 87 | print("Error crafting, trying to run again...")
| |
| 88 | end | |
| 89 | end |