Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tunnel Mining Program for ComputerCraft Turtle
- -- Define the width and height of the tunnel
- local width = 3
- local height = 3
- -- Function to refuel the turtle if it has fuel items
- local function refuel()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(1) then
- print("Refueled.")
- return true
- end
- end
- return false
- end
- -- Function to check fuel and halt if out of fuel
- local function checkFuel()
- if turtle.getFuelLevel() == 0 then
- print("Out of fuel. Attempting to refuel...")
- if not refuel() then
- print("Still out of fuel. Please add fuel items.")
- return false
- end
- end
- return true
- end
- -- Function to dig a 3x3 tunnel
- local function digTunnel()
- while true do
- for h = 1, height do
- for w = 1, width do
- if not checkFuel() then return end
- turtle.dig()
- turtle.forward()
- if h < height then
- turtle.digUp()
- turtle.up()
- end
- end
- for w = 1, width do
- if not checkFuel() then return end
- if w < width then
- turtle.back()
- end
- if h < height then
- turtle.down()
- end
- end
- end
- turtle.turnRight()
- if not checkFuel() then return end
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- -- Start digging the tunnel
- print("Starting to dig 3x3 tunnel...")
- digTunnel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement