Advertisement
davedumas0

my minecraft opencomputers control thingy - v0.3

Mar 6th, 2022
1,285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.94 KB | None | 0 0
  1. --------------------------
  2. --required function libs
  3. --------------------------
  4.  
  5.  
  6. local os = require("os")
  7. local computer = require("computer")
  8. local term = require("term")
  9. local colors = require("colors")
  10. local filesystem = require("filesystem")
  11. local component = require("component")
  12. local keyboard = require("keyboard")
  13. local event = require("event")
  14. local gpu = component.gpu
  15. local redstone = component.redstone
  16.  
  17.  
  18.  
  19.  
  20.  
  21. local gpu1 = component.gpu  -- get the proxy of the primary GPU
  22. local addr1 = tostring(component.get("c9d9"))  -- the address of the first screen
  23. local addr2 = tostring(component.get("fb45"))  -- the address of the second screen
  24.  
  25. local touchLocation = ""
  26. local touchName = ""
  27. local touchX = 0
  28. local touchY = 0
  29. local meItems = component.me_controller.getItemsInNetwork()
  30. local meFluids = component.me_controller.getFluidsInNetwork()
  31. local tempColor = colors_magenta
  32. local availableMobsListPage = 1
  33.  
  34. colors_white = 0xffffff
  35. colors_orange = 0xff6600
  36. colors_magenta = 0xff00ff
  37. colors_lightblue = 0x0099ff
  38. colors_yellow = 0xffff00
  39. colors_lime = 0x00ff00
  40. colors_pink = 0xff3399
  41. colors_gray = 0x737373
  42. colors_silver = 0xc0c0c0
  43. colors_cyan = 0x169c9d
  44. colors_purple = 0x8932b7
  45. colors_blue = 0x3c44a9
  46. colors_brown = 0x825432
  47. colors_green = 0x5d7c15
  48. colors_red = 0xb02e26
  49. colors_black = 0x000000
  50.  
  51. mobs = ""
  52.  
  53. lightToggle1 = false
  54. lightToggle2 = false
  55. lightToggle3 = false
  56. lightToggle4 = false
  57. lightToggle5 = false
  58.  
  59. navigateMobsListSelected = 1
  60.  
  61.  
  62. temp15 = 0
  63.  
  64.  
  65.  
  66.  
  67. term.clear()
  68.  
  69. function isRedstoneChannelOpen(redstoneChannel)
  70. local redstoneChannelData = redstone.getBundledInput(5, redstoneChannel)
  71.  
  72.  if redstoneChannelData > 0 then
  73.   return true
  74.   else return false
  75.  end
  76. end
  77.  
  78.  
  79. function openRedstoneChannel(redstoneChannel)
  80. local redstoneChannelData = redstone.setBundledOutput(5, redstoneChannel, 255)
  81. end
  82.  
  83. function closeRedstoneChannel(redstoneChannel)
  84. local redstoneChannelData = redstone.setBundledOutput(5, redstoneChannel, 0)
  85. end
  86.  
  87. function isPlayerInCorridor ()
  88. local temp1 = isRedstoneChannelOpen(1)
  89.   if temp1 then
  90.    return true
  91.   else return false
  92.   end
  93.  
  94. end
  95.  
  96.  
  97. -----------------------------
  98. ------ functions for UI -----
  99. ------------\/---------------
  100.  
  101. function drawLine (posX, posY, length, highth, line_color)
  102.   gpu.setBackground(line_color)
  103.  
  104.   gpu.fill(posX, posY, length, highth, " ")
  105. end
  106.  
  107. function drawLight1(X, Y, length, hight)
  108.  
  109.  if lightToggle1 == true then
  110.    drawText(X-1, Y-2, "enabled", colors_blue, colors_white)
  111.    drawLine(X, Y, length, hight, colors_green)
  112.    
  113.  else
  114.    drawText(X-1, Y-2, "disabled", colors_red, colors_white)
  115.    drawLine(X, Y, length, hight, colors_red)
  116.  end
  117.  
  118. end
  119.  
  120. function drawLight2(X, Y, length, hight)
  121.  
  122.  if lightToggle2 == true then
  123.    drawText(X-1, Y-2, "enabled", colors_green, colors_white)
  124.    drawLine(X, Y, length, hight, colors_green)
  125.  
  126.  else
  127.    drawText(X-1, Y-2, "disabled", colors_red, colors_white)
  128.    drawLine(X, Y, length, hight, colors_red)
  129.  end
  130.  
  131. end
  132.  
  133. function drawText (X, Y, text, color_txt, color_bg)
  134.  term.setCursor(X, Y)
  135.  gpu.setBackground(color_bg)
  136.  
  137.  gpu.setForeground(color_txt, false)
  138.  term.write(tostring(text))
  139.  gpu.setBackground(colors_black)
  140. end
  141.  
  142. function drawButton (label, x, y, hight, func, fuc_data, txt_color, bttn_color, enabled)
  143.  length = #label+2
  144.   if not enabled then
  145.      drawLine(x, y, length, hight, colors_gray)
  146.      drawText(x, y, label, colors_gray, colors_gray)  
  147.   end
  148.   if enabled then
  149.     drawLine(x, y, length, hight, bttn_color)
  150.     drawText(x+1,y+hight/2, label, txt_color, bttn_color)
  151.    if touchX ~= nil or touchY ~= nil then
  152.     if (touchX >= x) and (touchX <= x + length-1)  and (touchY >= y) and (touchY <= y + hight-1) then
  153.       func(fuc_data)
  154.     end
  155.    end
  156.   end
  157. end
  158.  
  159. function drawInvisibleButton (x, y, hight, length, func)
  160.  
  161.    if touchX ~= nil or touchY ~= nil then
  162.     if (touchX >= x) and (touchX <= x + length)  and (touchY >= y) and (touchY <= y + hight) then
  163.       func()
  164.     end
  165.    end
  166.  
  167. end
  168.  
  169.  
  170.  
  171. function swichToScreen1()
  172.    gpu.bind(addr1)
  173. end
  174.  
  175. function swichToScreen2()
  176.    gpu.bind(addr2)
  177. end
  178.  
  179. function clearBothScreens()
  180.    swichToScreen1()
  181.     term.clear()
  182.      swichToScreen2()
  183.       term.clear()
  184.        swichToScreen1()
  185. end
  186.  
  187. function clearPrimaryScreen()
  188.    swichToScreen1()
  189.     gpu.setResolution(160, 50)
  190.     term.clear()
  191. end
  192.  
  193. function clearSecondaryScreen()
  194.    swichToScreen2()
  195.    gpu.setResolution(140, 50)
  196.     term.clear()
  197. end
  198.  
  199. function drawCorridorAccessPanel()
  200. local panelX = 3
  201. local panelY  = 10
  202. local panelSizeX = 14
  203. local panelSizeY = 13
  204. local buttonSizeY = 5
  205.  drawLine(panelX-1, panelY, panelSizeX+2, panelSizeY, colors_gray)
  206.  drawText(panelX-1, panelY-1, "corridor  access", colors_white, colors_gray)
  207.  drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  208.  drawButton("open door ", panelX+1, panelY+1, buttonSizeY, openCoridorDoor, _, colors_lightblue, colors_green, true)
  209.  drawButton("close door", panelX+1, panelY+buttonSizeY+2, buttonSizeY, closeCoridorDoor, _, colors_lightblue, colors_red, true)
  210. end
  211.  
  212. function drawRoomAccessPanel()
  213. local panelX = 100
  214. local panelY  = 10
  215. local panelSizeX = 14
  216. local panelSizeY = 13
  217. local buttonSizeY = 5
  218.  drawLine(panelX-1, panelY, panelSizeX+2, panelSizeY, colors_gray)
  219.  drawText(panelX-1, panelY-1, "room  access", colors_white, colors_gray)
  220.  drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  221.  drawButton("open door ", panelX+1, panelY+1, buttonSizeY, openCoridorDoor, _, colors_lightblue, colors_green, true)
  222.  drawButton("close door", panelX+1, panelY+buttonSizeY+2, buttonSizeY, closeCoridorDoor, _, colors_lightblue, colors_red, true)
  223. end
  224.  
  225. function drawStorageInfoPanel()
  226. local panelX = 80
  227. local panelY  = 5
  228. local panelSizeX = 55
  229. local panelSizeY = 5
  230.  
  231.  drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  232.    drawText(panelX+1, panelY+1, "current stored essence:", colors_lightblue, colors_gray)
  233.    drawText(110, panelY+1, getCurrentEssenceInStorage().." mili-Buckets", colors_lightblue, colors_gray)
  234.    
  235.    drawText(panelX+1, panelY+3, "number of available mobs ", colors_lightblue, colors_gray)
  236.    drawText(panelX+30, panelY+3, numberOfMobsInSystem, colors_lightblue, colors_gray)
  237.  
  238. end
  239.  
  240. function drawAvailableMobsListPanel()
  241. local panelX = 80
  242. local panelY  = 11
  243. local panelSizeX = 26
  244. local panelSizeY = 9
  245.  
  246. numberOfMobsInSystem = #meItems
  247.  
  248.  
  249.   if availableMobsListPage == 1 then
  250.  
  251.  
  252.   if navigateMobsListSelected == 1 then
  253.    
  254.        drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  255.         drawText(panelX+6, panelY, "available mobs", colors_white, colors_gray)
  256.       drawText(panelX+1, panelY+1, meItems[1]["entity"], colors_lime, colors_silver)
  257.           drawText(panelX+1, panelY+2, meItems[2]["entity"], colors_lime, colors_gray)
  258.            drawText(panelX+1, panelY+3, meItems[3]["entity"], colors_lime, colors_gray)
  259.             drawText(panelX+1, panelY+4, meItems[4]["entity"], colors_lime, colors_gray)
  260.              drawText(panelX+1, panelY+5, meItems[5]["entity"], colors_lime, colors_gray)
  261.               drawText(panelX+1, panelY+6, meItems[6]["entity"], colors_lime, colors_gray)
  262.         drawText(panelX+1, panelY+7, "NONE", colors_lime, colors_gray)
  263.   elseif navigateMobsListSelected == 2 then
  264.     drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  265.      drawText(panelX+6, panelY, "available mobs", colors_white, colors_gray)
  266.    drawText(panelX+1, panelY+1, meItems[1]["entity"], colors_lime, colors_gray)
  267.        drawText(panelX+1, panelY+2, meItems[2]["entity"], colors_lime, colors_silver)
  268.         drawText(panelX+1, panelY+3, meItems[3]["entity"], colors_lime, colors_gray)
  269.          drawText(panelX+1, panelY+4, meItems[4]["entity"], colors_lime, colors_gray)
  270.           drawText(panelX+1, panelY+5, meItems[5]["entity"], colors_lime, colors_gray)
  271.            drawText(panelX+1, panelY+6, meItems[6]["entity"], colors_lime, colors_gray)
  272.      drawText(panelX+1, panelY+7, "NONE", colors_lime, colors_gray)
  273.   elseif navigateMobsListSelected == 3 then
  274.     drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  275.      drawText(panelX+6, panelY, "available mobs", colors_white, colors_gray)
  276.    drawText(panelX+1, panelY+1, meItems[1]["entity"], colors_lime, colors_gray)
  277.        drawText(panelX+1, panelY+2, meItems[2]["entity"], colors_lime, colors_gray)
  278.         drawText(panelX+1, panelY+3, meItems[3]["entity"], colors_lime, colors_silver)
  279.          drawText(panelX+1, panelY+4, meItems[4]["entity"], colors_lime, colors_gray)
  280.           drawText(panelX+1, panelY+5, meItems[5]["entity"], colors_lime, colors_gray)
  281.            drawText(panelX+1, panelY+6, meItems[6]["entity"], colors_lime, colors_gray)
  282.      drawText(panelX+1, panelY+7, "NONE", colors_lime, colors_gray)
  283.   elseif navigateMobsListSelected == 4 then
  284.     drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  285.      drawText(panelX+6, panelY, "available mobs", colors_white, colors_gray)
  286.    drawText(panelX+1, panelY+1, meItems[1]["entity"], colors_lime, colors_gray)
  287.        drawText(panelX+1, panelY+2, meItems[2]["entity"], colors_lime, colors_gray)
  288.         drawText(panelX+1, panelY+3, meItems[3]["entity"], colors_lime, colors_gray)
  289.          drawText(panelX+1, panelY+4, meItems[4]["entity"], colors_lime, colors_silver)
  290.           drawText(panelX+1, panelY+5, meItems[5]["entity"], colors_lime, colors_gray)
  291.            drawText(panelX+1, panelY+6, meItems[6]["entity"], colors_lime, colors_gray)
  292.      drawText(panelX+1, panelY+7, "NONE", colors_lime, colors_gray)
  293.   elseif navigateMobsListSelected == 5 then
  294.     drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  295.      drawText(panelX+6, panelY, "available mobs", colors_white, colors_gray)
  296.    drawText(panelX+1, panelY+1, meItems[1]["entity"], colors_lime, colors_gray)
  297.        drawText(panelX+1, panelY+2, meItems[2]["entity"], colors_lime, colors_gray)
  298.         drawText(panelX+1, panelY+3, meItems[3]["entity"], colors_lime, colors_gray)
  299.          drawText(panelX+1, panelY+4, meItems[4]["entity"], colors_lime, colors_gray)
  300.           drawText(panelX+1, panelY+5, meItems[5]["entity"], colors_lime, colors_silver)
  301.            drawText(panelX+1, panelY+6, meItems[6]["entity"], colors_lime, colors_gray)
  302.      drawText(panelX+1, panelY+7, "NONE", colors_lime, colors_gray)
  303.   elseif navigateMobsListSelected == 6 then
  304.     drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  305.      drawText(panelX+6, panelY, "available mobs", colors_white, colors_gray)
  306.    drawText(panelX+1, panelY+1, meItems[1]["entity"], colors_lime, colors_gray)
  307.        drawText(panelX+1, panelY+2, meItems[2]["entity"], colors_lime, colors_gray)
  308.         drawText(panelX+1, panelY+3, meItems[3]["entity"], colors_lime, colors_gray)
  309.          drawText(panelX+1, panelY+4, meItems[4]["entity"], colors_lime, colors_gray)
  310.           drawText(panelX+1, panelY+5, meItems[5]["entity"], colors_lime, colors_gray)
  311.            drawText(panelX+1, panelY+6, meItems[6]["entity"], colors_lime, colors_silver)
  312.      drawText(panelX+1, panelY+7, "NONE", colors_lime, colors_gray)
  313.   elseif navigateMobsListSelected == 7 then
  314.     drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  315.      drawText(panelX+6, panelY, "available mobs", colors_white, colors_gray)
  316.    drawText(panelX+1, panelY+1, meItems[1]["entity"], colors_lime, colors_gray)
  317.        drawText(panelX+1, panelY+2, meItems[2]["entity"], colors_lime, colors_gray)
  318.         drawText(panelX+1, panelY+3, meItems[3]["entity"], colors_lime, colors_gray)
  319.          drawText(panelX+1, panelY+4, meItems[4]["entity"], colors_lime, colors_gray)
  320.           drawText(panelX+1, panelY+5, meItems[5]["entity"], colors_lime, colors_gray)
  321.            drawText(panelX+1, panelY+6, meItems[6]["entity"], colors_lime, colors_gray)
  322.      drawText(panelX+1, panelY+7, "NONE", colors_lime, colors_silver)
  323.  
  324.   end
  325.  
  326.  
  327.  
  328.  
  329.  drawButton("DN", panelX-5, panelY+5, 3, navigateMobSelection_DN, _, colors_orange, colors_lime, true)
  330.  drawButton("UP", panelX-5, panelY+1, 3, navigateMobSelection_UP, _, colors_orange, colors_lime, true)
  331.  
  332.  
  333.  end
  334.  
  335.  
  336. end
  337.  
  338.  
  339.  
  340.  
  341. function drawMobSpawnerInfoPanel()
  342. local panelX = 111
  343. local panelY  = 11
  344. local panelSizeX = 24
  345. local panelSizeY = 5
  346.  
  347.  
  348.  drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_silver)
  349. if  navigateMobsListSelected <7 then
  350.   drawText(panelX+1, panelY+1, meItems[navigateMobsListSelected]["entity"], colors_magenta, colors_silver)
  351. elseif navigateMobsListSelected == 7 then
  352.  drawText(panelX+1, panelY+1, "NONE", colors_magenta, colors_silver)
  353.  
  354. end
  355.  
  356. end
  357.  
  358. function drawMobSpawnerControlPanel ()
  359. local panelX = 74
  360. local panelY  = 4
  361. local panelSizeX = 62
  362. local panelSizeY = 40
  363.  
  364.  
  365. drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_white)
  366.  
  367.     drawStorageInfoPanel()
  368.      drawAvailableMobsListPanel()
  369.      drawMobSpawnerInfoPanel()
  370.     drawMobSpawnerControls()
  371.     drawMobCrusherIndicatorLights()
  372.     drawMobSpawnerIndicatorLights()
  373. end
  374.  
  375. function drawMobCrusherIndicatorLights()
  376. local panelX = 80
  377. local panelY  = 20
  378. local panelSizeX = 55
  379. local panelSizeY = 10
  380.  
  381.   --drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  382.  
  383.      drawLine(panelX+1, panelY+1, 10, 7, colors_white)
  384.       drawLight1(panelX+3, panelY+3, 6, 2)
  385.        drawText(panelX+3, panelY+6, "crusher", colors_black, colors_white)
  386.         drawText(panelX+3, panelY+7, "control", colors_black, colors_white)
  387.  
  388.  
  389. end
  390.  
  391. function drawMobSpawnerIndicatorLights()
  392. local panelX = 90
  393. local panelY  = 20
  394. local panelSizeX = 55
  395. local panelSizeY = 10
  396.  
  397.   --drawLine(panelX, panelY, panelSizeX, panelSizeY, colors_gray)
  398.    drawLine(panelX+1, panelY+1, 10, 7, colors_white)
  399.    drawLight2(panelX+3, panelY+3, 6, 2)
  400.     drawText(panelX+3, panelY+6, "spawner", colors_black, colors_white)
  401.      drawText(panelX+3, panelY+7, "control", colors_black, colors_white)
  402.  
  403.  
  404. end
  405.  
  406. function drawMobSpawnerControls ()
  407. local panelX = 81
  408. local panelY  = 37
  409. local panelSizeX = 58
  410. local panelSizeY = 16
  411.  
  412.   drawButton("crushers", panelX+1, panelY+1, 3, toggleCrusher, _, colors_cyan, colors_green, true)
  413.  
  414.   drawButton("spawner", panelX+12, panelY+1, 3, toggleSpawner, _, colors_cyan, colors_green, true)
  415.   drawButton("tttt", panelX+30, panelY-19, 3,toggleSpawner , _, colors_magenta, colors_green, true)
  416. end
  417.  
  418.  
  419. function drawUIForScreen2()
  420.     drawCorridorAccessPanel()
  421.  
  422. end
  423.  
  424. function drawUIForScreen1()
  425.  
  426.   drawCorridorAccessPanel()
  427.  
  428. drawMobSpawnerControlPanel ()
  429.  
  430.    
  431. end
  432.  
  433. function touchCheck()
  434.   touchLocation,touchName, touchX, touchY = event.pull(0.01, "touch")
  435. end
  436.  
  437. -------------/\--------------
  438. ------ functions for UI -----
  439. -----------------------------
  440.  
  441. ----------------------------
  442. --- functions for buttons --
  443. -------------\/-------------
  444.  
  445.  
  446. function toggleCrusher()
  447.  
  448.   if not isRedstoneChannelOpen(2) then
  449.    lightToggle1 = true
  450.    openRedstoneChannel(2)
  451.   else
  452.    lightToggle1 = false
  453.    closeRedstoneChannel(2)
  454.   end
  455.  
  456. end
  457.  
  458. function toggleSpawner()
  459.  
  460.   if isRedstoneChannelOpen(7) then
  461.    lightToggle2 = false
  462.    closeRedstoneChannel(7)
  463.   else
  464.    lightToggle2 = true
  465.    openRedstoneChannel(7)
  466.   end
  467.  
  468. end
  469.  
  470. function navigateMobSelection_DN()
  471.  if navigateMobsListSelected <8 then
  472.    navigateMobsListSelected = navigateMobsListSelected +1
  473.  end
  474.  
  475.   if navigateMobsListSelected ==8 then
  476.    navigateMobsListSelected = 1
  477.  end
  478. end
  479.  
  480. function navigateMobSelection_UP()
  481.  if navigateMobsListSelected >0 then
  482.    navigateMobsListSelected = navigateMobsListSelected -1
  483.  end
  484.  
  485.   if navigateMobsListSelected ==0 then
  486.    navigateMobsListSelected = 7
  487.  end
  488. end
  489.  
  490.  
  491. function openCoridorDoor()
  492.  openRedstoneChannel(0)
  493. end
  494.  
  495. function closeCoridorDoor()
  496.  closeRedstoneChannel(0)
  497. end
  498.  
  499.  
  500. function closeAllRedstoneChannels()
  501.  closeRedstoneChannel(0)
  502.  closeRedstoneChannel(1)
  503.  closeRedstoneChannel(2)
  504.  closeRedstoneChannel(3)
  505.  closeRedstoneChannel(4)
  506.  closeRedstoneChannel(5)
  507.  closeRedstoneChannel(6)
  508.  closeRedstoneChannel(7)
  509.  closeRedstoneChannel(8)
  510.  closeRedstoneChannel(9)
  511.  closeRedstoneChannel(10)
  512.  closeRedstoneChannel(11)
  513.  closeRedstoneChannel(12)
  514.  closeRedstoneChannel(13)
  515.  closeRedstoneChannel(14)
  516.  closeRedstoneChannel(15)
  517. end
  518.  
  519.  
  520.  
  521.  
  522. function getCurrentEssenceInStorage()
  523.   if meFluids[1] == nil then
  524.    return "0"
  525.   else
  526.    return meFluids[1]["amount"]
  527.   end
  528. end
  529.  
  530.  
  531. ------------/\--------------
  532. --- functions for buttons --
  533. ----------------------------
  534.  
  535.  
  536.  
  537.  
  538. clearBothScreens()
  539. closeAllRedstoneChannels()
  540.  
  541. while true do
  542.    
  543.    touchCheck() -- returns x and y coords of cursor when screen is clicked
  544.    swichToScreen1() -- swiches to primary screen
  545.    drawUIForScreen1() -- draws UI for primary screen
  546.  
  547.    if isPlayerInCorridor () then -- if player is in coridor then
  548.     touchCheck() -- returns x and y coords of cursor when screen is clicked
  549.     swichToScreen2() -- swiches to secondary screen
  550.     drawUIForScreen2() -- draws UI for secondary screen
  551.    else
  552.     clearSecondaryScreen()
  553.     swichToScreen1() -- swiches to primary screen
  554.    end
  555.  
  556. drawText(1, 1, tostring(navigateMobsListSelected), colors_cyan, colors_black)
  557.  os.sleep(0.0)
  558. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement