Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- local lengthSet = false
- local bridgeSet = false
- local input
- local length
- local bridge
- print("Profondeur ? (int)")
- while lengthSet == false do
- input = io.read()
- input = tonumber( input )
- if input > 0 then
- length = tonumber( input )
- lengthSet = true
- else
- print("La profondeur doit ĂȘtre un entier non nul")
- end
- end
- print("Pont ? (Y/N)")
- while bridgeSet == false do
- input = io.read()
- if input == "Y" or input == "y" then
- bridge = true
- bridgeSet = true
- elseif input == "N" or input == "n" then
- bridge = false
- bridgeSet = true
- else
- print("Oui ou non (Y/N)")
- end
- end
- local depth = 0
- local collected = 0
- local steps = 0
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 1) == 0 then
- term.clear()
- term.setCursorPos(1,1)
- print( "Mined "..collected.." items." )
- print("Steps so far :" .. steps)
- end
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- collect()
- sleep(0.3)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- collect()
- sleep(0.3)
- 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.3 )
- 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.3 )
- 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.3 )
- end
- end
- steps = steps +1
- return true
- end
- print( "Tunnelling..." )
- for n=1,length do
- if bridge then
- turtle.placeDown()
- end
- tryDigUp()
- turtle.turnLeft()
- tryDig()
- tryUp()
- tryDig()
- turtle.turnRight()
- turtle.turnRight()
- tryDig()
- tryDown()
- tryDig()
- turtle.turnLeft()
- 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." )
- print("Steps done in total :" .. steps)
Advertisement
Add Comment
Please, Sign In to add comment