Guest User

aspects

a guest
Sep 20th, 2015
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.00 KB | None | 0 0
  1. os.loadAPI("button")
  2. local essentia = {}
  3. local jars = peripheral.getNames()
  4. local m = peripheral.wrap("left")
  5. local ess = {}
  6. local essCount = {}
  7. local a = peripheral.find("tt_aspectanalyzer")
  8. local c = peripheral.find("iron")
  9. local rowsActive = true
  10. local monCoord = {}
  11. local currEssentia
  12. local fillAmt = 0
  13.  
  14. function findEss()
  15.     local tempess = {}
  16.     local notAuram
  17.     for i = 1,49 do
  18.         if c.getStackInSlot(i) then
  19.             c.pushItem("NORTH", i, 1,1)
  20.             tempess = a.getAspects()
  21.             if tempess[2] then
  22.                 if tempess[2] == "auram" then
  23.                     notAuram = tempess[1]
  24.                 else
  25.                     notAuram = tempess[2]
  26.                 end
  27.             else
  28.                 notAuram = tempess[1]
  29.             end
  30.             c.pullItem("NORTH", 1,1,i)
  31.             ess[notAuram] = i
  32.             essentia[notAuram] = 0
  33.             essCount[notAuram] = c.getStackInSlot(i)["qty"]
  34.         end
  35.     end
  36. --  print(ess["terra"])
  37. --  print(ess["fames"])
  38. --  print(ess["ignis"])
  39. --  print(essCount["terra"])
  40. --  print(essCount["fames"])
  41. --  print(essCount["arbor"])
  42. --  print(essCount["iter"])
  43. end
  44.  
  45. function scanEssentia()
  46.     for i,j in ipairs(jars) do
  47.         if peripheral.getType(j) == "tt_aspectContainer" then
  48.             asp = peripheral.call(j, "getAspects")
  49.             countasp = peripheral.call(j, "getAspectCount", asp[1])
  50.             if countasp > 0 then
  51.                 essentia[asp[1]] = math.floor(countasp)
  52. --              print(asp[1]..":"..countasp)
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58. function sortEss(t)
  59.    local keys = {}
  60.    for k in pairs(t) do keys[#keys+1] = k end
  61.    table.sort(keys)
  62.    
  63.    local i = 0
  64.    return function()
  65.       i = i+1
  66.       if keys[i] then
  67.          return keys[i], t[keys[i]]
  68.       end
  69.    end
  70. end
  71.  
  72. function printEssentia()
  73.   m.setTextColor(colors.white)
  74.   local x = 1
  75.   local y = 1
  76.   monCoord[x] = {}
  77. --  for a = 1,17 do
  78.   for i,j in sortEss(essentia) do
  79.      if j<=20 then m.setTextColor(colors.red) end
  80.      if j<40 and j>20 then m.setTextColor(colors.yellow) end
  81.      if j>=40 then m.setTextColor(colors.green) end
  82.      
  83.      m.setCursorPos(x,y)
  84.      m.write(i)
  85.      m.setCursorPos(x+14,y)
  86.      m.write(tostring(j))
  87. --     print(j)
  88.      monCoord[x][y] = i
  89.      if y < 17 then
  90.         y = y+1
  91.      else
  92.         y = 1
  93.         x = x+17
  94.         monCoord[x] = {}  
  95.      end
  96.   end
  97. -- end
  98.  m.setTextColor(colors.white)
  99. end
  100.  
  101. function getClick()
  102.     local timerCode = 0
  103.     timerCode = os.startTimer(15)
  104.     local event,side,x,y
  105.     repeat
  106.         event,side,x,y = os.pullEvent()
  107.         --print(event)
  108.     until side == timerCode or event=="monitor_touch"
  109.     if event=="monitor_touch" then
  110.         if button.checkxy(x,y) then
  111.             print("button")
  112.         else
  113.             if rowsActive then
  114.                 fillAmt = 0
  115.                 print(x..":"..x-(x%17)+1)
  116.                 print(monCoord[x-(x%17)+1][y])
  117.                 currEssentia = monCoord[x-(x%17)+1][y]
  118.                 if currEssentia ~= nil then
  119.                     if essentia[currEssentia] < 64 then
  120.                         fillTable2()
  121.                     else
  122.                         m.clear()
  123.                         button.label(1,10, currEssentia.." is already full.  Please choose another.")
  124.                         sleep(3)
  125.                         refresh()
  126.                     end
  127.                 end
  128.             end
  129.         end
  130.     else
  131.         refresh()
  132.    end
  133. end
  134.  
  135. function refresh()
  136.    button.flash("Refresh")
  137.    m.clear()
  138.    findEss()
  139.    scanEssentia()
  140.    printEssentia()
  141.    print("Refreshed")
  142.    button.screen()
  143. end
  144.  
  145. function fillTable()
  146.    rowsActive = true
  147.    button.clearTable()
  148.    button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
  149.    button.screen()
  150.    button.setTable("Refill All", refillAll, "", 39,52, 19,19)
  151. end
  152.  
  153. function refillAll()
  154.     for essName,essAmt in pairs(essentia) do
  155.         currEssentia = essName
  156.         print(currEssentia)
  157.         fillAmt = (64-essAmt)
  158.         if fillAmt > (essCount[currEssentia]-1)*2 then fillAmt = (essCount[currEssentia]-1)*2 end
  159.         fillEss2()
  160.     end
  161. end
  162.  
  163. function cancel()
  164.    m.clear()
  165.    fillTable()
  166.    refresh()
  167. end  
  168.  
  169. function addEss(num)
  170.    fillAmt = fillAmt + num
  171.    if fillAmt < 0 then fillAmt = 0 end
  172.    if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
  173.    if fillAmt > (essCount[currEssentia]-1)*2 then fillAmt = (essCount[currEssentia]-1)*2 end
  174.    m.clear()
  175.    fillTable2()
  176. end
  177.  
  178. function fillEss2()
  179.     c.pushItem("UP", ess[currEssentia], fillAmt/2)
  180.     m.clear()
  181.     fillTable()
  182.     refresh()
  183. end
  184.  
  185. function fillTable2()
  186.    rowsActive = false
  187.    button.clearTable()
  188.    m.clear()
  189.    button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
  190.    button.label(7, 2, "Available: "..currEssentia.." is: "..(essCount[currEssentia]-1)*2)
  191.    button.setTable("+2", addEss, 2, 8, 18, 6,6)
  192.    button.setTable("+6", addEss, 6, 20, 30, 6, 6)
  193.    button.setTable("+10", addEss, 10, 32, 42, 6, 6)
  194.    button.setTable("-2", addEss, -2, 8, 18, 8, 8)
  195.    button.setTable("-6", addEss, -6, 20, 30, 8, 8)
  196.    button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
  197.    button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
  198.    button.setTable("Execute Fill Request", fillEss2, "", 8, 42, 16, 18)
  199.    button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
  200.    button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
  201.    button.screen()
  202. end
  203.  
  204. fillTable()
  205. refresh()
  206. while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment