Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Computer Program
- local modem = peripheral.find("modem") or error("No modem found")
- local geoScanner = peripheral.find("geoScanner") or error("No geo scanner found")
- modem.open(10000)
- -- Get computer's GPS coordinates
- local compX, compY, compZ = gps.locate()
- if not compX then error("GPS signal not found") end
- print("Computer position:", compX, compY, compZ)
- -- Function to convert scanner coordinates to world coordinates
- local function toWorldCoords(relX, relY, relZ)
- return compX + relX, compY + relY, compZ + relZ
- end
- -- Function to perform chunked scanning
- local function chunkedScan(radius)
- local scanData = {}
- local chunkSize = 8 -- GeoScanner's maximum scan size
- local scansPerformed = 0
- local totalScans = math.ceil((radius * 2 + 1) ^ 3 / chunkSize ^ 3)
- for x = -radius, radius, chunkSize do
- for y = -radius, radius, chunkSize do
- for z = -radius, radius, chunkSize do
- local chunkRadius = math.min(chunkSize / 2, radius - math.max(math.abs(x), math.abs(y), math.abs(z)))
- if chunkRadius > 0 then
- scansPerformed = scansPerformed + 1
- print(string.format("Performing scan %d of %d", scansPerformed, totalScans))
- local scan = geoScanner.scan(chunkRadius, x + chunkRadius, y + chunkRadius, z + chunkRadius)
- if scan then
- for _, block in ipairs(scan) do
- local wx, wy, wz = toWorldCoords(x + block.x, y + block.y, z + block.z)
- scanData[wx..","..wy..","..wz] = block.name
- end
- print(string.format("Chunk scan successful. Found %d blocks.", #scan))
- else
- print(string.format("Chunk scan failed at (%d, %d, %d)", x, y, z))
- end
- end
- end
- end
- end
- return scanData
- end
- -- Function to send command to turtle
- local function sendCommand(cmd, data)
- modem.transmit(10000, 10000, {command = cmd, data = data})
- end
- -- Main program
- print("Enter scan radius:")
- local radius = tonumber(read())
- if not radius or radius <= 0 then
- error("Invalid scan radius")
- end
- print("Scanning with radius " .. radius .. "...")
- local scanData = chunkedScan(radius)
- local blockCount = 0
- for _ in pairs(scanData) do blockCount = blockCount + 1 end
- print("Scan complete. Found " .. blockCount .. " blocks.")
- print("Enter the ore to mine (e.g., minecraft:diamond_ore):")
- local oreToMine = read()
- local oreLocations = {}
- for coords, blockName in pairs(scanData) do
- if blockName == oreToMine then
- local x, y, z = coords:match("(-?%d+),(-?%d+),(-?%d+)")
- table.insert(oreLocations, {x = tonumber(x), y = tonumber(y), z = tonumber(z)})
- end
- end
- if #oreLocations == 0 then
- print("No " .. oreToMine .. " found in scan area.")
- else
- print("Found " .. #oreLocations .. " " .. oreToMine .. " deposits.")
- print("Sending data to turtle...")
- sendCommand("scan_data", scanData)
- sendCommand("mine_targets", oreLocations)
- print("Waiting for mining operation to complete...")
- while true do
- local event, side, channel, replyChannel, message = os.pullEvent("modem_message")
- if channel == 10000 then
- if message.command == "target_mined" then
- print("Ore mined at:", message.x, message.y, message.z)
- elseif message.command == "mining_complete" then
- print("All ores mined. Operation complete.")
- break
- elseif message.command == "mining_failed" then
- print("Mining operation failed:", message.reason)
- break
- end
- end
- end
- end
- print("Program complete.")
Advertisement
Add Comment
Please, Sign In to add comment