MtnMCG

geo scanning

Sep 18th, 2024 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. -- Find the Geo Scanner peripheral
  2. local geoScanner = peripheral.find("geoScanner")
  3.  
  4. if not geoScanner then
  5. print("No Geo Scanner found. Please attach one to the computer.")
  6. return
  7. end
  8.  
  9. -- List of ores to scan for
  10. local ores = {
  11. "minecraft:coal_ore", "minecraft:iron_ore", "minecraft:gold_ore",
  12. "minecraft:diamond_ore", "minecraft:emerald_ore", "minecraft:lapis_ore",
  13. "minecraft:redstone_ore", "minecraft:copper_ore", "minecraft:nether_quartz_ore",
  14. "minecraft:nether_gold_ore", "minecraft:ancient_debris",
  15. -- Deepslate variants
  16. "minecraft:deepslate_coal_ore", "minecraft:deepslate_iron_ore",
  17. "minecraft:deepslate_gold_ore", "minecraft:deepslate_diamond_ore",
  18. "minecraft:deepslate_emerald_ore", "minecraft:deepslate_lapis_ore",
  19. "minecraft:deepslate_redstone_ore", "minecraft:deepslate_copper_ore"
  20. }
  21.  
  22. -- Function to scan for a specific ore
  23. local function scanForOre(oreName)
  24. print("Scanning for " .. oreName .. "...")
  25.  
  26. -- Get the scan radius (this method returns the maximum scan radius)
  27. local scanRadius = geoScanner.getRadius()
  28.  
  29. -- Perform the scan
  30. local success, result = pcall(function()
  31. return geoScanner.scan(scanRadius)
  32. end)
  33.  
  34. if not success then
  35. print("Scan failed: " .. tostring(result))
  36. return
  37. end
  38.  
  39. -- Filter the results for the specific ore
  40. local oreLocations = {}
  41. for _, block in ipairs(result) do
  42. if block.name == oreName then
  43. table.insert(oreLocations, block)
  44. end
  45. end
  46.  
  47. -- Sort ore locations by distance (closest first)
  48. table.sort(oreLocations, function(a, b)
  49. return (a.x^2 + a.y^2 + a.z^2) < (b.x^2 + b.y^2 + b.z^2)
  50. end)
  51.  
  52. -- Display results
  53. if #oreLocations > 0 then
  54. print(string.format("Found %d locations of %s:", #oreLocations, oreName))
  55. for i, location in ipairs(oreLocations) do
  56. print(string.format("%d. x=%d, y=%d, z=%d", i, location.x, location.y, location.z))
  57. if i >= 5 then break end -- Limit to showing top 5 results
  58. end
  59. else
  60. print("No " .. oreName .. " found in scan range.")
  61. end
  62. end
  63.  
  64. -- Function to analyze the current chunk
  65. local function analyzeChunk()
  66. local result, err = geoScanner.chunkAnalyze()
  67.  
  68. if not result then
  69. print("Chunk analysis failed: " .. err)
  70. return
  71. end
  72.  
  73. print("Chunk Analysis Results:")
  74. for oreName, count in pairs(result) do
  75. print(string.format("%s: %d", oreName, count))
  76. end
  77. end
  78.  
  79. -- Function to display ore list with pagination
  80. local function displayOreList(page)
  81. local itemsPerPage = 10
  82. local startIndex = (page - 1) * itemsPerPage + 1
  83. local endIndex = math.min(startIndex + itemsPerPage - 1, #ores)
  84.  
  85. print("\nOre List (Page " .. page .. "/" .. math.ceil(#ores / itemsPerPage) .. "):")
  86. for i = startIndex, endIndex do
  87. print(i .. ". " .. ores[i])
  88. end
  89. print("\nN: Next Page, P: Previous Page, S: Select Ore, B: Back to Main Menu")
  90. end
  91.  
  92. -- Function to handle ore selection
  93. local function selectOre()
  94. local currentPage = 1
  95. while true do
  96. displayOreList(currentPage)
  97. local input = read():lower()
  98.  
  99. if input == "n" and currentPage * 10 < #ores then
  100. currentPage = currentPage + 1
  101. elseif input == "p" and currentPage > 1 then
  102. currentPage = currentPage - 1
  103. elseif input == "s" then
  104. print("Enter the number of the ore you want to scan for:")
  105. local oreChoice = tonumber(read())
  106. if ores[oreChoice] then
  107. return ores[oreChoice]
  108. else
  109. print("Invalid ore selection.")
  110. end
  111. elseif input == "b" then
  112. return nil
  113. else
  114. print("Invalid input. Please try again.")
  115. end
  116. end
  117. end
  118.  
  119. -- Main menu loop
  120. while true do
  121. print("\nGeo Scanner Menu:")
  122. print("1. Scan for specific ore")
  123. print("2. Analyze current chunk")
  124. print("3. Exit")
  125.  
  126. local choice = tonumber(read())
  127.  
  128. if choice == 1 then
  129. local selectedOre = selectOre()
  130. if selectedOre then
  131. scanForOre(selectedOre)
  132. end
  133. elseif choice == 2 then
  134. analyzeChunk()
  135. elseif choice == 3 then
  136. print("Exiting program.")
  137. break
  138. else
  139. print("Invalid choice. Please try again.")
  140. end
  141. end
Advertisement
Add Comment
Please, Sign In to add comment