Guest User

aspects

a guest
Jun 12th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.01 KB | None | 0 0
  1. os.loadAPI("button")
  2. local essentia = {}
  3. local jars = peripheral.getNames()
  4. local m = peripheral.wrap("monitor_0")
  5. local monCoord = {}
  6. local currEssentia
  7. local fillAmt = 0
  8. local rowsActive = true
  9. local pipe = peripheral.wrap("LogisticsPipes:Request_0")
  10. local beans = {}
  11.  
  12. function findBeans()
  13.    data = pipe.getAvailableItems()
  14.    for i,j in pairs(data) do
  15.       data2 = pipe.getNBTTagCompound(j[1])
  16.       beans[data2["value"]["Aspects"]["value"][1]["value"]["key"]["value"]] = i
  17.    end
  18. end
  19.  
  20. function sortEss(t)
  21.    local keys = {}
  22.    for k in pairs(t) do keys[#keys+1] = k end
  23.    table.sort(keys)
  24.    
  25.    local i = 0
  26.    return function()
  27.       i = i+1
  28.       if keys[i] then
  29.          return keys[i], t[keys[i]]
  30.       end
  31.    end
  32. end
  33.  
  34. function scanEssentia()
  35.   for i,j in ipairs(jars) do
  36.      if peripheral.getType(j) == "tilejar" then
  37.        asp = peripheral.call(j, "getAspects")[1]
  38.        aspName = asp["name"]
  39.        countasp = asp["quantity"]
  40.        print(aspName)
  41.        print(countasp)
  42.        if countasp > 0 then
  43.          essentia[asp] = math.floor(countasp)
  44.        end
  45.      end
  46.   end
  47. end
  48.  
  49. function printEssentia()
  50.   m.setTextColor(colors.white)
  51.   local x = 1
  52.   local y = 1
  53.   monCoord[x] = {}
  54. --  for a = 1,17 do
  55.   for i,j in sortEss(essentia) do
  56.      if j<=20 then m.setTextColor(colors.red) end
  57.      if j<40 and j>20 then m.setTextColor(colors.yellow) end
  58.      if j>=40 then m.setTextColor(colors.green) end
  59.      
  60.      m.setCursorPos(x,y)
  61.      m.write(i)
  62.      m.setCursorPos(x+14,y)
  63.      m.write(tostring(j))
  64. --     print(j)
  65.      monCoord[x][y] = i
  66.      if y < 17 then
  67.         y = y+1
  68.      else
  69.         y = 1
  70.         x = x+17
  71.         monCoord[x] = {}  
  72.      end
  73.   end
  74. -- end
  75.  m.setTextColor(colors.white)
  76. end
  77.  
  78. function getClick()
  79.    local event,side,x,y = os.pullEvent()
  80.    if event=="monitor_touch" then
  81.      if button.checkxy(x,y) then
  82.         print("button")
  83.      else
  84.         if rowsActive then
  85.           fillAmt = 0
  86.           print(x..":"..x-(x%17)+1)
  87.           print(monCoord[x-(x%17)+1][y])
  88.           currEssentia = monCoord[x-(x%17)+1][y]
  89.           if currEssentia ~= nil then
  90.           if essentia[currEssentia] < 64 then
  91.              fillTable2()
  92.           else
  93.              m.clear()
  94.              button.label(1,10, currEssentia.." is already full.  Please choose another.")
  95.              sleep(3)
  96.              refresh()
  97.           end
  98.           end
  99.         end
  100.      end
  101.    end
  102. end
  103.  
  104. function refresh()
  105.    button.flash("Refresh")
  106.    m.clear()
  107.    scanEssentia()
  108.    printEssentia()
  109.    print("Refreshed")
  110.    button.screen()
  111. end
  112.  
  113. function fillTable()
  114.    rowsActive = true
  115.    button.clearTable()
  116.    button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
  117.    button.screen()
  118. end
  119.  
  120. function addEss(num)
  121.    fillAmt = fillAmt + num
  122.    if fillAmt < 0 then fillAmt = 0 end
  123.    if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
  124.    m.clear()
  125.    fillTable2()
  126. end
  127.  
  128. function fillEss2()
  129.    pipe.makeRequest(data[beans[currEssentia]][1], fillAmt)
  130.    m.clear()
  131.    fillTable()
  132.    refresh()
  133. end
  134.  
  135. function cancel()
  136.    m.clear()
  137.    fillTable()
  138.    refresh()
  139. end  
  140.  
  141. function fillTable2()
  142.    rowsActive = false
  143.    button.clearTable()
  144.    m.clear()
  145.    button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
  146.    button.setTable("+1", addEss, 1, 8, 18, 6,6)
  147.    button.setTable("+5", addEss, 5, 20, 30, 6, 6)
  148.    button.setTable("+10", addEss, 10, 32, 42, 6, 6)
  149.    button.setTable("-1", addEss, -1, 8, 18, 8, 8)
  150.    button.setTable("-5", addEss, -5, 20, 30, 8, 8)
  151.    button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
  152.    button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
  153.    button.setTable("Execute Fill Request", fillEss2, "", 8, 42, 16, 18)
  154.    button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
  155.    button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
  156.    button.screen()
  157. end
  158.  
  159. fillTable()
  160. refresh()
  161. findBeans()
  162. while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment