Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- printError( "Requires a Turtle" )
- return
- end
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: tunface <length>" )
- 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( "Facing length must be positive" )
- return
- end
- local depth = 0
- local item = 1
- local function count()
- length = length + 1
- if math.fmod(length, 10) == 0 then
- print( "Faced "..length.." section." )
- end
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() then
- sleep(0.1)
- 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 Facing." )
- end
- end
- local function charge()
- local function tryCharge()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- if turtle.getItemDetail(n).name == "chisel:cobblestone2" then
- turtle.select(n)
- return true
- end
- end
- end
- turtle.select(2)
- return false
- end
- if not tryCharge() then
- print( "Add more cobblestone to continue." )
- while not tryCharge() do
- os.pullEvent( "turtle_inventory" )
- end
- print( "Resuming Tunnel Facing." )
- end
- end
- local function chargeTorch()
- local function tryChargeTorch()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- if turtle.getItemDetail(n).name == "tconstruct:stone_torch" then
- turtle.select(n)
- return true
- end
- end
- end
- turtle.select(16)
- return false
- end
- if not tryChargeTorch() then
- print( "Add more torches to continue." )
- while not tryChargeTorch() do
- os.pullEvent( "turtle_inventory" )
- end
- print( "Resuming Tunnel Facing." )
- 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
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryBack()
- refuel()
- while not turtle.back() do
- sleep( 0.1 )
- 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
- else
- sleep( 0.1 )
- 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
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryPlace()
- refuel()
- charge()
- while not turtle.detect() do
- if turtle.place() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- local function tryPlaceUp()
- refuel()
- charge()
- while not turtle.detectUp() do
- if turtle.placeUp() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- local function tryPlaceDown()
- refuel()
- charge()
- while not turtle.detectDown() do
- if turtle.placeDown() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- local function tryPlaceTorch()
- refuel()
- chargeTorch()
- while not turtle.detectDown() do
- if turtle.placeDown() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- print( "Facing the tunnel..." )
- for n=1,length do
- tryDig()
- tryPlace()
- tryUp()
- tryDig()
- tryPlace()
- tryUp()
- if math.fmod(n, 7) == 0 then
- tryPlaceTorch()
- end
- tryDig()
- tryPlace()
- turtle.turnRight()
- turtle.turnRight()
- tryDigUp()
- tryPlaceUp()
- tryForward()
- tryDigUp()
- tryPlaceUp()
- tryDigDown()
- tryForward()
- tryDigUp()
- tryPlaceUp()
- tryDig()
- tryPlace()
- tryDown()
- tryDig()
- tryPlace()
- tryDown()
- tryDig()
- tryPlace()
- turtle.turnRight()
- turtle.turnRight()
- tryDigDown()
- tryPlaceDown()
- tryForward()
- tryDigDown()
- tryPlaceDown()
- tryForward()
- tryDigDown()
- tryPlaceDown()
- turtle.turnRight()
- tryForward()
- turtle.turnLeft()
- if n == length then
- print( "Tunnel facing complete." )
- end
- end
- print( "Tunnel facing complete." )
- print( "Faced "..length.." segments total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement