Advertisement
BombBloke

Essence Monitor (OpenPeripheral)

Aug 29th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.65 KB | None | 0 0
  1. -----------------------
  2. -- Essence Monitor
  3. -----------------------
  4.  
  5. -- By Jeffrey Alexander, aka Bomb Bloke.
  6.  
  7. -----------------------
  8. -- Important variables:
  9. -----------------------
  10.  
  11. local aspectNames = {"Aer","Alienis","Aqua","Arbor","Auram","Bestia","Cognitio","Corpus","Exanimis","Fabrico","Fames","Gelum",
  12.     "Granum","Herba","Humanus","Ignis","Instrumentum","Iter","Limus","Lucrum","Lux","Machina","Messis","Metallum","Meto",
  13.     "Mortuus","Motus","Ordo","Pannus","Perditio","Perfodio","Permutatio","Potentia","Praecantatio","Sano","Saxum","Sensus",
  14.     "Spiritus","Telum","Tempestas","Tenebrae","Terra","Tutamen","Vacuos","Venenum","Victus","Vinculum","Vitium","Vitreus","Volatus"}
  15.  
  16. local jar, unknownJars, countDown, mon, chest, furnace, xSize, ySize, myEvent, myTimer = {}, {}, 0
  17.  
  18. -----------------------
  19. -- Functions:
  20. -----------------------
  21.  
  22. local function drawTrimmings()
  23.     mon.setBackgroundColour(colours.grey)
  24.     mon.clear()
  25.    
  26.     mon.setTextColour(colours.black)
  27.     mon.setBackgroundColour(colours.black)
  28.     mon.setCursorPos(20,1)
  29.     mon.clearLine()
  30.     mon.setBackgroundColour(colours.lightGrey)
  31.     mon.write(" Essences ")
  32.    
  33.     for i=1,17 do for j=0,2 do
  34.         if i==17 and j==2 then break end
  35.         mon.setCursorPos(1+j*17,i+2)
  36.         mon.write(aspectNames[i+j*17])
  37.         mon.write(string.rep(" ",16-#aspectNames[i+j*17]))
  38.     end end
  39. end
  40.  
  41. -----------------------
  42. -- Init:
  43. -----------------------
  44.  
  45. do
  46.     local peripherals = peripheral.getNames()
  47.  
  48.     for i=1,#peripherals do if peripheral.getType(peripherals[i]) == "monitor" then
  49.         mon = peripheral.wrap(peripherals[i])
  50.         mon.side = peripherals[i]
  51.     elseif peripheral.getType(peripherals[i]) == "tilejar" then
  52.         local jarTemp = peripheral.wrap(peripherals[i])
  53.         local tempAspects = jarTemp.getAspects()
  54.         if tempAspects then jar[tempAspects[1].name] = jarTemp else unknownJars[#unknownJars+1] = jarTemp end
  55.     elseif peripheral.getType(peripherals[i]) == "gold" then
  56.         chest = peripheral.wrap(peripherals[i])
  57.     elseif peripheral.getType(peripherals[i]) == "container_alchemyfurnace" then
  58.         furnace = peripheral.wrap(peripherals[i])
  59.     end end
  60. end
  61.  
  62. xSize, ySize = mon.getSize()
  63. myTimer = os.startTimer(0)
  64.  
  65. drawTrimmings()
  66.  
  67. -----------------------
  68. -- Main Program:
  69. -----------------------
  70.  
  71. while true do
  72.     myEvent = {os.pullEvent()}
  73.    
  74.     if myEvent[1] == "timer" and myEvent[2] == myTimer then
  75.         mon.setTextColour(colours.black)
  76.         mon.setBackgroundColour(colours.grey)
  77.         mon.setCursorPos(35,19)
  78.        
  79.         if countDown > 0 then
  80.             countDown = countDown - 1
  81.             mon.write("Update in "..tostring(countDown).."s...            ")
  82.         else
  83.             mon.write("Updating...             ")
  84.                        
  85.             if unknownJars then
  86.                 for i=1,table.maxn(unknownJars) do if unknownJars[i] then
  87.                     local tempAspects = unknownJars[i].getAspects()
  88.  
  89.                     if tempAspects then
  90.                         jar[tempAspects[1].name] = unknownJars[i]
  91.                         unknownJars[i] = nil
  92.                     end
  93.                 end end
  94.  
  95.                 if table.maxn(unknownJars) == 0 then unknownJars = nil end
  96.             end
  97.            
  98.             local working, gap = false
  99.  
  100.             mon.setBackgroundColour(colours.white)
  101.             local counter = 1
  102.             for column = 14,49,17 do for row = 3,19 do
  103.                 mon.setCursorPos(column, row)
  104.                
  105.                 if jar[aspectNames[counter]] then
  106.                     local tempAspects = jar[aspectNames[counter]].getAspects()
  107.                    
  108.                     if tempAspects then
  109.                         local num = tostring(tempAspects[1].quantity)
  110.                         if #tempAspects > 1 then print("Oddity with "..aspectNames[counter]) end
  111.                         mon.write(string.rep(" ",2-#num)..num)
  112.                         gap = 64 - tempAspects[1].quantity
  113.                     else
  114.                         if unknownJars then
  115.                             unknownJars[#unknownJars+1] = aspectNames[counter]
  116.                         else unknownJars = {aspectNames[counter]} end
  117.                        
  118.                         jar[aspectNames[counter]] = nil
  119.                        
  120.                         mon.write("??")
  121.                         gap = 64
  122.                     end
  123.                 else
  124.                     mon.write("??")
  125.                     gap = 64
  126.                 end
  127.                
  128.                 gap = math.min(gap, chest.getStackInSlot(counter).qty - 1, 22)
  129.                 if gap > 0 and not working then
  130.                     chest.pushItemIntoSlot("south",counter,gap,1)
  131.                     working = true
  132.                 end
  133.                
  134.                 counter = counter + 1
  135.                 if counter == 51 then break end
  136.             end end
  137.            
  138.             --local missing = furnace.getStackInSlot(2)
  139.             --gap = math.min(chest.getStackInSlot(81).qty - 1, missing and (64-missing.qty) or 64)
  140.             --print("will try to move "..gap.." fuel")
  141.             --if gap > 0 then furnace.pullItemIntoSlot("north",81,gap,2) end
  142.            
  143.             countDown = 60
  144.         end
  145.        
  146.         myTimer = os.startTimer(1)
  147.        
  148.     elseif myEvent[1] == "monitor_resize" and myEvent[2] == mon.side then
  149.         xSize, ySize = mon.getSize()
  150.         drawTrimmings()
  151.         myTimer = os.startTimer(0)
  152.        
  153.     elseif myEvent[1] == "key" and (myEvent[2] == keys.q or myEvent[2] == keys.x) then
  154.         os.pullEvent("char")
  155.         error()
  156.        
  157.     end
  158. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement