Advertisement
SpaceRanger4321

Untitled

Mar 26th, 2022
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. local ores = {
  2. ["minecraft:diamond_ore"] = 10,
  3. ["minecraft:emerald_ore"] = 10,
  4. ["minecraft:gold_ore"] = 8,
  5. ["minecraft:redstone_ore"] = 5,
  6. ["minecraft:lapis_ore"] = 5,
  7. ["minecraft:iron_ore"] = 2,
  8. ["minecraft:coal_ore"] = 1
  9. }
  10.  
  11. local colours = {
  12. ["minecraft:coal_ore"] = { 150, 150, 150 },
  13. ["minecraft:iron_ore"] = { 255, 150, 50 },
  14. ["minecraft:lava"] = { 150, 75, 0 },
  15. ["minecraft:gold_ore"] = { 255, 255, 0 },
  16. ["minecraft:diamond_ore"] = { 0, 255, 255 },
  17. ["minecraft:redstone_ore"] = { 255, 0, 0 },
  18. ["minecraft:lapis_ore"] = { 0, 50, 255 },
  19. ["minecraft:emerald_ore"] = { 0, 255, 0 }
  20. }
  21. local modules = peripheral.find("neuralInterface")
  22. if not modules then error("Must have a neural interface", 0) end
  23. if not modules.hasModule("plethora:scanner") then error("The block scanner is missing", 0) end
  24. if not modules.hasModule("plethora:glasses") then error("The overlay glasses are missing", 0) end
  25.  
  26. local canvas = modules.canvas()
  27. canvas.clear()
  28.  
  29. local block_text = {}
  30. local blocks = {}
  31. for x = -scannerRange, scannerRange, 1 do
  32. block_text[x] = {}
  33. blocks[x] = {}
  34.  
  35. for z = -scannerRange, scannerRange, 1 do
  36. block_text[x][z] = canvas.addText({ 0, 0 }, " ", 0xFFFFFFFF, size)
  37. blocks[x][z] = { y = nil, block = nil }
  38. end
  39. end
  40.  
  41. canvas.addText({ offsetX, offsetY }, "^", 0xFFFFFFFF, size * 2)
  42.  
  43. local function scan()
  44. while true do
  45. local scanned_blocks = modules.scan()
  46. for x = -scannerRange, scannerRange do
  47. for z = -scannerRange, scannerRange do
  48. local best_score, best_block, best_y = -1
  49. for y = -scannerRange, scannerRange do
  50. local scanned = scanned_blocks[scannerWidth ^ 2 * (x + scannerRange) + scannerWidth * (y + scannerRange) + (z + scannerRange) + 1]
  51. if scanned then
  52. local new_score = ores[scanned.name]
  53. if new_score and new_score > best_score then
  54. best_block = scanned.name
  55. best_score = new_score
  56. best_y = y
  57. end
  58. end
  59. end
  60.  
  61. -- Update our block table with this information.
  62. blocks[x][z].block = best_block
  63. blocks[x][z].y = best_y
  64. end
  65. end
  66. sleep(scanInterval)
  67. end
  68. end
  69.  
  70. local function render()
  71. while true do
  72. local meta = modules.getMetaOwner and modules.getMetaOwner()
  73. local angle = meta and math.rad(-meta.yaw % 360) or math.rad(180)
  74. for x = -scannerRange, scannerRange do
  75. for z = -scannerRange, scannerRange do
  76. local text = block_text[x][z]
  77. local block = blocks[x][z]
  78.  
  79. if block.block then
  80. local px = math.cos(angle) * -x - math.sin(angle) * -z
  81. local py = math.sin(angle) * -x + math.cos(angle) * -z
  82.  
  83. local sx = math.floor(px * size * cellSize)
  84. local sy = math.floor(py * size * cellSize)
  85. text.setPosition(offsetX + sx, offsetY + sy)
  86. text.setText(tostring(block.y))
  87. text.setColor(table.unpack(colours[block.block]))
  88. else
  89. text.setText(" ")
  90. end
  91. end
  92. end
  93.  
  94. sleep(renderInterval)
  95. end
  96. end
  97.  
  98. parallel.waitForAll(render, scan)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement