Advertisement
yarmoam233

Ore finder2

Apr 13th, 2025 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local scanner = peripheral.wrap("back")
  2. local delay = 3 -- Scanning delay (seconds)
  3.  
  4. -- Target Definitions - choose ONE of these options:
  5.  
  6. -- OPTION 1: Single block type
  7. -- local targetBlock = "minecraft:iron_ore"
  8. -- local isMultipleTargets = false
  9.  
  10. -- OPTION 2: Multiple block types (finds clusters of ANY of these blocks connected together)
  11. local targetBlocks = {
  12.     "allthemodium:allthemodium_ore",
  13.     "allthemodium:allthemodium_slate_ore",
  14.     "minecraft:ancient_debris"
  15. }
  16. local isMultipleTargets = true
  17.  
  18. -- Function to check if a block is a target
  19. local function isTargetBlock(blockName)
  20.     if isMultipleTargets then
  21.         for _, targetName in pairs(targetBlocks) do
  22.             if blockName == targetName then
  23.                 return true
  24.             end
  25.         end
  26.         return false
  27.     else
  28.         return blockName == targetBlock
  29.     end
  30. end
  31.  
  32. -- Checks if two blocks are adjacent (including diagonals)
  33. local function areConnected(a, b)
  34.     local dx, dy, dz =
  35.         math.abs(a.x - b.x),
  36.         math.abs(a.y - b.y),
  37.         math.abs(a.z - b.z)
  38.     return (dx <= 1 and dy <= 1 and dz <= 1)
  39. end
  40.  
  41. -- Finds clusters of connected blocks
  42. local function findClusters(blocks)
  43.     local clusters = {}
  44.     local visited = {}
  45.    
  46.     for i, block in pairs(blocks) do
  47.         if not visited[i] and isTargetBlock(block.name) then
  48.             local cluster = {}
  49.             local stack = {block}
  50.             visited[i] = true
  51.            
  52.             while #stack > 0 do
  53.                 local current = table.remove(stack)
  54.                 table.insert(cluster, current)
  55.                
  56.                 -- Check neighboring blocks
  57.                 for j, neighbor in pairs(blocks) do
  58.                     if not visited[j] and isTargetBlock(neighbor.name) and areConnected(current, neighbor) then
  59.                         visited[j] = true
  60.                         table.insert(stack, neighbor)
  61.                     end
  62.                 end
  63.             end
  64.            
  65.             if #cluster >= 2 then
  66.                 table.insert(clusters, cluster)
  67.             end
  68.         end
  69.     end
  70.    
  71.     return clusters
  72. end
  73.  
  74. -- Formats cardinal directions
  75. local function getDirectionString(x, y, z)
  76.     local dirX = (x > 0) and "EAST" or "WEST"
  77.     local dirZ = (z > 0) and "SOUTH" or "NORTH"
  78.     local dirY = (y > 0) and "UP" or "DOWN"
  79.    
  80.     return string.format("%d %s, %d %s, %d %s",
  81.         math.abs(x), dirX,
  82.         math.abs(z), dirZ,
  83.         math.abs(y), dirY
  84.     )
  85. end
  86.  
  87. -- Get display name for current targets
  88. local function getTargetDisplayName()
  89.     if isMultipleTargets then
  90.         if #targetBlocks <= 2 then
  91.             -- If just a couple targets, show them all
  92.             return table.concat(targetBlocks, " & ")
  93.         else
  94.             -- If many targets, show count
  95.             return #targetBlocks .. " different ores"
  96.         end
  97.     else
  98.         return targetBlock
  99.     end
  100. end
  101.  
  102. -- Main loop
  103. while true do
  104.     term.clear()
  105.     term.setCursorPos(1, 1)
  106.    
  107.     -- Display target block info
  108.     term.setTextColor(colors.yellow)
  109.     print("SCANNING FOR: ")
  110.     term.setTextColor(colors.lime)
  111.     print(getTargetDisplayName())
  112.    
  113.     -- Countdown
  114.     term.setTextColor(colors.orange)
  115.     print("\nScanning in...")
  116.     for i = delay, 1, -1 do
  117.         term.setTextColor(i % 2 == 0 and colors.red or colors.yellow)
  118.         term.write(tostring(i) .. (i > 1 and "... " or ""))
  119.         sleep(1)
  120.     end
  121.    
  122.     -- Scan and detect clusters
  123.     local blocks = scanner.scan(16)
  124.     if not blocks then
  125.         term.setTextColor(colors.red)
  126.         print("Scanner error!")
  127.         sleep(delay)
  128.         goto continue
  129.     end
  130.    
  131.     local clusters = findClusters(blocks)
  132.    
  133.     -- Display results
  134.     if #clusters > 0 then
  135.         term.setTextColor(colors.green)
  136.         print(string.format("\nFound %d cluster(s)!", #clusters))
  137.         for i, cluster in ipairs(clusters) do
  138.             -- Pick the first block to navigate to
  139.             local target = cluster[1]
  140.             term.setTextColor(colors.cyan)
  141.             print("\n[Cluster " .. i .. " - " .. #cluster .. " blocks]")
  142.             term.setTextColor(colors.lightBlue)
  143.             print("Block type: " .. target.name)
  144.             print("Navigate to:")
  145.             term.setTextColor(colors.white)
  146.             print(getDirectionString(target.x, target.y, target.z))
  147.         end
  148.     else
  149.         term.setTextColor(colors.red)
  150.         print("\nNo clusters found.")
  151.     end
  152.    
  153.     term.setTextColor(colors.gray)
  154.     print("\nRescanning...")
  155.     sleep(delay)
  156.    
  157.     ::continue::
  158. end
  159.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement