Advertisement
Guest User

aspects

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