Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Config
- AspectList={ "aer", "alienis", "aqua", "arbor", "auram", "bestia", "cognitio", "corpus", "exanimis",
- "fabrico", "fames", "gelum", "herba", "humanus", "ignis", "instrumentum", "iter", "limus",
- "lucrum", "lux", "machina", "messis", "metallum", "meto", "mortuus", "motus", "ordo",
- "pannus", "perditio", "perfodio", "permutatio", "potentia", "praecantatio", "sano", "sensus", "spiritus",
- "telum", "tempestas","tempus", "tenebrae", "terra", "tutamen", "vacuos", "venenum","victus",
- "vinculum", "vitium", "vitreus", "volatus"}
- local packetSize = 32
- local mSide = "back"
- local cSide = "top"
- local pushAnalyzerDir = "WEST"
- local pullanalyzerDir = "EAST"
- local pushOutDir = "NORTH"
- local burnerBusySide = "right"
- --Generic functions
- function getAnalyzerName()
- for i,j in ipairs(peripheral.getNames()) do
- peripheralType=peripheral.getType(j)
- if peripheralType=="tt_aspectanalyzer" then
- return j
- end
- end
- return nil
- end
- function printItemSlot(slot)
- if slot.display_name ~= nil then print("display_name : "..slot.display_name) end
- if slot.qty ~= nil then print("qty : "..slot.qty) end
- if slot.max_size ~= nil then print("max_size : "..slot.max_size) end
- if slot.max_dmg ~= nil then print("max_dmg : "..slot.max_dmg) end
- if slot.raw_name ~= nil then print("raw_name : "..slot.raw_name) end
- if slot.dmg ~= nil then print("dmg : "..slot.dmg) end
- if slot.id ~= nil then print("id : "..slot.id) end
- if slot.name ~= nil then print("name : "..slot.name) end
- if slot.mod_id ~= nil then print("mod_id : "..slot.mod_id) end
- end
- --init
- local orders={}
- local essentiaJars={}
- local modem = peripheral.wrap(mSide)
- local chest = peripheral.wrap(cSide)
- local maxAspectLen=0
- local curAspectLen=0
- local analyzerName = getAnalyzerName()
- function containsAspect(slot,aspectName)
- chest.pushItemIntoSlot(pushAnalyzerDir,slot,1)
- --print(analyzer.listMethods())
- local amount = peripheral.call(analyzerName,"getAspectCount")[aspectName]
- chest.pullItem(pushAnalyzerDir,1,1,slot)
- if amount == nil then
- return 0
- else
- return amount
- end
- end
- function ordersF(aspectName)
- local needed = orders[aspectName]
- if needed == nil then
- return 0
- else
- return needed
- end
- end
- function printOrders()
- print("ORDERS : ---------------------")
- for i,j in pairs(orders) do
- if j > 0 then
- print(i.." : "..j)
- end
- end
- print("------------------------------")
- end
- --function missingJars()
- -- for i=1,#AspectList do
- --
- -- end
- --end
- --function registerJar(aspectName)
- -- if essentiaJars[aspectName] == nil then
- -- essentiaJars[aspectName] = 1
- -- else
- -- essentiaJars[aspectName] = essentiaJars[aspectName] + 1
- -- end
- --end
- function nbJars(aspectName)
- local count = 0
- for i,j in pairs(essentiaJars) do
- if i == string.lower(aspectName) then
- count = count + 1
- end
- end
- return count
- end
- function missingEssentiaJar()
- local missingJars = {}
- local count = 0
- for i=1,#AspectList do
- local aspect = AspectList[i]
- if nbJars(aspect) < 1 then
- count = count + 1
- missingJars[count] = aspect
- end
- end
- return missingJars
- end
- function printMissingJars()
- local missings = missingEssentiaJar()
- if #missings > 0 then
- print("WARNING : those aspects have no dedicated jars!")
- for i=1,#missings do
- print(" "..missings[i])
- end
- end
- end
- function refreshOrders()
- orders={} -- reinit Array (clear)
- essentiaJars={} -- reinit Array (clear)
- for i,j in ipairs(peripheral.getNames()) do
- peripheralType=peripheral.getType(j)
- if peripheralType=="tileessentiacontainer" or
- peripheralType=="tt_aspectContainer" or
- peripheralType=="tilejar" or
- peripheralType=="tilecreativejar" or
- peripheralType=="tilejarvoid" then
- -- Try to get Methods
- Aspects=peripheral.call(j,"getAspects")[1]
- if Aspects==nil then --empty jar
- AspectName="empty"
- AspectAmount =0
- else --filled jar
- if peripheralType=="tt_aspectContainer" then
- AspectName=Aspects
- AspectAmount = peripheral.call(j, "getAspectCount", Aspects)
- orders[AspectName]=ordersF(AspectName) + 64-AspectAmount
- essentiaJars[AspectName]=j
- else
- --AspectName=Aspects["name"] or "empty"
- --AspectAmount=Aspects["quantity"] or 0
- --addvalue(AspectName,AspectAmount)
- --print("type: other")
- end
- --print(AspectName)
- end
- else
- --print("JAR NOT FOUND :".. i.."/"..j.."/"..peripheralType)
- end
- --print("-----------------------------------------")
- end
- printOrders()
- end
- function pushOut(slot,amount)
- return chest.pushItem(pushOutDir,slot,amount)
- end
- function waitForBurner()
- local hasWork = false
- sleep(2)
- --WAIT for the burner
- while rs.getInput(burnerBusySide) do
- if not hasWork then
- hasWork = true
- end
- print("waiting for the burner...")
- sleep(5)
- end
- if hasWork then
- print("Waiting 30 seconds for alembics to be emptied...")
- sleep(90)
- end
- end
- --## Mainfunction ##--
- orders={} -- Initialize Array (clear)
- --filltable() -- Initailize Array (Names and Value=0)
- while true do
- refreshOrders()
- printMissingJars()
- local as = chest.getAllStacks()
- for slot=1,#as do --for each slot in the chest
- if as[slot].display_name == "Crystallized Essence" then
- for aspectName,value in pairs(orders) do --for each aspect we need to burn (orders)
- if value > 0 then
- if containsAspect(slot,aspectName) > 0 then
- term.setTextColor(colors.red)
- print(string.upper(aspectName).." in slot "..slot..". expected : "..value..".")
- --PUSH crystallized essence to the burner
- local pushed = 0
- if value > packetSize then
- pushed = pushOut(slot,packetSize)
- else
- pushed = pushOut(slot,value)
- end
- term.setTextColor(colors.green)
- print(pushed.." "..aspectName.." crystallized essence pushed.")
- term.setTextColor(colors.white)
- orders[aspectName] = orders[aspectName] - pushed
- end
- end
- end
- end
- end
- waitForBurner()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement