Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to place a torch behind the turtle
- local function placeTorch()
- turtle.select(2) -- Select torch slot
- turtle.place() -- Place torch
- end
- -- Function to drop items behind the turtle when inventory is full
- local function dropItems()
- for slot = 3, 16 do
- turtle.select(slot)
- turtle.drop()
- end
- end
- -- Main function to dig the tunnel
- local function digTunnel(length, resumeIfNoTorches)
- local torchInterval = 10
- local torchesAvailable = true
- local fuelLevel = turtle.getFuelLevel()
- for i = 1, length do
- -- Check fuel level and refuel if needed
- if fuelLevel == nil or fuelLevel <= 0 then
- print("Out of fuel!")
- -- Attempt to refuel
- if not turtle.refuel() then
- print("Unable to refuel!")
- return
- end
- fuelLevel = turtle.getFuelLevel() -- Update fuel level
- end
- -- Dig forward
- if not turtle.dig() then
- -- If unable to dig, try to move forward and dig again
- turtle.forward()
- turtle.dig()
- end
- -- Drop items behind the turtle if inventory is full
- if turtle.getItemCount(16) > 0 then
- dropItems()
- end
- -- Place torch every torchInterval blocks behind the turtle
- if torchesAvailable and i % torchInterval == 0 then
- if turtle.getItemCount(2) > 0 then
- placeTorch()
- else
- print("Out of torches!")
- if not resumeIfNoTorches then
- return
- end
- torchesAvailable = false
- end
- end
- -- Move up and clear any obstacles
- if not turtle.digUp() then
- turtle.up()
- end
- end
- end
- -- Main program
- local args = {...}
- local tunnelLength = tonumber(args[1])
- local resumeIfNoTorches = args[2] == "true"
- if tunnelLength == nil or tunnelLength <= 0 then
- print("Invalid tunnel length. Please provide a positive number as argument.")
- return
- end
- if tunnelLength == math.huge then
- tunnelLength = 999999999 -- Set a large finite number for infinite tunneling
- end
- print("Digging tunnel...")
- digTunnel(tunnelLength, resumeIfNoTorches)
- print("Tunneling complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement