Advertisement
Guest User

ComputerCraft Aspect Direwolf20 Lets Play 1.7

a guest
Aug 30th, 2015
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.00 KB | None | 0 0
  1.  
  2. os.loadAPI("button")
  3. local essentia = {}
  4. local jars = peripheral.getNames()
  5. local m = peripheral.wrap("left")
  6. local ess = {}
  7. local essCount = {}
  8. local a = peripheral.find("tt_aspectanalyzer")
  9. local c = peripheral.find("iron")
  10. local rowsActive = true
  11. local monCoord = {}
  12. local currEssentia
  13. local fillAmt = 0
  14.  
  15. function findEss()
  16.     local tempess = {}
  17.     local notAuram
  18.     for i = 1,49 do
  19.         if c.getStackInSlot(i) then
  20.             c.pushItem("SOUTH", i, 1,1)
  21.             tempess = a.getAspects()
  22.             if tempess[2] then
  23.                 if tempess[2] == "auram" then
  24.                     notAuram = tempess[1]
  25.                 else
  26.                     notAuram = tempess[2]
  27.                 end
  28.             else
  29.                 notAuram = tempess[1]
  30.             end
  31.             c.pullItem("SOUTH", 1,1,i)
  32.             ess[notAuram] = i
  33.             essentia[notAuram] = 0
  34.             essCount[notAuram] = c.getStackInSlot(i)["qty"]
  35.         end
  36.     end
  37. --  print(ess["terra"])
  38. --  print(ess["fames"])
  39. --  print(ess["ignis"])
  40. --  print(essCount["terra"])
  41. --  print(essCount["fames"])
  42. --  print(essCount["arbor"])
  43. --  print(essCount["iter"])
  44. end
  45.  
  46. function scanEssentia()
  47.     for i,j in ipairs(jars) do
  48.         if peripheral.getType(j) == "tt_aspectContainer" then
  49.             asp = peripheral.call(j, "getAspects")
  50.             countasp = peripheral.call(j, "getAspectCount", asp[1])
  51.             if countasp > 0 then
  52.                 essentia[asp[1]] = math.floor(countasp)
  53. --              print(asp[1]..":"..countasp)
  54.             end
  55.         end
  56.     end
  57. end
  58.  
  59. function sortEss(t)
  60.    local keys = {}
  61.    for k in pairs(t) do keys[#keys+1] = k end
  62.    table.sort(keys)
  63.    
  64.    local i = 0
  65.    return function()
  66.       i = i+1
  67.       if keys[i] then
  68.          return keys[i], t[keys[i]]
  69.       end
  70.    end
  71. end
  72.  
  73. function printEssentia()
  74.   m.setTextColor(colors.white)
  75.   local x = 1
  76.   local y = 1
  77.   monCoord[x] = {}
  78. --  for a = 1,17 do
  79.   for i,j in sortEss(essentia) do
  80.      if j<=20 then m.setTextColor(colors.red) end
  81.      if j<40 and j>20 then m.setTextColor(colors.yellow) end
  82.      if j>=40 then m.setTextColor(colors.green) end
  83.      
  84.      m.setCursorPos(x,y)
  85.      m.write(i)
  86.      m.setCursorPos(x+14,y)
  87.      m.write(tostring(j))
  88. --     print(j)
  89.      monCoord[x][y] = i
  90.      if y < 17 then
  91.         y = y+1
  92.      else
  93.         y = 1
  94.         x = x+17
  95.         monCoord[x] = {}  
  96.      end
  97.   end
  98. -- end
  99.  m.setTextColor(colors.white)
  100. end
  101.  
  102. function getClick()
  103.     local timerCode = 0
  104.     timerCode = os.startTimer(15)
  105.     local event,side,x,y
  106.     repeat
  107.         event,side,x,y = os.pullEvent()
  108.         --print(event)
  109.     until side == timerCode or event=="monitor_touch"
  110.     if event=="monitor_touch" then
  111.         if button.checkxy(x,y) then
  112.             print("button")
  113.         else
  114.             if rowsActive then
  115.                 fillAmt = 0
  116.                 print(x..":"..x-(x%17)+1)
  117.                 print(monCoord[x-(x%17)+1][y])
  118.                 currEssentia = monCoord[x-(x%17)+1][y]
  119.                 if currEssentia ~= nil then
  120.                     if essentia[currEssentia] < 64 then
  121.                         fillTable2()
  122.                     else
  123.                         m.clear()
  124.                         button.label(1,10, currEssentia.." is already full.  Please choose another.")
  125.                         sleep(3)
  126.                         refresh()
  127.                     end
  128.                 end
  129.             end
  130.         end
  131.     else
  132.         refresh()
  133.    end
  134. end
  135.  
  136. function refresh()
  137.    button.flash("Refresh")
  138.    m.clear()
  139.    findEss()
  140.    scanEssentia()
  141.    printEssentia()
  142.    print("Refreshed")
  143.    button.screen()
  144. end
  145.  
  146. function fillTable()
  147.    rowsActive = true
  148.    button.clearTable()
  149.    button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
  150.    button.screen()
  151.    button.setTable("Refill All", refillAll, "", 39,52, 19,19)
  152. end
  153.  
  154. function refillAll()
  155.     for essName,essAmt in pairs(essentia) do
  156.         currEssentia = essName
  157.         print(currEssentia)
  158.         fillAmt = (64-essAmt)
  159.         if fillAmt > (essCount[currEssentia]-1)*2 then fillAmt = (essCount[currEssentia]-1)*2 end
  160.         fillEss2()
  161.     end
  162. end
  163.  
  164. function cancel()
  165.    m.clear()
  166.    fillTable()
  167.    refresh()
  168. end  
  169.  
  170. function addEss(num)
  171.    fillAmt = fillAmt + num
  172.    if fillAmt < 0 then fillAmt = 0 end
  173.    if fillAmt > 64-essentia[currEssentia] then fillAmt = 64-essentia[currEssentia] end
  174.    if fillAmt > (essCount[currEssentia]-1)*2 then fillAmt = (essCount[currEssentia]-1)*2 end
  175.    m.clear()
  176.    fillTable2()
  177. end
  178.  
  179. function fillEss2()
  180.     c.pushItem("UP", ess[currEssentia], fillAmt/2)
  181.     m.clear()
  182.     fillTable()
  183.     refresh()
  184. end
  185.  
  186. function fillTable2()
  187.    rowsActive = false
  188.    button.clearTable()
  189.    m.clear()
  190.    button.label(7, 1, "Essentia: "..currEssentia.." contains "..essentia[currEssentia])
  191.    button.label(7, 2, "Available: "..currEssentia.." is: "..(essCount[currEssentia]-1)*2)
  192.    button.setTable("+2", addEss, 2, 8, 18, 6,6)
  193.    button.setTable("+6", addEss, 6, 20, 30, 6, 6)
  194.    button.setTable("+10", addEss, 10, 32, 42, 6, 6)
  195.    button.setTable("-2", addEss, -2, 8, 18, 8, 8)
  196.    button.setTable("-6", addEss, -6, 20, 30, 8, 8)
  197.    button.setTable("-10", addEss, -10, 32, 42, 8 ,8)
  198.    button.setTable("Refill Jar", addEss, 64-essentia[currEssentia], 8, 42, 10, 10)
  199.    button.setTable("Execute Fill Request", fillEss2, "", 8, 42, 16, 18)
  200.    button.setTable("Cancel", cancel, "", 20, 30, 12, 14)
  201.    button.label(7, 4, "Currently Adding "..fillAmt.." "..currEssentia.." essentia.")
  202.    button.screen()
  203. end
  204.  
  205. fillTable()
  206. refresh()
  207. while true do getClick() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement