Advertisement
TechManDylan

OreScanner

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