Miner8149

EssentiaList - Final

Jun 23rd, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.00 KB | None | 0 0
  1. --Prints Essentia, and ammounts
  2. --Miner8149
  3.  
  4. local essentia = {}
  5. local connected = peripheral.getNames()
  6. local m = peripheral.wrap("top")
  7. m.setTextScale(0.5)
  8. local xMax, yMax = m.getSize()
  9. local xMon, yMon
  10. local monCoord = {}
  11. local currEssentia
  12. local redLevel = 5000
  13. local grnLevel = 100000
  14. local colLength = 28
  15.  
  16. --***********************
  17. function sortEss(t)
  18.    local keys = {}
  19.    for k in pairs(t) do keys[#keys+1] = k end
  20.    table.sort(keys)
  21.  
  22.    local i = 0
  23.    return function()
  24.           i = i+1
  25.           if keys[i] then
  26.                  return keys[i], t[keys[i]]
  27.           end
  28.    end
  29. end
  30. --***********************
  31. function getScreenSize()
  32.     xMax, yMax = m.getSize()
  33.     if(xMax == 15) then xMon = 1 end
  34.     if(xMax == 36) then xMon = 2 end
  35.     if(xMax == 57) then xMon = 3 end
  36.     if(xMax == 79) then xMon = 4 end
  37.    
  38.     if(yMax == 10) then yMon = 1 end
  39.     if(yMax == 24) then yMon = 2 end
  40.     if(yMax == 38) then yMon = 3 end
  41.     if(yMax == 52) then yMon = 4 end
  42.     print(string.format("Screen Size %dx%d", xMon, yMon))
  43. end
  44. --***********************
  45. function scanEssentia()
  46.     essentia = {}
  47.     for i,j in ipairs(connected) do
  48.         if peripheral.getType(j) == "EssentiaProvider" then
  49.             aspectList = {peripheral.call(j, "getAspects")}          --# Take all results, stick them in a table.
  50.             --if #aspectList == 1 then  --# This may be needed for regular jars?
  51.             --  countasp = peripheral.call(j, "getAmount", aspectList[1])
  52.             --    if countasp > 0 then
  53.             --      essentia[aspectList[1]] = math.floor(countasp)
  54.             --    end
  55.             --else  --# As for your provider block thingy:
  56.                 for k = 0, #aspectList / 2 - 1 do
  57.                     essentia[aspectList[k*2+1]] = aspectList[k*2+2]
  58.                 end
  59.             --end
  60.         end
  61.     end
  62. end
  63. --***********************
  64. function printEssentia()
  65.     m.setTextColor(colors.white)
  66.     local x = 1
  67.     local y = 1
  68.     for i,j in sortEss(essentia) do
  69.         if j<=redLevel then m.setTextColor(colors.red) end
  70.         if j<grnLevel and j>redLevel then m.setTextColor(colors.yellow) end
  71.         if j>=grnLevel then m.setTextColor(colors.green) end
  72.             m.setCursorPos(x,y)
  73.             m.write(i)
  74.             m.setCursorPos(x+13,y)
  75.             printNum(j)
  76.            
  77.             if y < colLength then
  78.                 y = y+1
  79.             else
  80.                 y = 1
  81.                 x = x+19
  82.             end
  83.     end
  84. m.setTextColor(colors.white)
  85. end
  86. --***********************
  87. function printNum(number)
  88.     local newNum = 0
  89.     if number < 9999 then
  90.         m.write(tostring(number))
  91.     elseif number >= 9999 and number < 1000000 then
  92.         newNum = number/1000
  93.         m.write(string.format("%dK", newNum))
  94.     elseif number >= 1000000 and number < 1000000000 then
  95.         newNum = number/1000000
  96.         m.write(string.format("%dM", newNum))
  97.     else
  98.         m.write("LOTS")
  99.     end
  100. end
  101. --***********************
  102. function refresh()
  103.    m.clear()
  104.    getScreenSize()
  105.    scanEssentia()
  106.    printEssentia()
  107.    print("Refreshed")
  108.    sleep(5)
  109. end
  110.  
  111.  
  112.  
  113. refresh()
  114. while (true) do refresh() end
Add Comment
Please, Sign In to add comment