Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local meController = component.proxy(component.me_controller.address)
- local gpu = component.gpu
- -- Each element of the array is "item", "damage", "number wanted", "max craft size"
- -- Damage value should be zero for base items
- maxProcessors = 2
- retVals = {}
- items = {
- { "harvestcraft:delightedmealitem", 0, 64, 8 },
- { "minecraft:ender_pearl", 0, 256, 64 },
- { "wct:infinity_booster_card", 0, 64, 8 },
- { "appliedenergistics2:material", 24, 64, 16 },
- { "appliedenergistics2:material", 23, 64, 16 },
- { "appliedenergistics2:material", 22, 64, 16 },
- { "appliedenergistics2:material", 12, 64, 16 },
- { "appliedenergistics2:material", 10, 128, 32 },
- { "appliedenergistics2:material", 7, 128, 32 },
- { "appliedenergistics2:material", 2, 128, 32 },
- { "appliedenergistics2:material", 1, 256, 64 },
- { "appliedenergistics2:material", 0, 512, 64 },
- { "enderio:item_alloy_ingot", 1, 32, 8 },
- { "minecraft:torch", 0, 128, 32 },
- { "thermaldynamics:duct_0", 3, 64, 16 },
- { "thermalfoundation:material", 160, 128, 16 },
- { "thermalfoundation:material", 163, 256, 16 },
- { "minecraft:clay_ball", 0, 512, 128 },
- { "minecraft:redstone_torch", 0, 64, 16 },
- { "minecraft:glowstone_dust", 0, 512, 64 },
- { "minecraft:obsidian", 0, 512, 64 },
- { "minecraft:diamond", 0, 512, 64 },
- { "minecraft:emerald", 0, 512, 64 },
- { "ic2:ingot", 8, 128, 64 },
- { "enderio:item_alloy_ingot", 2, 64, 4 },
- { "minecraft:stick", 0, 512, 64 },
- }
- loopDelay = 10 -- Seconds between runs
- usedProcessors = 0
- indexesRetVal = 0
- while true do
- for curIdx = 1, #items do
- curName = items[curIdx][1]
- curDamage = items[curIdx][2]
- curMinValue = items[curIdx][3]
- curMaxRequest = items[curIdx][4]
- while usedProcessors == maxProcessors do
- for intRetVals = 1, #retVals do
- pcall(function()
- if retVals[intRetVals].isDone() or retVals[intRetVals].isCanceled() then
- usedProcessors = usedProcessors - 1
- table.remove(retVals, intRetVals)
- end
- end)
- -- io.write("CurRetVal" .. intRetVals .. "\n")
- end
- -- io.write("Max Processors reached\n")
- os.sleep(1)
- end
- -- io.write("Checking for " .. curMinValue .. " of " .. curName .. "\n")
- storedItem = meController.getItemsInNetwork({
- name = curName,
- damage = curDamage
- })
- io.write("Network contains ")
- gpu.setForeground(0xCC24C0) -- Purple-ish
- io.write(storedItem[1].size)
- gpu.setForeground(0xFFFFFF) -- White
- io.write(" items with label ")
- gpu.setForeground(0x00FF00) -- Green
- io.write(storedItem[1].label .. "\n")
- gpu.setForeground(0xFFFFFF) -- White
- if storedItem[1].size < curMinValue then
- delta = curMinValue - storedItem[1].size
- craftAmount = delta
- if delta > curMaxRequest then
- craftAmount = curMaxRequest
- end
- io.write(" Need to craft ")
- gpu.setForeground(0xFF0000) -- Red
- io.write(delta)
- gpu.setForeground(0xFFFFFF) -- White
- io.write(", requesting ")
- gpu.setForeground(0xCC24C0) -- Purple-ish
- io.write(craftAmount .. "... ")
- gpu.setForeground(0xFFFFFF) -- White
- craftables = meController.getCraftables({
- name = curName,
- damage = curDamage
- })
- numberCpus = meController.getCpus()
- freeCpu = false
- for indexCpu = 1, #numberCpus do
- freeCpu = freeCpu or not numberCpus[indexCpu].busy
- end
- if craftables.n >= 1 then
- cItem = craftables[1]
- -- io.write("0\n")
- if freeCpu and usedProcessors < maxProcessors then
- -- io.write("1\n")
- -- indexProcessor = usedProcessors + 1
- ret = cItem.request(craftAmount)
- -- table.insert(retVals, ret)
- if ret.isCanceled() then
- gpu.setForeground(0xFF0000) -- Red
- io.write("Fail. Needed Materials not in the System\n")
- else
- table.insert(retVals, ret)
- usedProcessors = usedProcessors + 1
- -- io.write("2\n")
- gpu.setForeground(0x00FF00) -- Green
- io.write("OK\n")
- end
- -- indexesRetVal = indexesRetVal + 1
- else
- gpu.setForeground(0xFF0000) -- Red
- io.write("Fail. No Free CPU available or max used CPUs reached.\n")
- end
- gpu.setForeground(0xFFFFFF) -- White
- else
- gpu.setForeground(0xFF0000) -- Red
- io.write(" Unable to locate craftable for " .. storedItem[1].name .. "\n")
- gpu.setForeground(0xFFFFFF) -- White
- end
- end
- end
- intRetValNumber = #retVals
- intRetValDone = 0
- while intRetValDone < intRetValNumber do
- for i = 1, #retVals do
- if retVals[i].isDone() or retVals[i].isCanceled() then intRetValDone = intRetValDone + 1 end
- end
- if intRetValDone < intRetValNumber then intRetValDone = 0 end
- os.sleep(1)
- end
- indexRetVal = 0
- io.write("Sleeping for " .. loopDelay .. " seconds...\n\n")
- os.sleep(loopDelay)
- term.clear()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement