Advertisement
davedumas0

opencomputers thaumcraft thingy

Mar 31st, 2022
1,516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.43 KB | None | 0 0
  1.  
  2. local os = require("os")
  3. local computer = require("computer")
  4. local term = require("term")
  5. local filesystem = require("filesystem")
  6. local component = require("component")
  7. local keyboard = require("keyboard")
  8. local event = require("event")
  9. local gpu = component.gpu
  10.  
  11.  
  12.  
  13.  
  14.  
  15. --minecraft colors
  16. colors_white = 0xffffff
  17. colors_orange = 0xff6600
  18. colors_magenta = 0xff00ff
  19. colors_lightblue = 0x0099ff
  20. colors_yellow = 0xffff00
  21. colors_lime = 0x00ff00
  22. colors_pink = 0xff3399
  23. colors_gray = 0x737373
  24. colors_silver = 0xc0c0c0
  25. colors_cyan = 0x169c9d
  26. colors_purple = 0x8932b7
  27. colors_blue = 0x3c44a9
  28. colors_brown = 0x825432
  29. colors_green = 0x5d7c15
  30. colors_red = 0xb02e26
  31. colors_black = 0x000000
  32. --minecraft colors
  33.  
  34. local touchLocation = " "
  35. local touchName = " "
  36. local touchX = 0
  37. local touchY = 0
  38. local aspectValues = {}
  39. local aspects = {}
  40. local jars = {}
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. function modemListen ()
  48.  modem.open(5)
  49.   _, _, from, port, _, msg = event.pull(0.001,  "modem_message")
  50.  if msg ~= nil then
  51.   message = msg
  52.  
  53.  end
  54. end
  55.  
  56. function touchCheck()
  57.   touchLocation,touchName, touchX, touchY = event.pull(0.01, "touch")
  58. end
  59.  
  60. -----------------------------
  61. ------ functions for UI -----
  62. ------------\/---------------
  63.  
  64.  
  65. function drawAspctsPanel()
  66. local panelX = 10
  67. local panelY  = 5
  68. local panelSizeX = 30
  69. local panelSizeY = #jars
  70.   drawLine(panelX-1, panelY, panelSizeX+2, panelSizeY+2, colors_gray)
  71.  
  72.  drawText(panelX+7, panelY-3, "thaumcraft ", colors_purple, colors_black)
  73.   drawText(panelX+9, panelY-2, "aspects ", colors_purple, colors_black)
  74.    
  75.      drawText(panelX+29, panelSizeY+panelY+3, #jars, colors_purple, colors_black)
  76.  
  77.  
  78.  
  79.  
  80.  
  81.   for k, v in ipairs(jars) do
  82.    tg =  component.invoke(v, "getAspectNames")
  83.    tf =  component.invoke(v, "getAspectCount", tg[1])
  84.     aspects[tg[1]] =  tf
  85.     drawText(panelX+2, panelY+k, tg[1], colors_purple, colors_gray)
  86.    
  87.     if aspects[tg[1]] ~= nil then
  88.      drawText(panelX+18, panelY+k, aspects[tg[1]], colors_silver, colors_gray)
  89.    
  90.    
  91.    
  92.     end
  93.   end
  94.  
  95.  
  96. end
  97.  
  98.  
  99. function drawLine (posX, posY, length, highth, line_color)
  100.   gpu.setBackground(line_color)
  101.  
  102.   gpu.fill(posX, posY, length, highth, " ")
  103. end
  104.  
  105.  
  106. function drawText (X, Y, text, color_txt, color_bg)
  107.  term.setCursor(X, Y)
  108.  gpu.setBackground(color_bg)
  109.  
  110.  gpu.setForeground(color_txt, false)
  111.  term.write(tostring(text))
  112.  gpu.setBackground(colors_black)
  113. end
  114.  
  115. function drawButton (label, x, y, hight, func, fuc_data, txt_color, bttn_color, enabled)
  116.  length = #label+2
  117.   if not enabled then
  118.      drawLine(x, y, length, hight, colors_gray)
  119.      drawText(x, y, label, colors_gray, colors_gray)  
  120.   end
  121.   if enabled then
  122.     drawLine(x, y, length, hight, bttn_color)
  123.     drawText(x+1,y+hight/2, label, txt_color, bttn_color)
  124.    if touchX ~= nil or touchY ~= nil then
  125.     if (touchX >= x) and (touchX <= x + length-1)  and (touchY >= y) and (touchY <= y + hight-1) then
  126.       func(fuc_data)
  127.     end
  128.    end
  129.   end
  130. end
  131.  
  132. function refreshAspects()
  133.  t = 0
  134.  
  135. end
  136.  
  137.  
  138.  
  139.  
  140. term.clear()
  141.  
  142.  
  143. t = 0
  144.  
  145.  
  146. while true do
  147.  
  148.   --modemListen ()
  149.   touchCheck()
  150.  
  151.   drawButton("refresh", 85, 35, 3, refreshAspects, _, colors_lightblue, colors_white, true)
  152.  
  153.  if t == 0 then
  154.     term.clear()
  155.     jars = {}
  156.      for key, value in pairs(component.list()) do
  157.       if value == "jar_normal" then
  158.        table.insert(jars, key)
  159.       end
  160.      end
  161.     drawAspctsPanel()
  162.      t = 1
  163.  end
  164. os.sleep(0.0)
  165. end
  166.  
  167.  
  168.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement