Advertisement
rhn

Essentia1.5+

rhn
Oct 30th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.30 KB | None | 0 0
  1. local essentia = {}
  2. local jars = peripheral.getNames()
  3. local m = peripheral.wrap("top")
  4. local monCoord = {}
  5. local currEssentia
  6. local fillAmt = 0
  7. local rowsActive = true
  8. local emptyjars = 0
  9.  
  10. function sortEss(t)
  11.    local keys = {}
  12.    for k in pairs(t) do keys[#keys+1] = k end
  13.    table.sort(keys)
  14.    
  15.    local i = 0
  16.    return function()
  17.       i = i+1
  18.       if keys[i] then
  19.          return keys[i], t[keys[i]]
  20.       end
  21.    end
  22. end
  23.  
  24. function scanEssentia()
  25.   for i,j in ipairs(jars) do
  26.      if peripheral.getType(j) == "tilejar" then
  27.        asp = peripheral.call(j, "getAspects")
  28.     --print(asp[1])
  29.     if asp[1] then
  30.             countasp = asp[1]["quantity"]
  31.             nameasp = asp[1]["name"]
  32.             if countasp > 0 then
  33.             if essentia[string.lower(nameasp)] then
  34.                     essentia[string.lower(nameasp)] = essentia[string.lower(nameasp)] + math.floor(countasp)
  35.             else
  36.                 essentia[string.lower(nameasp)] = math.floor(countasp)
  37.             end
  38.             end
  39. --      print(countasp)
  40.     print(nameasp..":"..countasp)
  41.     else
  42.         emptyjars= emptyjars+1
  43.     end
  44.  
  45. --     print(peripheral.getType(j))
  46.      end
  47.   end
  48. end
  49.  
  50. function printEssentia()
  51.     m.clear()                      
  52.     m.setCursorPos(1,1)
  53.   m.setTextColor(colors.white)
  54.   local x = 1
  55.   local y = 1
  56.   monCoord[x] = {}
  57.   for i,j in sortEss(essentia) do
  58.      if j<=20 then m.setTextColor(colors.red) end
  59.      if j<40 and j>20 then m.setTextColor(colors.yellow) end
  60.      if j>=40 then m.setTextColor(colors.green) end
  61.      
  62.      m.setCursorPos(x,y)
  63.      m.write(i)
  64.      m.setCursorPos(x+13,y)
  65.      m.write(tostring(j))
  66. --     print(j)
  67.      monCoord[x][y] = i
  68.      if y < 20 then
  69.         y = y+1
  70.      else
  71.         y = 1
  72.         x = x+17
  73.         monCoord[x] = {}  
  74.      end
  75.    end
  76.  
  77. --emptyjars print
  78.      if emptyjars<=5 then m.setTextColor(colors.red) end
  79.      if emptyjars<10 and emptyjars>5 then m.setTextColor(colors.yellow) end
  80.      if emptyjars>=10 then m.setTextColor(colors.green) end
  81. m.setCursorPos(18,23)
  82. m.write("Empty Warded Jars: "..emptyjars)
  83.  m.setTextColor(colors.white)
  84.  
  85. end
  86.  
  87.  
  88.  
  89. while true do
  90.     emptyjars=0
  91.     local k = next(essentia)
  92.     while k do
  93.         essentia[k] = nil
  94.         k = next(essentia)
  95.     end
  96.     scanEssentia()
  97.     print("Scanning essentia complete")
  98.     printEssentia()
  99.     print("Printing essentia complete")
  100.     sleep(1)
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement