davedumas0

thaumcraftThingy(opencomputers server)

Apr 2nd, 2022 (edited)
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.08 KB | None | 0 0
  1. -- server config https://cdn.discordapp.com/attachments/358433226290626564/959697119164371005/unknown.png
  2.  
  3. local os = require("os")
  4. local computer = require("computer")
  5. local term = require("term")
  6. local filesystem = require("filesystem")
  7. local component = require("component")
  8. local keyboard = require("keyboard")
  9. local event = require("event")
  10. local gpu = component.gpu
  11. local modem = component.modem
  12.  
  13.  
  14.  
  15.  
  16. --minecraft colors
  17. colors_white = 0xffffff
  18. colors_orange = 0xff6600
  19. colors_magenta = 0xff00ff
  20. colors_lightblue = 0x0099ff
  21. colors_yellow = 0xffff00
  22. colors_lime = 0x00ff00
  23. colors_pink = 0xff3399
  24. colors_gray = 0x737373
  25. colors_silver = 0xc0c0c0
  26. colors_cyan = 0x169c9d
  27. colors_purple = 0x8932b7
  28. colors_blue = 0x3c44a9
  29. colors_brown = 0x825432
  30. colors_green = 0x5d7c15
  31. colors_red = 0xb02e26
  32. colors_black = 0x000000
  33. --minecraft colors
  34.  
  35. local touchLocation = " "
  36. local touchName = " "
  37. local touchX = 0
  38. local touchY = 0
  39. local aspectValues = {}
  40. local aspects = {}
  41. local jars = {}
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. function modemListen()
  49.  modem.open(5)
  50.    _, _, from, port, _, msg = event.pull(0.001,  "modem_message")
  51.   if msg ~= nil then
  52.    message = msg
  53.   else
  54.    message = " "
  55.   end
  56. end
  57.  
  58. function touchCheck()
  59.   _,_, touchX, touchY = event.pull(0.001, "touch")
  60. end
  61.  
  62. function sendMsgToRobot (msg)
  63.  
  64.  modem.broadcast(5, msg)
  65.  
  66. end
  67.  
  68. -----------------------------
  69. ------ functions for UI -----
  70. ------------\/---------------
  71.  
  72.  
  73. function drawAspctsPanel()
  74. local panelX = 10
  75. local panelY  = 5
  76. local panelSizeX = 30
  77. local panelSizeY = #jars
  78.   drawLine(panelX-1, panelY, panelSizeX+2, panelSizeY+2, colors_gray)
  79.  
  80.  drawText(panelX+7, panelY-3, "thaumcraft ", colors_purple, colors_black)
  81.   drawText(panelX+9, panelY-2, "aspects ", colors_purple, colors_black)
  82.    
  83.      drawText(panelX+26, panelSizeY+panelY+3, #jars.."/".."49", colors_purple, colors_black)
  84.  
  85.  
  86.  
  87.  
  88.  
  89.   for k, v in ipairs(jars) do
  90.    tg =  component.invoke(v, "getAspectNames")
  91.    tf =  component.invoke(v, "getAspectCount", tg[1])
  92.     aspects[tg[1]] =  tf
  93.     drawText(panelX+2, panelY+k, tg[1], colors_purple, colors_gray)
  94.    
  95.     if aspects[tg[1]] ~= nil then
  96.      drawText(panelX+18, panelY+k, aspects[tg[1]], colors_silver, colors_gray)
  97.    
  98.    
  99.    
  100.     end
  101.   end
  102.  
  103.  
  104. end
  105.  
  106.  
  107.  
  108. function drawRobotControlsPAnel()
  109.  
  110. local panelX = 55
  111. local panelY  = 10
  112. local panelSizeX = 31
  113. local panelSizeY = 17
  114. local panel_BGColor = colors_gray
  115.  
  116.  
  117.  drawText(panelX+panelSizeX/2-7, panelY-1, "robot controls", colors_orange, colors_black)
  118.  drawLine(panelX, panelY, panelSizeX, panelSizeY, panel_BGColor)
  119.  drawButton("robotFW", panelX+11, panelY+1, 3, robotGoForward, _, colors_green, colors_silver, true)
  120.  drawButton("robotTL", panelX+1, panelY+5, 3, robotTurnLeft, _, colors_green, colors_silver, true)
  121.  drawButton("robotTR", panelX+21, panelY+5, 3, robotTurnRight, _, colors_green, colors_silver, true)
  122.  drawButton("robotBK", panelX+11, panelY+9, 3, robotGoBack, _, colors_green, colors_silver, true)
  123.  drawButton("robotUP", panelX+1, panelY+1, 3, robotGoUp, _, colors_lightblue, colors_cyan, true)
  124.  drawButton("robotDN", panelX+21, panelY+1, 3, robotGoDown, _, colors_lightblue, colors_cyan, true)
  125. end
  126.  
  127. function robotTurnRight()
  128.   sendMsgToRobot("robotTurnRight")
  129. end
  130.  
  131. function robotTurnLeft()
  132.   sendMsgToRobot("robotTurnLeft")
  133. end
  134.  
  135. function robotGoForward()
  136.   sendMsgToRobot("robotGoForward")
  137. end
  138.  
  139. function robotGoBack()
  140.  sendMsgToRobot("robotGoBack")
  141. end
  142.  
  143. function robotGoUp()
  144.  sendMsgToRobot("robotGoUp")
  145. end
  146.  
  147. function robotGoDown()
  148.  sendMsgToRobot("robotGoDown")
  149. end
  150.  
  151.  
  152. function drawLine (posX, posY, length, highth, line_color)
  153.   gpu.setBackground(line_color)
  154.  
  155.   gpu.fill(posX, posY, length, highth, " ")
  156. end
  157.  
  158.  
  159. function drawText (X, Y, text, color_txt, color_bg)
  160.  term.setCursor(X, Y)
  161.  gpu.setBackground(color_bg)
  162.  
  163.  gpu.setForeground(color_txt, false)
  164.  term.write(tostring(text))
  165.  gpu.setBackground(colors_black)
  166. end
  167.  
  168. function drawButton (label, x, y, hight, func, fuc_data, txt_color, bttn_color, enabled)
  169.  length = #label+2
  170.   if not enabled then
  171.      drawLine(x, y, length, hight, colors_gray)
  172.      drawText(x, y, label, colors_gray, colors_gray)  
  173.   end
  174.   if enabled then
  175.     drawLine(x, y, length, hight, bttn_color)
  176.     drawText(x+1,y+hight/2, label, txt_color, bttn_color)
  177.    if touchX ~= nil or touchY ~= nil then
  178.     if (touchX >= x) and (touchX <= x + length-1)  and (touchY >= y) and (touchY <= y + hight-1) then
  179.       func(fuc_data)
  180.     end
  181.    end
  182.   end
  183. end
  184.  
  185. function drawRefreshButton()
  186. drawButton("refresh", 25 - 9/2, 5 + #jars+3, 3, refreshAspects, _, colors_lightblue, colors_white, true)
  187. end
  188.  
  189.  
  190.  
  191. function refreshAspects()
  192.  t = 0
  193. end
  194.  
  195.  
  196.  
  197. term.clear()
  198.  
  199.  
  200. t = 0
  201.  
  202.  
  203. while true do
  204.  
  205.   --modemListen ()
  206.   touchCheck()
  207. drawRobotControlsPAnel()
  208.   drawRefreshButton()
  209.  
  210.  if t == 0 then
  211.     term.clear()
  212.     jars = {}
  213.     aspects = {}
  214.     aspectValues = {}
  215.      for key, value in pairs(component.list()) do
  216.       if value == "jar_normal" then
  217.        table.insert(jars, key)
  218.       end
  219.      end
  220.     drawAspctsPanel()
  221.    
  222.      t = 1
  223.  end
  224.  
  225.  
  226.  
  227. os.sleep(0.0)
  228. end
  229.  
  230.  
  231.  
Add Comment
Please, Sign In to add comment