se7enek

GeoLocator

May 30th, 2026 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local geo = peripheral.wrap("back")
  2.  
  3. if not geo then
  4.     print("Geo Scanner not found.")
  5.     return
  6. end
  7.  
  8. local oreSymbols = {
  9.     ["allthemodium:allthemodium_slate_ore"] = { symbol = "A", color = colors.yellow, priority = 5 },
  10.     ["allthemodium:vibranium_ore"] = { symbol = "V", color = colors.green, priority = 4 },
  11.     ["allthemodium:nether_vibranium_ore"] = { symbol = "V", color = colors.green, priority = 4 },
  12.     ["allthemodium:other_vibranium_ore"] = { symbol = "V", color = colors.green, priority = 4 },
  13.     ["minecraft:ancient_debris"] = { symbol = "N", color = colors.orange, priority = 3 },
  14.     ["lootr:lootr_chest"] = { symbol = "C", color = colors.brown, priority = 2 },
  15.     ["lootr:lootr_barrel"] = { symbol = "C", color = colors.brown, priority = 2 },
  16.     ["lootr:lootr_trapped_chest"] = { symbol = "C", color = colors.red, priority = 2 },
  17.     ["minecraft:spawner"] = { symbol = "S", color = colors.blue, priority = 1 },
  18.     ["minecraft:diamond_ore"] = { symbol = "D", color = colors.cyan, priority = 2 },
  19.     ["minecraft:deepslate_diamond_ore"] = { symbol = "D", color = colors.cyan, priority = 2 }
  20. }
  21.  
  22. local function calculateDistance(x1, z1, x2, z2)
  23.     return math.sqrt((x2 - x1) ^ 2 + (z2 - z1) ^ 2)
  24. end
  25.  
  26. local function drawMap(playerX, playerZ, ores)
  27.     term.clear()
  28.     local cursorY = 1
  29.  
  30.     for y = -8, 8 do
  31.         term.setCursorPos(1, cursorY)
  32.         cursorY = cursorY + 1
  33.         for x = -13, 12 do
  34.             local oreSymbol = " "
  35.             local oreColor = colors.white  -- Default color for empty spots
  36.  
  37.             for _, ore in ipairs(ores) do
  38.                 if ore.x == playerX + x and ore.z == playerZ + y then
  39.                     local oreInfo = oreSymbols[ore.name]
  40.                     oreSymbol = oreInfo.symbol or "?"
  41.                     oreColor = oreInfo.color
  42.                     break
  43.                 end
  44.             end
  45.  
  46.             term.setTextColor(oreColor)  -- Set color before writing the symbol
  47.             term.write(oreSymbol)
  48.         end
  49.     end
  50.  
  51.     term.setCursorPos(14, 9)
  52.     term.setTextColor(colors.white)  -- Set "X" color to white
  53.     term.write("\7")
  54.     term.setCursorPos(14, 1)
  55.     term.write("N")
  56.     term.setCursorPos(1, 9)
  57.     term.write("W")
  58.     term.setCursorPos(26, 9)
  59.     term.write("E")
  60.     term.setCursorPos(14, 17)
  61.     term.write("S")
  62. end
  63.  
  64. local function findClosestOre(ores, playerX, playerZ)
  65.     local closestOre = nil
  66.     local closestDistance = nil
  67.     local highestPriority = nil
  68.  
  69.     for _, ore in ipairs(ores) do
  70.         local distance = calculateDistance(playerX, playerZ, ore.x, ore.z)
  71.         local oreInfo = oreSymbols[ore.name]
  72.        
  73.         -- Check if the ore has a higher priority or is closer
  74.         if closestOre == nil or
  75.            (oreInfo.priority > highestPriority) or
  76.            (oreInfo.priority == highestPriority and distance < closestDistance) then
  77.             closestOre = ore
  78.             closestDistance = distance
  79.             highestPriority = oreInfo.priority
  80.         end
  81.     end
  82.  
  83.     return closestOre, closestDistance
  84. end
  85.  
  86. local function drawArrows(ores, playerX, playerZ)
  87.     for x = -13, 12 do
  88.         for _, ore in ipairs(ores) do
  89.             if ore.z < playerZ - 8 and ore.x == playerX + x then
  90.                 term.setCursorPos(x + 14, 1)
  91.                 term.write("\24")
  92.             end
  93.         end
  94.     end
  95.     for x = -13, 12 do
  96.         for _, ore in ipairs(ores) do
  97.             if ore.z > playerZ + 8 and ore.x == playerX + x then
  98.                 term.setCursorPos(x + 14, 17)
  99.                 term.write("\25")
  100.             end
  101.         end
  102.     end
  103.     for y = -8, 8 do
  104.         for _, ore in ipairs(ores) do
  105.             if ore.x < playerX - 13 and ore.z == playerZ + y then
  106.                 term.setCursorPos(1, y + 9)
  107.                 term.write("\27")
  108.             end
  109.         end
  110.     end
  111.     for y = -8, 8 do
  112.         for _, ore in ipairs(ores) do
  113.             if ore.x > playerX + 12 and ore.z == playerZ + y then
  114.                 term.setCursorPos(26, y + 9)
  115.                 term.write("\26")
  116.             end
  117.         end
  118.     end
  119. end
  120.  
  121. local function scanAndDisplay()
  122.     local playerPos = { x = 0, y = 0, z = 0 }
  123.     while true do
  124.         local blocks = geo.scan(16)
  125.         if blocks and #blocks > 0 then
  126.             local ores = {}
  127.             for _, block in ipairs(blocks) do
  128.                 if oreSymbols[block.name] then
  129.                     table.insert(ores, { x = block.x, z = block.z, y = block.y or "unknown", name = block.name })
  130.                 end
  131.             end
  132.             drawMap(playerPos.x, playerPos.z, ores)
  133.             drawArrows(ores, playerPos.x, playerPos.z)
  134.             local closestOre, closestDistance = findClosestOre(ores, playerPos.x, playerPos.z)
  135.            
  136.             -- Check if closestOre is not nil
  137.             if closestOre then
  138.                 local closestOreInfo = oreSymbols[closestOre.name]
  139.                 local closestSymbol = closestOreInfo and closestOreInfo.symbol or "?"
  140.  
  141.                 term.setCursorPos(1, 18)
  142.                 term.clearLine()
  143.                 term.setTextColor(closestOreInfo.color)  -- Set the text color for the symbol
  144.                 term.write("Closest " .. closestSymbol .. " distance: " .. math.floor(closestDistance))
  145.  
  146.                 local heightInfo = closestOre.y == "unknown" and "unknown" or tostring(closestOre.y - playerPos.y)
  147.                 term.setCursorPos(1, 19)
  148.                 term.clearLine()
  149.                 term.setTextColor(closestOreInfo.color)  -- Set the text color for the symbol
  150.                 term.write("Closest " .. closestSymbol .. " height: " .. heightInfo)
  151.             else
  152.                 term.setCursorPos(1, 18)
  153.                 term.clearLine()
  154.                 term.write("No closest ore found.")
  155.             end
  156.         end
  157.         sleep(1)
  158.     end
  159. end
  160.  
  161. scanAndDisplay()
Advertisement
Add Comment
Please, Sign In to add comment