Guest User

Thaumcraft Essentia automation

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