Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local geo = peripheral.find("geoScanner")
- if not geo then
- print("Geo Scanner not found.")
- return
- end
- local oreSymbols = {
- ["allthemodium:allthemodium_slate_ore"] = { symbol = "A", color = colors.yellow, priority = 5 },
- ["allthemodium:vibranium_ore"] = { symbol = "V", color = colors.green, priority = 4 },
- ["allthemodium:nether_vibranium_ore"] = { symbol = "V", color = colors.green, priority = 4 },
- ["allthemodium:other_vibranium_ore"] = { symbol = "V", color = colors.green, priority = 4 },
- ["allthemodium:unobtainium_ore"] = { symbol = "U", color = colors.purple, priority = 3 },
- ["lootr:lootr_chest"] = { symbol = "C", color = colors.brown, priority = 2 },
- ["lootr:lootr_barrel"] = { symbol = "C", color = colors.brown, priority = 2 },
- ["lootr:lootr_trapped_chest"] = { symbol = "C", color = colors.red, priority = 2 },
- ["minecraft:spawner"] = { symbol = "S", color = colors.blue, priority = 1 },
- ["qua:lootr_shulker"] = { symbol = "C", color = colors.brown, priority = 2 }
- }
- local function calculateDistance(x1, z1, x2, z2)
- return math.sqrt((x2 - x1) ^ 2 + (z2 - z1) ^ 2)
- end
- local function drawMap(playerX, playerZ, ores)
- term.clear()
- local cursorY = 1
- for y = -8, 8 do
- term.setCursorPos(1, cursorY)
- cursorY = cursorY + 1
- for x = -13, 12 do
- local oreSymbol = " "
- local oreColor = colors.white -- Default color for empty spots
- for _, ore in ipairs(ores) do
- if ore.x == playerX + x and ore.z == playerZ + y then
- local oreInfo = oreSymbols[ore.name]
- oreSymbol = oreInfo.symbol or "?"
- oreColor = oreInfo.color
- break
- end
- end
- term.setTextColor(oreColor) -- Set color before writing the symbol
- term.write(oreSymbol)
- end
- end
- term.setCursorPos(14, 9)
- term.setTextColor(colors.white) -- Set "X" color to white
- term.write("\7")
- term.setCursorPos(14, 1)
- term.write("N")
- term.setCursorPos(1, 9)
- term.write("W")
- term.setCursorPos(26, 9)
- term.write("E")
- term.setCursorPos(14, 17)
- term.write("S")
- end
- local function findClosestOre(ores, playerX, playerZ)
- local closestOre = nil
- local closestDistance = nil
- local highestPriority = nil
- for _, ore in ipairs(ores) do
- local distance = calculateDistance(playerX, playerZ, ore.x, ore.z)
- local oreInfo = oreSymbols[ore.name]
- -- Check if the ore has a higher priority or is closer
- if closestOre == nil or
- (oreInfo.priority > highestPriority) or
- (oreInfo.priority == highestPriority and distance < closestDistance) then
- closestOre = ore
- closestDistance = distance
- highestPriority = oreInfo.priority
- end
- end
- return closestOre, closestDistance
- end
- local function drawArrows(ores, playerX, playerZ)
- for x = -13, 12 do
- for _, ore in ipairs(ores) do
- if ore.z < playerZ - 8 and ore.x == playerX + x then
- term.setCursorPos(x + 14, 1)
- term.write("\24")
- end
- end
- end
- for x = -13, 12 do
- for _, ore in ipairs(ores) do
- if ore.z > playerZ + 8 and ore.x == playerX + x then
- term.setCursorPos(x + 14, 17)
- term.write("\25")
- end
- end
- end
- for y = -8, 8 do
- for _, ore in ipairs(ores) do
- if ore.x < playerX - 13 and ore.z == playerZ + y then
- term.setCursorPos(1, y + 9)
- term.write("\27")
- end
- end
- end
- for y = -8, 8 do
- for _, ore in ipairs(ores) do
- if ore.x > playerX + 12 and ore.z == playerZ + y then
- term.setCursorPos(26, y + 9)
- term.write("\26")
- end
- end
- end
- end
- local function scanAndDisplay()
- local playerPos = { x = 0, y = 0, z = 0 }
- while true do
- local blocks = geo.scan(16)
- if blocks and #blocks > 0 then
- local ores = {}
- for _, block in ipairs(blocks) do
- if oreSymbols[block.name] then
- table.insert(ores, { x = block.x, z = block.z, y = block.y or "unknown", name = block.name })
- end
- end
- drawMap(playerPos.x, playerPos.z, ores)
- drawArrows(ores, playerPos.x, playerPos.z)
- local closestOre, closestDistance = findClosestOre(ores, playerPos.x, playerPos.z)
- -- Check if closestOre is not nil
- if closestOre then
- local closestOreInfo = oreSymbols[closestOre.name]
- local closestSymbol = closestOreInfo and closestOreInfo.symbol or "?"
- term.setCursorPos(1, 18)
- term.clearLine()
- term.setTextColor(closestOreInfo.color) -- Set the text color for the symbol
- term.write("Closest " .. closestSymbol .. " distance: " .. math.floor(closestDistance))
- local heightInfo = closestOre.y == "unknown" and "unknown" or tostring(closestOre.y - playerPos.y)
- term.setCursorPos(1, 19)
- term.clearLine()
- term.setTextColor(closestOreInfo.color) -- Set the text color for the symbol
- term.write("Closest " .. closestSymbol .. " height: " .. heightInfo)
- else
- term.setCursorPos(1, 18)
- term.clearLine()
- term.write("No closest ore found.")
- end
- end
- sleep(1)
- end
- end
- scanAndDisplay()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement