Advertisement
dadragon84

Ore Scanner

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