Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- local length = tonumber(args[1])
- local num_tunnels = tonumber(args[2]) or 1
- local spacing = tonumber(args[3]) or 3
- if not length or length < 1 or num_tunnels < 1 then
- print("Usage: tunnel_ancient <length> [num_tunnels=1] [spacing=3]")
- return
- end
- local ANCIENT = "minecraft:ancient_debris"
- local LAVA = "minecraft:lava"
- local NETH = "minecraft:netherrack"
- local MIN_FUEL = 200
- local nethSlot = nil
- local fuelSlots = {}
- -- -------- inventory / fuel --------
- local function fuelLevel()
- local f = turtle.getFuelLevel()
- return type(f) == "string" and math.huge or f
- end
- local function isFuel()
- return turtle.refuel(0)
- end
- local function rescanInventory()
- fuelSlots = {}
- nethSlot = nil
- for i = 1, 16 do
- local d = turtle.getItemDetail(i)
- if d then
- if d.name == ANCIENT then
- -- keep
- elseif d.name == NETH then
- if not nethSlot then
- nethSlot = i
- else
- turtle.select(i)
- turtle.drop()
- end
- else
- turtle.select(i)
- if isFuel() then
- fuelSlots[#fuelSlots + 1] = i
- else
- turtle.drop()
- end
- end
- end
- end
- turtle.select(1)
- end
- local function refuelFast()
- if fuelLevel() >= MIN_FUEL then return end
- for _, s in ipairs(fuelSlots) do
- if turtle.getItemCount(s) > 0 then
- turtle.select(s)
- turtle.refuel()
- if fuelLevel() >= MIN_FUEL then break end
- end
- end
- turtle.select(1)
- end
- local function selectNeth()
- if nethSlot and turtle.getItemCount(nethSlot) > 0 then
- turtle.select(nethSlot)
- return true
- end
- for i = 1, 16 do
- local d = turtle.getItemDetail(i)
- if d and d.name == NETH and turtle.getItemCount(i) > 0 then
- nethSlot = i
- turtle.select(i)
- return true
- end
- end
- return false
- end
- -- -------- two core ops --------
- -- navigate: dig solids (gravel-safe) then move. ignores liquids.
- local function navigate(detectFn, digFn, moveFn, attackFn)
- while detectFn() do
- digFn()
- end
- while not moveFn() do
- if attackFn then attackFn() end
- end
- end
- -- check: if air -> place neth; if lava -> place neth; if ancient -> dig then place neth
- local function check(inspectFn, digFn, placeFn)
- local ok, b = inspectFn()
- -- No block (air): fill it to make walkable/sealed
- if not ok then
- if selectNeth() then
- placeFn()
- turtle.select(1)
- end
- return
- end
- if not b then return end
- if b.name == ANCIENT then
- digFn()
- if selectNeth() then
- placeFn()
- turtle.select(1)
- end
- elseif b.name == LAVA then
- if selectNeth() then
- placeFn()
- turtle.select(1)
- end
- end
- end
- -- -------- directional wrappers --------
- local function navigateForward() navigate(turtle.detect, turtle.dig, turtle.forward, turtle.attack) end
- local function navigateUp() navigate(turtle.detectUp, turtle.digUp, turtle.up, turtle.attackUp) end
- local function navigateDown() navigate(turtle.detectDown, turtle.digDown, turtle.down, turtle.attackDown) end
- local function checkForward() check(turtle.inspect, turtle.dig, turtle.place) end
- local function checkUp() check(turtle.inspectUp, turtle.digUp, turtle.placeUp) end
- local function checkDown() check(turtle.inspectDown, turtle.digDown, turtle.placeDown) end
- -- -------- tunnel dig --------
- local function digTunnel(len)
- local upper = false
- for i = 1, len do
- refuelFast()
- -- move
- navigateForward()
- -- walls at current height
- turtle.turnLeft(); checkForward()
- turtle.turnRight(); turtle.turnRight(); checkForward()
- turtle.turnLeft()
- -- seal relevant walk surface at current height
- if upper then
- checkUp() -- ceiling
- else
- checkDown() -- floor
- end
- -- transition + walls + surface at new height
- if upper then
- navigateDown()
- upper = false
- turtle.turnLeft(); checkForward()
- turtle.turnRight(); turtle.turnRight(); checkForward()
- turtle.turnLeft()
- checkDown()
- else
- navigateUp()
- upper = true
- turtle.turnLeft(); checkForward()
- turtle.turnRight(); turtle.turnRight(); checkForward()
- turtle.turnLeft()
- checkUp()
- end
- if (i % 10) == 0 then rescanInventory() end
- end
- -- normalize to lower
- if upper then
- navigateDown()
- end
- end
- -- -------- main --------
- rescanInventory()
- for t = 1, num_tunnels do
- digTunnel(length)
- if t < num_tunnels then
- -- return to tunnel origin
- turtle.turnRight(); turtle.turnRight()
- for _ = 1, length do turtle.forward() end
- turtle.turnRight(); turtle.turnRight()
- -- shift right to next tunnel start
- turtle.turnRight()
- for _ = 1, spacing do navigateForward() end
- turtle.turnLeft()
- end
- end
- -- return to absolute start
- turtle.turnRight(); turtle.turnRight()
- for _ = 1, length do turtle.forward() end
- turtle.turnRight(); turtle.turnRight()
- if num_tunnels > 1 then
- turtle.turnLeft()
- for _ = 1, spacing * (num_tunnels - 1) do navigateForward() end
- turtle.turnRight()
- end
- print("Done. Returned to start.")
Advertisement