Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 3 then
- print( "Usage: tunnel3 <width> <height> <depth>\nfor now, start in the bottom-left corner!" )
- return
- end
- -- Mine in a quarry pattern until we hit something we can't dig
- local width = tonumber( tArgs[1] )
- local height = tonumber( tArgs[2] )
- local length = tonumber( tArgs[3] )
- if length < 1 or height < 1 or width < 1 then
- print( "Tunnel dimensions must be positive" )
- return
- 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.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 tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() 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
- os.pullEvent( "turtle_inventory" )
- 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
- print( "Tunnelling..." )
- for n=1,length do
- --turtle.placeDown()
- if n%2 == 1 then --we're in bottom left corner
- for x=1, width do
- if (x+width%2)%2 == 0 then --we're at bottom of column
- for y=1, height do
- tryDigUp()
- tryUp()
- end --now at top of column
- else --we're at top of column
- for y=1, height do
- tryDigDown()
- tryDown()
- end --now at bottom of column
- end
- turtle.turnRight()
- tryDig()
- tryForward()
- turtle.turnLeft()
- end --in next column to right
- else --we're in right corner
- for x=1, width do
- if (x+width%2)%2 == 0 then --we're in top of column
- for y=1, height do
- tryDigDown()
- tryDown()
- end --now at bottom of column
- else --we're in bottom of column
- for y=1, height do
- tryDigUp()
- tryUp()
- end --now at top of column
- end
- turtle.turnLeft()
- tryDig()
- tryForward()
- turtle.turnRight()
- end --now in next column to left
- end
- if n<length then
- tryDig()
- if not tryForward() then
- print( "Aborting Tunnel." )
- break
- end
- else
- print( "Tunnel complete." )
- 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