Advertisement
TechManDylan

OreScanGPT

Jan 12th, 2025 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.85 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.         -- Get player metadata and calculate rotation angle
  88.         local meta = modules.getMetaOwner and modules.getMetaOwner()
  89.         local angle = meta and math.rad(-meta.yaw % 360) or math.rad(180)
  90.        
  91.         -- Calculate rotation matrices
  92.         local cosAngle = math.cos(angle)
  93.         local sinAngle = math.sin(angle)
  94.  
  95.         -- Debug: Print the player's angle
  96.         print("Player angle (yaw): " .. (meta and meta.yaw or "unknown"))
  97.  
  98.         -- Update the overlay display
  99.         for x = -scannerRange, scannerRange do
  100.             for z = -scannerRange, scannerRange do
  101.                 local text = block_text[x][z]
  102.                 local block = blocks[x][z]
  103.  
  104.                 if block.block then
  105.                     -- Rotate positions based on player's facing direction
  106.                     local rotatedX = cosAngle * x - sinAngle * z
  107.                     local rotatedZ = sinAngle * x + cosAngle * z
  108.  
  109.                     -- Convert rotated positions to screen coordinates
  110.                     local screenX = math.floor(rotatedX * size * cellSize)
  111.                     local screenY = math.floor(rotatedZ * size * cellSize)
  112.  
  113.                     -- Update text position and appearance
  114.                     text.setPosition(offsetX + screenX, offsetY + screenY)
  115.                     text.setText(tostring(block.y))
  116.                     text.setColor(table.unpack(colours[block.block]))
  117.  
  118.                     -- Debug: Log position updates
  119.                     print(("Block %s at (%d, %d) rendered at (%d, %d)"):format(
  120.                         block.block, x, z, screenX, screenY
  121.                     ))
  122.                 else
  123.                     -- Clear text for empty positions
  124.                     text.setText(" ")
  125.                 end
  126.             end
  127.         end
  128.  
  129.         -- Delay for rendering interval
  130.         sleep(renderInterval)
  131.     end
  132. end
  133.  
  134. parallel.waitForAll(render, scan)
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement