Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local scanner = peripheral.wrap("back")
- local delay = 3 -- Scanning delay (seconds)
- -- Target Definitions - choose ONE of these options:
- -- OPTION 1: Single block type
- -- local targetBlock = "minecraft:iron_ore"
- -- local isMultipleTargets = false
- -- OPTION 2: Multiple block types (finds clusters of ANY of these blocks connected together)
- local targetBlocks = {
- "allthemodium:allthemodium_ore",
- "allthemodium:allthemodium_slate_ore",
- "minecraft:ancient_debris"
- }
- local isMultipleTargets = true
- -- Function to check if a block is a target
- local function isTargetBlock(blockName)
- if isMultipleTargets then
- for _, targetName in pairs(targetBlocks) do
- if blockName == targetName then
- return true
- end
- end
- return false
- else
- return blockName == targetBlock
- end
- end
- -- Checks if two blocks are adjacent (including diagonals)
- local function areConnected(a, b)
- local dx, dy, dz =
- math.abs(a.x - b.x),
- math.abs(a.y - b.y),
- math.abs(a.z - b.z)
- return (dx <= 1 and dy <= 1 and dz <= 1)
- end
- -- Finds clusters of connected blocks
- local function findClusters(blocks)
- local clusters = {}
- local visited = {}
- for i, block in pairs(blocks) do
- if not visited[i] and isTargetBlock(block.name) then
- local cluster = {}
- local stack = {block}
- visited[i] = true
- while #stack > 0 do
- local current = table.remove(stack)
- table.insert(cluster, current)
- -- Check neighboring blocks
- for j, neighbor in pairs(blocks) do
- if not visited[j] and isTargetBlock(neighbor.name) and areConnected(current, neighbor) then
- visited[j] = true
- table.insert(stack, neighbor)
- end
- end
- end
- if #cluster >= 2 then
- table.insert(clusters, cluster)
- end
- end
- end
- return clusters
- end
- -- Formats cardinal directions
- local function getDirectionString(x, y, z)
- local dirX = (x > 0) and "EAST" or "WEST"
- local dirZ = (z > 0) and "SOUTH" or "NORTH"
- local dirY = (y > 0) and "UP" or "DOWN"
- return string.format("%d %s, %d %s, %d %s",
- math.abs(x), dirX,
- math.abs(z), dirZ,
- math.abs(y), dirY
- )
- end
- -- Get display name for current targets
- local function getTargetDisplayName()
- if isMultipleTargets then
- if #targetBlocks <= 2 then
- -- If just a couple targets, show them all
- return table.concat(targetBlocks, " & ")
- else
- -- If many targets, show count
- return #targetBlocks .. " different ores"
- end
- else
- return targetBlock
- end
- end
- -- Main loop
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- -- Display target block info
- term.setTextColor(colors.yellow)
- print("SCANNING FOR: ")
- term.setTextColor(colors.lime)
- print(getTargetDisplayName())
- -- Countdown
- term.setTextColor(colors.orange)
- print("\nScanning in...")
- for i = delay, 1, -1 do
- term.setTextColor(i % 2 == 0 and colors.red or colors.yellow)
- term.write(tostring(i) .. (i > 1 and "... " or ""))
- sleep(1)
- end
- -- Scan and detect clusters
- local blocks = scanner.scan(16)
- if not blocks then
- term.setTextColor(colors.red)
- print("Scanner error!")
- sleep(delay)
- goto continue
- end
- local clusters = findClusters(blocks)
- -- Display results
- if #clusters > 0 then
- term.setTextColor(colors.green)
- print(string.format("\nFound %d cluster(s)!", #clusters))
- for i, cluster in ipairs(clusters) do
- -- Pick the first block to navigate to
- local target = cluster[1]
- term.setTextColor(colors.cyan)
- print("\n[Cluster " .. i .. " - " .. #cluster .. " blocks]")
- term.setTextColor(colors.lightBlue)
- print("Block type: " .. target.name)
- print("Navigate to:")
- term.setTextColor(colors.white)
- print(getDirectionString(target.x, target.y, target.z))
- end
- else
- term.setTextColor(colors.red)
- print("\nNo clusters found.")
- end
- term.setTextColor(colors.gray)
- print("\nRescanning...")
- sleep(delay)
- ::continue::
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement