Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local completion = require "cc.completion"
- local scanner = peripheral.find("geoScanner")
- local args = { ... }
- if #args < 1 then
- printError("error: needs 1 argument (radius)")
- return
- end
- local radius = tonumber(args[1])
- if not radius then
- printError("error: invalid radius")
- return
- end
- local cost, err = scanner.cost(radius)
- if err then
- printError("error: when calculating cost: " .. err)
- return
- end
- print("Cost: " .. cost .. " FE")
- local function possiblyRefuel(cost)
- local fuel = turtle.getFuelLevel();
- if fuel ~= "unlimited" then
- print("Fuel: " .. fuel .. " FE")
- if cost > fuel then
- print("Energy deficit: " .. (fuel - cost) .. " FE")
- write("Refuel? [Yn] ")
- local choice = read()
- if choice == "" or choice == "y" or choice == "Y" then
- for i = 1, 16 do
- turtle.select(i)
- turtle.refuel()
- end
- print("Turtle refueled.")
- return possiblyRefuel(cost)
- else
- printError("error: not enough fuel")
- return false
- end
- end
- end
- return true
- end
- if not possiblyRefuel(cost) then return end
- if scanner.getScanCooldown and scanner.getScanCooldown() > 0 then
- print("Waiting for scanner cooldown (" .. scanner.getScanCooldown() .. "s)...")
- sleep(scanner.getScanCooldown() + 1)
- end
- print("Scanning...")
- local scanResult, err = scanner.scan(radius)
- if err then
- printError("error: when scanning: " .. err)
- return
- end
- print("Scan complete. Analyzing...")
- local totals = {}
- local sum = 0
- for i, block in ipairs(scanResult) do
- if totals[block.name] then
- totals[block.name] = totals[block.name] + 1
- else
- totals[block.name] = 1
- end
- sum = sum + 1
- end
- print("Scanned " .. sum .. " blocks. Results:")
- local TERM_ROWS = 13
- local row = 0
- for name, amount in pairs(totals) do
- print(" " .. name .. ": " .. amount)
- row = row + 1
- if row >= TERM_ROWS - 2 then
- read()
- row = 0
- print("Scanned " .. sum .. " blocks. Results:")
- end
- end
- local function get_keys(t)
- local keys = {}
- for key, _ in pairs(t) do
- table.insert(keys, key)
- end
- return keys
- end
- local keys = get_keys(totals)
- while true do
- write("Get positions of block? ")
- local result = read(nil, nil, function(s) return completion.choice(s, keys) end)
- if result == "" then
- break
- end
- if not totals[result] then
- printError("error: unknown block")
- else
- local row = 0
- for i, block in ipairs(scanResult) do
- if block.name == result then
- print(" " .. i .. ": (" .. block.x .. ", " .. block.y .. ", " .. block.z .. ")")
- row = row + 1
- if row >= TERM_ROWS - 1 then
- read()
- row = 0
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment