local tArgs = { ... } if #tArgs ~= 1 then print( "Usage: tunnel " ) return end -- Mine in a quarry pattern until we hit something we can't dig local length = tonumber( tArgs[1] ) if length < 1 then print( "Tunnel length must be positive" ) return end local depth = 0 local collected = 0 local function tryPlaceTorch() turtle.select(2) turtle.place() end local function collect() collected = collected + 1 if math.fmod(collected, 25) == 0 then print( "Mined "..collected.." items." ) end end local function tryDig() while turtle.detect() do if turtle.dig() then collect() sleep(0.5) else return false end end return true end local function tryDigUp() while turtle.detectUp() do if turtle.digUp() then collect() sleep(0.5) else return false end end return true end local function refuel() local fuelLevel = turtle.getFuelLevel() if fuelLevel == "unlimited" or fuelLevel > 0 then return end local function tryRefuel() for n=1,16 do if turtle.getItemCount(n) > 0 then turtle.select(n) if turtle.refuel(1) then turtle.select(1) return true end end end turtle.select(1) return false end if not tryRefuel() then print( "Add more fuel to continue." ) while not tryRefuel() do sleep(1) end print( "Resuming Tunnel." ) end end local function tryUp() refuel() while not turtle.up() do if turtle.detectUp() then if not tryDigUp() then return false end elseif turtle.attackUp() then collect() else sleep( 0.5 ) end end return true end local function tryDown() refuel() while not turtle.down() do if turtle.detectDown() then if not tryDigDown() then return false end elseif turtle.attackDown() then collect() else sleep( 0.5 ) end end return true end local function tryForward() refuel() while not turtle.forward() do if turtle.detect() then if not tryDig() then return false end elseif turtle.attack() then collect() else sleep( 0.5 ) end end return true end local function tryPlace(slot) turtle.select(3) turtle.place() end local function tryPlaceUp(slot) turtle.select(3) turtle.placeUp() end local function tryPlaceDown(slot) turtle.select(3) turtle.placeDown() end print( "Tunnelling..." ) local materialSlot = 3 for n=1,length do tryForward() tryPlaceDown() turtle.turnLeft() tryForward() tryPlaceDown(3) tryPlace(3) tryUp() tryPlace(3) tryPlaceUp(3) turtle.turnRight() turtle.turnRight() tryForward() tryPlaceUp(3) tryForward() tryPlaceUp(3) tryPlace(3) tryDown() tryPlace(3) tryPlaceDown(3) turtle.turnRight() turtle.turnRight() tryForward() turtle.turnRight() end print( "Returning to start..." ) -- Return to where we started turtle.turnLeft() turtle.turnLeft() while length > 0 do if tryForward() then length = length - 1 else turtle.dig() end end turtle.turnRight() turtle.turnRight() print( "Tunnel complete." ) print( "Mined "..collected.." items total." )