Advertisement
purefocus

Thaumcraft Controller

Apr 1st, 2015
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.39 KB | None | 0 0
  1. local jars = {}
  2. local jarCount = 0
  3.  
  4. local aspectLocations = {"instrumentum","venenum","perditio","vitreus","vinculum",
  5. "victus","pannus","alienis","sensus","mortuus","metallum",
  6. "permutatio","ordo","aqua","iter","auram","ignis","fabrico",
  7. "messis","herba","arbor","lucrum","corpus","praecantatio",
  8. "gelum","fames","motus","sano","meto","aer","bestia","tenebrae", "tutamen", "lux",
  9. "potentia", "vacous", "terra", "humanus", "spiritus", "machina", "perfodio", "exanimis", "limus",
  10. "telum", "volatus", "cognitio"}
  11.  
  12. local waitTimes = {}
  13. local lastCheck = {}
  14.  
  15. local primalNames = {"aer", "aqua", "ignis", "ordo", "perditio", "terra"}
  16. local primalJars = {}
  17. local primalIndex = 0
  18.  
  19. local chest = peripheral.wrap("back")
  20.  
  21. local offX = 20
  22. local offY = 5
  23.  
  24. local monitor = peripheral.wrap("right")
  25.  
  26. function locate (list, value)
  27.     for i, v in ipairs(list) do
  28.         if v == value then
  29.             return i
  30.         end
  31.     end
  32.     return 0
  33. end
  34.  
  35. function printAspect(mon, px, py, jar)
  36.     mon.setCursorPos(px, py)
  37.    
  38.     aspect = jar.getAspects()[1]
  39.     count = jar.getAspectCount(aspect)
  40.     index = locate(aspectLocations, aspect)
  41.     if lastCheck[index] == nil then
  42.         lastCheck[index] = count
  43.     end
  44.     if waitTimes[index] == nil or count == 64 then
  45.         if lastCheck[index] > count then
  46.             mon.setTextColor(colors.orange)
  47.         else
  48.             if lastCheck[index] < count then
  49.                 mon.setTextColor(colors.lightBlue)
  50.             else
  51.                 if count < 32 then
  52.                     fillJar(aspect, count)
  53.                     mon.setTextColor(colors.red)
  54.                 else
  55.                     if count < 64 then
  56.                         fillJar(aspect, count)
  57.                         mon.setTextColor(colors.yellow)
  58.                     else
  59.                         waitTimes[index] = nil
  60.                         mon.setTextColor(colors.lime)
  61.                     end
  62.                 end
  63.             end
  64.         end
  65.     else
  66.         mon.setTextColor(colors.blue)
  67.         if waitTimes[index] == count then
  68.             waitTimes[index] = nil
  69.         end
  70.     end
  71.     lastCheck[index] = count
  72.    
  73.     mon.write(aspect)
  74.     mon.setCursorPos(px + 14, py)
  75.     mon.write(tostring(count))
  76. end
  77.  
  78. function loadJars()
  79.     names = peripheral.getNames()
  80.     for i, v in ipairs(names) do
  81.         typ = peripheral.getType(v)
  82.         if typ == "tt_aspectContainer" then
  83.             jar = peripheral.wrap(v)
  84.             aspect = jar.getAspects()[1]
  85.             if locate(primalNames, aspect) > 0 then
  86.                 primalIndex = primalIndex + 1
  87.                 jars[primalIndex] = jar
  88.             else
  89.                 jarCount = jarCount + 1
  90.                 jars[jarCount + 6] = jar
  91.             end
  92.         else
  93.             monitor = peripheral.wrap(v)
  94.         end
  95.     end
  96.    
  97.     print(jarCount)
  98. end
  99.  
  100. function fillJar(aspect, count)
  101.     need = 64 - count;
  102.     index = locate(aspectLocations, aspect)
  103.     if waitTimes[index] == nil then
  104.         if index == 0 then
  105.             --print("no  " .. aspect)
  106.         else
  107.             stack = chest.getStackInSlot(index)
  108.             if stack.qty > 1 then
  109.                 take = math.min(stack.qty - 1, need)
  110.                 --print(take .. "  " .. index)
  111.                 chest.pushItem("north", index, take)
  112.                 waitTimes[index] = count + take
  113.             end
  114.         end
  115.     else
  116.         if waitTimes[index] == count then
  117.             waitTimes[index] = nil
  118.         end
  119.     end
  120. end
  121.  
  122. loadJars()
  123.  
  124. while true do
  125.     monitor.clear()
  126.     monitor.setTextScale(0.9)
  127.     monitor.setCursorPos(1, 1)
  128.     monitor.write(jarCount)
  129.     for i, v in ipairs(jars) do
  130.         if v == nil then
  131.         else
  132.             if i % 2 == 1 then
  133.                 printAspect(monitor, 1, (i - 1) / 2 + 1, v)
  134.                 -- monitor.setCursorPos(19 + offX, i / 2 + 1 + offY)
  135.                 -- monitor.setTextColor(colors.white)
  136.                 -- monitor.write("|")
  137.             else
  138.                 printAspect(monitor, 21, (i - 1) / 2 + 1, v)
  139.             end
  140.         end
  141.  
  142.     end
  143.    
  144.     sleep(1)
  145. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement