Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function placeTorch()
- for slot = 1, 16 do
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail and itemDetail.name == "minecraft:torch" then
- turtle.select(slot)
- if turtle.placeDown() then
- return true
- end
- end
- end
- return false
- end
- local function checkAndDig()
- while turtle.detect() do
- turtle.dig()
- sleep(0.5)
- end
- end
- local function mineTunnel(length)
- -- Check if length is valid
- if length < 1 then
- print("Length must be greater than zero.")
- return
- end
- local torchCounter = 0
- -- Mine the tunnel
- for i = 1, length do
- checkAndDig()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- -- Increment torch counter
- torchCounter = torchCounter + 1
- -- Place torch every 10 blocks
- if torchCounter == 10 then
- if not placeTorch() then
- print("No torches left to place!")
- end
- torchCounter = 0
- end
- -- Mine the left side of the tunnel
- turtle.turnLeft()
- checkAndDig()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- turtle.turnRight()
- -- Move to the right side of the tunnel
- turtle.turnRight()
- turtle.forward()
- checkAndDig()
- turtle.forward()
- turtle.digUp()
- turtle.digDown()
- turtle.turnLeft()
- -- Return to original orientation
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- -- Move to the next row
- if i < length then
- turtle.forward()
- end
- end
- end
- -- Main program
- local args = {...}
- local length = tonumber(args[1])
- if not length then
- print("Usage: tunnel <length>")
- return
- end
- mineTunnel(length)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement