Advertisement
Bart1ebee

aspects

Mar 27th, 2015
574
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.22 KB | None | 0 0
  1. -- Based on direwolf20 thaumcraft essentia/request monitor updated by Bart1ebee
  2. -- Button API (XBbMUYNn) by direwolf20
  3. -- Working with 1.7.10 tested with versions below
  4. -- Thaumcraft-1.7.10-4.2.3.5
  5. -- ThaumicTinkerer-2.5-1.7.10-439
  6. -- ComputerCraft 1.65
  7. -- OpenPeripheralAddons-1.7.10-0.2.0-snapshot-149
  8. -- Works with crystallized essentia should work with mana beans
  9. -- Thanks to direwolf20 for initially writing the program.
  10. -- TODO: Check crystallized essentia is available if there is not any the app will crash.
  11.  
  12. --rednet.open("left")
  13. os.loadAPI("button")
  14. --local turtleID = 40
  15. local essentia = {}
  16. local jars = peripheral.getNames()
  17. local m = peripheral.find("monitor")
  18. local monCoord = {}
  19. local currEssentia
  20. local fillAmt = 0
  21. local rowsActive = true
  22. local pipe = peripheral.find("LogisticsPipes:Request")
  23. local beans = {}
  24.  
  25. function findBeans()
  26.    data = pipe.getAvailableItems()
  27.    for i=1,#data do
  28.       data2 = data[i].getValue1().getTagCompound()
  29.       beans[data2["value"]["Aspects"]["value"][1]["value"]["key"]["value"]] = data[i].getValue1()
  30.    end
  31. --   print(beans["instrumentum"][1])
  32. end
  33.  
  34. function sortEss(t)
  35.    local keys = {}
  36.    for k in pairs(t) do keys[#keys+1] = k end
  37.    table.sort(keys)
  38.    
  39.    local i = 0
  40.    return function()
  41.       i = i+1
  42.       if keys[i] then
  43.          return keys[i], t[keys[i]]
  44.       end
  45.    end
  46. end
  47.  
  48. function scanEssentia()
  49.   for i,j in ipairs(jars) do
  50.      if peripheral.getType(j) == "tt_aspectContainer" then
  51.        asp = peripheral.call(j, "getAspects")
  52.        print(asp)
  53.        countasp = peripheral.call(j, "getAspectCount", asp[1])
  54.        if countasp > 0 then
  55.          essentia[asp[1]] = math.floor(countasp)
  56.        end
  57.       -- print(countasp)
  58.       -- print(asp[1]..":"..countasp)
  59.       -- print(peripheral.getType(j))
  60.      end
  61.   end
  62. end
  63.  
  64. function printEssentia()
  65.   m.setTextColor(colors.white)
  66.   local x = 1
  67.   local y = 1
  68.   monCoord[x] = {}
  69. --  for a = 1,17 do
  70.   for i,j in sortEss(essentia) do
  71.      if j<=20 then m.setTextColor(colors.red) end
  72.      if j<40 and j>20 then m.setTextColor(colors.yellow) end
  73.      if j>=40 then m.setTextColor(colors.green) end
  74.      
  75.      m.setCursorPos(x,y)
  76.      m.write(i)
  77.      m.setCursorPos(x+14,y)
  78.      m.write(tostring(j))
  79. --     print(j)
  80.      monCoord[x][y] = i
  81.      if y < 17 then
  82.         y = y+1
  83.      else
  84.         y = 1
  85.         x = x+17
  86.         monCoord[x] = {}  
  87.      end
  88.   end
  89. -- end
  90.  m.setTextColor(colors.white)
  91. end
  92.  
  93. function getClick()
  94.    local event,side,x,y = os.pullEvent()
  95.    if event=="monitor_touch" then
  96.      if button.checkxy(x,y) then
  97.         print("button")
  98.      else
  99.         if rowsActive then
  100.           fillAmt = 0
  101.           print(x..":"..x-(x%17)+1)
  102.           print(monCoord[x-(x%17)+1][y])
  103.           currEssentia = monCoord[x-(x%17)+1][y]
  104.           if currEssentia ~= nil then
  105.           if essentia[currEssentia] < 64 then
  106.              fillTable2()
  107.           else
  108.              m.clear()
  109.              button.label(1,10, currEssentia.." is already full.  Please choose another.")
  110.              sleep(3)
  111.              refresh()
  112.           end
  113.           end
  114.         end
  115.      end
  116.    end
  117. end
  118.  
  119. function refresh()
  120.    button.flash("Refresh")
  121.    m.clear()
  122.    scanEssentia()
  123.    printEssentia()
  124.    print("Refreshed")
  125.    button.screen()
  126. end
  127.  
  128. function fillTable()
  129.    rowsActive = true
  130.    button.clearTable()
  131.    button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
  132.    button.screen()
  133. end
  134.  
  135. function addEss(num)
  136.    fillAmt = fillAmt + num
  137.    if fillAmt < 0 then fillAmt = 0 end
  138.    if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
  139.    m.clear()
  140.    fillTable2()
  141. end
  142.  
  143. function fillEss2()
  144.    pipe.makeRequest(beans[currEssentia], fillAmt)
  145.    m.clear()
  146.    fillTable()
  147.    refresh()
  148. end
  149.  
  150. function fillEss()
  151.    --No longer used, see fillEss2()
  152.    local essData = {}
  153.    essData[1] = currEssentia
  154.    essData[2] = fillAmt
  155.    local sendData = ""
  156.    sendData = textutils.serialize(essData)
  157.    rednet.send(turtleID, sendData)
  158.    m.clear()
  159.    button.label(7, 10, "Waiting for aspects to finish cooking....")
  160.    button.label(7, 12, "Don't forget to refresh the screen after")
  161.    button.label(7, 13, "the golem is done moving the essentia.")
  162.    rednet.receive()
  163.    m.clear()
  164.    fillTable()
  165.    refresh()
  166. end
  167.  
  168. function cancel()
  169.    m.clear()
  170.    fillTable()
  171.    refresh()
  172. end  
  173.  
  174. function fillTable2()
  175.    rowsActive = false
  176.    button.clearTable()
  177.    m.clear()
  178.    button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
  179.    button.setTable("+1", addEss, 1, 8, 18, 6,6)
  180.    button.setTable("+5", addEss, 5, 20, 30, 6, 6)
  181.    button.setTable("+10", addEss, 10, 32, 42, 6, 6)
  182.    button.setTable("-1", addEss, -1, 8, 18, 8, 8)
  183.    button.setTable("-5", addEss, -5, 20, 30, 8, 8)
  184.    button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
  185.    button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
  186.    button.setTable("Execute Fill Request", fillEss2, "", 8, 42, 16, 18)
  187.    button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
  188.    button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
  189.    button.screen()
  190. end
  191.  
  192. fillTable()
  193. refresh()
  194. findBeans()
  195. while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement