Advertisement
Guest User

Untitled

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