Guest User

Test Script

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