Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local targs = { ... }
- if #targs ~= 1 then
- print( "Usage: tunnel <distance>" )
- return
- end
- local digFor = tonumber( targs[1] )
- if digFor < 1 then
- print("Excavate distance must be positive" )
- end
- local distance = 0;
- local torchCount = turtle.getItemCount(1)
- if torchCount == 0 then
- print("Please place torches in first slot")
- end
- local height = 0
- local direction = 0
- local function checkFuel()
- local fuelNeeded = (distance*2) + (digFor-distance)*6 + 1
- if (turtle.getFuelLevel() < fuelNeeded)
- print("Need more fuel")
- return
- end
- end
- local function full()
- for n=2, 16 do
- if nCount == 0 then
- return false
- end
- end
- return true
- end
- local function dumpItems()
- for n=2,16 do
- turtle.select(n)
- turtle.drop()
- end
- turtle.select(1)
- end
- local function returnCargo()
- if direction = 1 then
- turtle.turnLeft()
- elseif direction = 2 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.turnLeft()
- end
- for h=0, height do
- turtle.down()
- end
- for n=0, distance do
- turtle.forward()
- end
- dumpItems()
- turtle.turnLeft()
- turtle.turnLeft()
- checkFuel()
- for n=0, distance do
- turtle.forward()
- end
- for h=0, height do
- turtle.up()
- end
- if direction = 1 then
- turtle.turnLeft()
- elseif direction = 2 then
- turtle.turnRight()
- end
- end
- local function digRow()
- while turtle.detect() then
- if turtle.dig() then
- if full() then
- returnCargo()
- end
- end
- end
- turtle.turnLeft()
- direction = 1
- while turtle.detect() then
- if turtle.dig() then
- if full() then
- returnCargo()
- end
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- direction = 2
- while turtle.detect() then
- if turtle.dig() then
- if full() then
- returnCargo()
- end
- end
- end
- turtle.turnLeft()
- direction = 0
- end
- local function tryUp()
- end
- local function tryForward()
- while not turtle.forward() do -- if we can't more forward
- if turtle.detect() then -- check if something there
- if turtle.dig() then -- attempt to dig
- if full() then
- returnCargo()
- end
- else
- return false
- end
- elseif turtle.attack() then
- if full() then
- returnCargo()
- end
- else
- sleep( 1 )
- end
- end
- distance = distance + 1
- return true
- end
- local function tryUp()
- while not turtle.up() do -- if we can't more forward
- if turtle.detect() then -- check if something there
- if turtle.digUp() then -- attempt to dig
- if full() then
- returnCargo()
- end
- else
- return false
- end
- elseif turtle.attack() then
- if full() then
- returnCargo()
- end
- else
- sleep( 1 )
- end
- end
- height = height + 1
- return true
- end
- checkFuel() -- make sure we have fuel
- local done = false
- while not done do
- for n=1, digFor do
- if not tryForward() then
- done = true
- break
- end
- digRow()
- if not tryUp() then
- done = true
- break
- end
- digRow()
- if not tryUp() then
- done = true
- break
- end
- digRow()
- turtle.down()
- turtle.down()
- height = 0
- end
- print( "Done Digging" )
- turtle.turnLeft()
- turtle.turnLeft()
- for n=0, distance do
- turtle.forward()
- end
- dumpItems()
Advertisement
Add Comment
Please, Sign In to add comment