Advertisement
lucifersamfr

essentia

Feb 12th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.64 KB | None | 0 0
  1. -- Config
  2. AspectList={  "aer",      "alienis",  "aqua",     "arbor",      "auram",    "bestia",       "cognitio",     "corpus", "exanimis",
  3.               "fabrico",  "fames",    "gelum",    "herba",      "humanus",  "ignis",        "instrumentum", "iter",   "limus",
  4.               "lucrum",   "lux",      "machina",  "messis",     "metallum", "meto",         "mortuus",      "motus",  "ordo",
  5.               "pannus",   "perditio", "perfodio", "permutatio", "potentia", "praecantatio", "sano",         "sensus", "spiritus",
  6.               "telum",    "tempestas","tempus",   "tenebrae",   "terra",    "tutamen",      "vacuos",       "venenum","victus",
  7.               "vinculum", "vitium",   "vitreus",  "volatus"}
  8.  
  9. local packetSize = 32
  10. local mSide = "back"
  11. local cSide = "top"
  12. local pushAnalyzerDir = "WEST"
  13. local pullanalyzerDir = "EAST"
  14. local pushOutDir = "NORTH"
  15. local burnerBusySide = "right"
  16.  
  17. --Generic functions
  18. function getAnalyzerName()
  19.   for i,j in ipairs(peripheral.getNames()) do
  20.     peripheralType=peripheral.getType(j)
  21.     if peripheralType=="tt_aspectanalyzer" then
  22.       return j
  23.     end
  24.   end
  25.   return nil
  26. end
  27. function printItemSlot(slot)
  28.   if slot.display_name ~= nil then  print("display_name : "..slot.display_name) end
  29.   if slot.qty ~= nil then           print("qty          : "..slot.qty) end
  30.   if slot.max_size ~= nil then      print("max_size     : "..slot.max_size) end
  31.   if slot.max_dmg ~= nil then       print("max_dmg      : "..slot.max_dmg) end
  32.   if slot.raw_name ~= nil then      print("raw_name     : "..slot.raw_name) end
  33.   if slot.dmg ~= nil then           print("dmg          : "..slot.dmg) end
  34.   if slot.id ~= nil then            print("id           : "..slot.id) end
  35.   if slot.name ~= nil then          print("name         : "..slot.name) end
  36.   if slot.mod_id ~= nil then        print("mod_id       : "..slot.mod_id) end
  37. end
  38.  
  39. --init
  40. local orders={}
  41. local essentiaJars={}
  42. local modem = peripheral.wrap(mSide)
  43. local chest = peripheral.wrap(cSide)
  44. local maxAspectLen=0
  45. local curAspectLen=0
  46. local analyzerName = getAnalyzerName()
  47.  
  48. function containsAspect(slot,aspectName)
  49.   chest.pushItemIntoSlot(pushAnalyzerDir,slot,1)
  50.   --print(analyzer.listMethods())
  51.   local amount = peripheral.call(analyzerName,"getAspectCount")[aspectName]
  52.   chest.pullItem(pushAnalyzerDir,1,1,slot)
  53.   if amount == nil then
  54.     return 0
  55.   else
  56.     return amount
  57.   end
  58. end
  59.  
  60. function ordersF(aspectName)
  61.   local needed = orders[aspectName]
  62.   if needed == nil then
  63.     return 0
  64.   else
  65.     return needed
  66.   end
  67. end
  68.  
  69. function printOrders()
  70.   print("ORDERS : ---------------------")
  71.   for i,j in pairs(orders) do
  72.     if j > 0 then
  73.       print(i.." : "..j)
  74.     end
  75.   end
  76.   print("------------------------------")
  77. end
  78.  
  79. --function missingJars()
  80. --  for i=1,#AspectList do
  81. --
  82. --  end
  83. --end
  84.  
  85. --function registerJar(aspectName)
  86. --  if essentiaJars[aspectName] == nil then
  87. --    essentiaJars[aspectName] = 1
  88. --  else
  89. --    essentiaJars[aspectName] = essentiaJars[aspectName] + 1
  90. --  end
  91. --end
  92.  
  93. function nbJars(aspectName)
  94.   local count = 0
  95.   for i,j in pairs(essentiaJars) do
  96.     if i == string.lower(aspectName) then
  97.       count = count + 1
  98.     end
  99.   end
  100.   return count
  101. end
  102.  
  103. function missingEssentiaJar()
  104.   local missingJars = {}
  105.   local count  = 0
  106.   for i=1,#AspectList do
  107.     local aspect = AspectList[i]
  108.     if nbJars(aspect) < 1 then
  109.       count = count + 1
  110.       missingJars[count] = aspect
  111.     end
  112.   end
  113.   return missingJars
  114. end
  115.  
  116. function printMissingJars()
  117.   local missings = missingEssentiaJar()
  118.   if #missings > 0 then
  119.     print("WARNING : those aspects have no dedicated jars!")
  120.     for i=1,#missings do
  121.       print("  "..missings[i])
  122.     end
  123.   end
  124. end
  125.  
  126. function refreshOrders()
  127.   orders={}         -- reinit Array (clear)
  128.   essentiaJars={}   -- reinit Array (clear)
  129.   for i,j in ipairs(peripheral.getNames()) do
  130.     peripheralType=peripheral.getType(j)
  131.     if peripheralType=="tileessentiacontainer" or
  132.       peripheralType=="tt_aspectContainer" or
  133.       peripheralType=="tilejar" or
  134.       peripheralType=="tilecreativejar" or
  135.       peripheralType=="tilejarvoid" then
  136.       -- Try to get Methods
  137.       Aspects=peripheral.call(j,"getAspects")[1]
  138.       if Aspects==nil then     --empty jar
  139.         AspectName="empty"
  140.         AspectAmount =0
  141.       else                            --filled jar
  142.         if peripheralType=="tt_aspectContainer" then
  143.           AspectName=Aspects
  144.           AspectAmount = peripheral.call(j, "getAspectCount", Aspects)
  145.           orders[AspectName]=ordersF(AspectName) + 64-AspectAmount
  146.           essentiaJars[AspectName]=j
  147.         else
  148.           --AspectName=Aspects["name"] or "empty"
  149.           --AspectAmount=Aspects["quantity"] or 0
  150.           --addvalue(AspectName,AspectAmount)
  151.           --print("type: other")
  152.         end  
  153.         --print(AspectName)
  154.       end
  155.     else
  156.       --print("JAR NOT FOUND :".. i.."/"..j.."/"..peripheralType)
  157.     end
  158.     --print("-----------------------------------------")
  159.   end
  160.   printOrders()
  161. end
  162.  
  163. function pushOut(slot,amount)
  164.   return chest.pushItem(pushOutDir,slot,amount)
  165. end
  166.  
  167. function waitForBurner()
  168.   local hasWork = false
  169.   sleep(2)
  170.   --WAIT for the burner
  171.   while rs.getInput(burnerBusySide) do
  172.     if not hasWork then
  173.       hasWork = true
  174.     end
  175.     print("waiting for the burner...")
  176.     sleep(5)
  177.   end
  178.   if hasWork then
  179.     print("Waiting 30 seconds for alembics to be emptied...")
  180.     sleep(90)
  181.   end
  182. end
  183.  
  184. --## Mainfunction ##--
  185. orders={}       -- Initialize Array (clear)
  186. --filltable() -- Initailize Array (Names and Value=0)
  187.  
  188. while true do
  189.   refreshOrders()
  190.   printMissingJars()
  191.   local as = chest.getAllStacks()
  192.   for slot=1,#as do --for each slot in the chest
  193.     if as[slot].display_name == "Crystallized Essence" then
  194.       for aspectName,value in pairs(orders) do --for each aspect we need to burn (orders)
  195.         if value > 0 then
  196.           if containsAspect(slot,aspectName) > 0 then
  197.             term.setTextColor(colors.red)
  198.             print(string.upper(aspectName).." in slot "..slot..". expected : "..value..".")
  199.            
  200.             --PUSH crystallized essence to the burner
  201.             local pushed = 0
  202.             if value > packetSize then
  203.               pushed = pushOut(slot,packetSize)
  204.             else
  205.               pushed = pushOut(slot,value)
  206.             end
  207.             term.setTextColor(colors.green)
  208.             print(pushed.." "..aspectName.." crystallized essence pushed.")
  209.             term.setTextColor(colors.white)
  210.             orders[aspectName] = orders[aspectName] - pushed
  211.            
  212.           end
  213.         end
  214.       end
  215.     end
  216.   end
  217.  
  218.   waitForBurner()
  219. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement