Advertisement
vitalik228

[B.U.G OS] (/lib/Bug_Os/Programs/HoloMaps/holomaps.lua)

Apr 11th, 2022 (edited)
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.47 KB | None | 0 0
  1. -- HOLO_MAPS minecraft-opencomputers-mod
  2. -- HOLOGRAMM MUST BE PLACED FACING TO Z- COORDINATE
  3. -- COPYRIGHT BY vitalik228. https://pastebin.com/u/vitalik228
  4. -- Green block - maybe diamonds/gold or coal
  5. -- Blue block - maybe water/lava
  6. -- More features - in the future
  7.  
  8. local shell = require("shell")
  9. shell.execute("pastebin get iKzRve2g /lib/forms.lua -f")
  10. local component = require("component")
  11. local gpu = component.gpu
  12. local geolyzer = component.geolyzer
  13. local hologram = component.hologram
  14. local forms = require("forms")
  15. local showground = false
  16.  
  17. gpu.setBackground(0x000000) gpu.fill(1,1, 160, 50, " ")
  18.  
  19.   sizex = 4
  20.   sizez = 4
  21.   sizey = 4
  22.    
  23.   sizeox = 0
  24.   sizeoz = 0
  25.   sizeoy = 0
  26.  
  27. --GUI  start
  28. hologram.clear()
  29. gpu.setResolution(160,50)
  30. forms=require("forms")
  31. forms.ignoreAll()
  32.  
  33. Form1=forms.addForm()
  34. Form1.border=0
  35.  
  36. MainForm=forms.addForm()
  37. MainForm.H=35
  38. MainForm.W=60
  39. MainForm.left=53
  40. MainForm.color=14792345
  41. MainForm.top=8
  42.  
  43. ExitButton=MainForm:addButton(58,1,"", function() forms.stop() end)
  44. ExitButton.color=16711680
  45. ExitButton.W=3
  46.  
  47. function startonClick(self, user)
  48. if sizeox == 0 or sizeoy == 0 or sizeoz == 0 then
  49.           Label8.visible = true
  50.           MainForm:redraw()
  51.           StartButton.color = 0x606060
  52.           StartButton:redraw()
  53. else
  54.            Label8.visible = false  
  55.            MainForm:redraw()
  56.            StartButton.color = 0xBDE000
  57.            StartButton:redraw()
  58.            hologram.clear()
  59.            scan()
  60.   end
  61. end
  62.  
  63. StartButton=MainForm:addButton(22,27,"Scan", startonClick)
  64. StartButton.H=5
  65. StartButton.W=16
  66. StartButton.color = 0x606060
  67.  
  68. MainText=MainForm:addLabel(2,1,"HoloMaps")
  69. MainText.fontColor=0
  70. MainText.centered=true
  71. MainText.W=7
  72. MainText.color=14792345
  73.  
  74. Edit1=MainForm:addEdit(20,18, function() sizeoy = tonumber(Edit1.text) end)
  75. Edit1.fontColor=0
  76. Edit1.color=14792345
  77. Edit1.text="Max heigth(Y): 10"
  78.  
  79. Edit2=MainForm:addEdit(20,12, function() sizeox = tonumber(Edit2.text) end)
  80. Edit2.fontColor=0
  81. Edit2.color=14792345
  82. Edit2.text="Max long(X): 10"
  83.  
  84. Label2=MainForm:addLabel(21,17,"Height")
  85. Label2.fontColor=0
  86. Label2.centered=true
  87. Label2.W=6
  88. Label2.color=14792345
  89.  
  90. Label6=MainForm:addLabel(21,11,"Long")
  91. Label6.fontColor=0
  92. Label6.centered=true
  93. Label6.W=4
  94. Label6.color=14792345
  95.  
  96. Edit3=MainForm:addEdit(20,6, function() sizeoz = tonumber(Edit3.text) end)
  97. Edit3.fontColor=0
  98. Edit3.color=14792345
  99. Edit3.text="Max width(Z): 10"
  100.  
  101. Label1=MainForm:addLabel(21,5,"Width")
  102. Label1.fontColor=0
  103. Label1.centered=true
  104. Label1.W=5
  105. Label1.color=14792345
  106.  
  107. Label8=MainForm:addLabel(21,3,"Please select zone!")
  108. Label8.visible = false
  109. Label8.color=0xff0000
  110.  
  111. function Button1Click(self, user)
  112.         if Button1.color == 0x00ff00 then
  113.              showground = false
  114.              Button1.color = 0xff0000
  115.        else
  116.              showground = true
  117.              Button1.color = 0x00ff00
  118.        end
  119.     Button1:redraw()
  120. end
  121.  
  122. Label3=MainForm:addLabel(21,22,"Show Ground?:")
  123. Label3.fontColor=0
  124. Label3.centered=true
  125. Label3.W=13
  126. Label3.color=14792345
  127. Button1=MainForm:addButton(37,22,"", function() Button1Click() end)
  128. Button1.W=2
  129. Button1.color=0xFF0000
  130. --GUI END
  131. --Scan
  132.  
  133. --print("Scanning...") --If GUI - off
  134. function scan()
  135.   offsetz = -16
  136.   offsetx = -16
  137.   offsety = -36
  138. if sizeox ~= 0 or sizeoy ~= 0 or sizeoz ~= 0 then
  139. os.sleep(1)
  140.  
  141.   local map = {}
  142.   --local scanData = {}
  143.    
  144.   local y = 0
  145.   local x = 0
  146.   local z = 0
  147.   local i = 0
  148.   for y = 1, sizeoy do
  149.       --offset Offset)
  150.       offsety = offsety + 4
  151.       for x = 1, sizeox do
  152.             --offset Offset)
  153.             offsetx = offsetx + 4
  154.              for z = 1, sizeoz do
  155.                     offsetz = offsetz + 4
  156.                     --print("Scan...  ", "X: ", offsetx, "Y: ", offsety, "Z: ", offsetz) --If GUI - off
  157.                     --print("sizeox ", sizeox, " sizeoz ", sizeoz, " sizeoy", sizeoy, "X: ", x, "Y: ", y, "Z: ", z) --If GUI - off
  158.                     local scanData = geolyzer.scan(offsetx, offsetz, offsety, sizex, sizez, sizey)
  159.                     local i = 1
  160.                      for y = 0, sizey - 1 do
  161.                        for z = 0, sizez - 1 do
  162.                          for x = 0, sizex - 1 do
  163.                              map[i] = {posx = offsetx + x, posy = offsety + y, posz = offsetz + z, hardness = scanData[i]}
  164.                               i = i + 1
  165.                             end
  166.                          end
  167.                       end
  168.                         for i = 1, sizex*sizez*sizey do
  169.                               if(map[i].hardness > 0) then
  170.                                     if(map[i].hardness > 3.5) then
  171.                                       if (map[i].hardness > 10) then
  172.                                     hologram.set(map[i].posx+20, map[i].posy+30, map[i].posz+20, 3)
  173.                                        else
  174.                                         hologram.set(map[i].posx+20, map[i].posy+30, map[i].posz+20, 2)
  175.                                       end
  176.                                     else
  177.                                         hologram.set(map[i].posx+20, map[i].posy+30, map[i].posz+20, showground)
  178.                                     end
  179.                                     --print(map[i].posx, map[i].posy, map[i].posz, map[i].hardness) --If GUI - off
  180.                                     --print("STEP") --If GUI - off
  181.                                 end
  182.                        end
  183.                       --offset Offset)
  184.                        if z >= sizeoz then
  185.                             offsetz = -16
  186.                       end
  187.                       scanData = nil
  188.                        os.sleep(0.04)  
  189.              end
  190.           if x >= sizeox then
  191.              offsetx = -16
  192.          end
  193.        end
  194.     end
  195. end
  196.    StartButton.color = 0x40F70C
  197.    StartButton:redraw()
  198. end
  199. forms.run(MainForm)
  200. gpu.setBackground(0x000000) gpu.fill(1,1, 160, 50, " ")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement