Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Created by: pastebin.com/u/clintwk
- local function progHelp()
- print( "Usage: " )
- print( shell.getRunningProgram().." <length> (branches) (L or R)" )
- print( "Place path blocks in slot 1!" )
- end
- local tArgs = { ... }
- if #tArgs <= 3 and #tArgs > 0 then
- if #tArgs == 2 then
- print( "Must put argument for branch direction (L) or (R)" )
- progHelp()
- return
- end
- else
- progHelp()
- return
- end
- -- Mine in a quarry pattern until we hit something we can't dig
- if not tonumber( tArgs[1] ) then
- print( "Tunnel length must be a positive number" )
- progHelp()
- return
- end
- local length = tonumber( tArgs[1] )
- local branches = 1
- local direction = "L"
- if length < 1 then
- print( "Tunnel length must be a positive number" )
- progHelp()
- return
- end
- if #tArgs == 3 then
- if not tonumber( tArgs[2] ) then
- print( "Branches must be a positive number" )
- progHelp()
- return
- end
- branches = tonumber( tArgs[2] )
- if branches < 1 then
- print( "Number of branches must be a positive number" )
- progHelp()
- return
- end
- direction = tArgs[3]
- if direction ~= "L" and direction ~= "l" and direction ~= "R" and direction ~= "r" then
- print( "Please enter the direction you would like your branches to go (either L or R)" )
- progHelp()
- return
- end
- if direction == "L" or direction == "l" then
- direction = "L"
- else
- direction = "R"
- end
- end
- local depth = 0
- local collected = 0
- 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.2)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- collect()
- sleep(0.2)
- 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.2 )
- 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.2 )
- end
- end
- return true
- end
- print( "Tunnelling..." )
- local function tunnel(tunStart, tunEnd)
- for n=tunStart,tunEnd do
- turtle.placeDown()
- tryDigUp()
- turtle.suck()
- if n<length then
- tryDig()
- if not tryForward() then
- print( "Aborting Tunnel." )
- break
- end
- else
- print( "Tunnel complete." )
- end
- end
- end
- local function newBranch()
- tunnel(1, 3)
- if direction == "L" then
- turtle.turnLeft()
- direction = "R"
- else
- turtle.turnRight()
- direction = "L"
- end
- end
- local function connectBranch()
- if direction == "L" then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- tunnel(1, 2)
- turtle.turnRight()
- turtle.turnRight()
- tunnel(1, 2)
- end
- for b=1,branches do
- tunnel(1, length)
- if b ~= 1 then
- connectBranch()
- end
- if b ~= branches then
- if b == 1 then
- if direction == "L" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- newBranch()
- end
- end
- --[[
- print( "Returning to start..." )
- -- Return to where we started
- turtle.turnLeft()
- turtle.turnLeft()
- while depth > 0 do
- if turtle.forward() then
- depth = depth - 1
- else
- turtle.dig()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- ]]
- print( "Tunnel complete." )
- print( "Mined "..collected.." items total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement