Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- data entry --
- local Args = {...}
- if #Args ~= 1 then
- print("Usage: stair <distance>")
- return
- end
- -- check fuel level --
- function checkfuel()
- if turtle.getFuelLevel() < 80 then
- print("Add coal on inventory!")
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount > 0 then
- turtle.select( n )
- if turtle.refuel(1) then
- print( "New Fuel level is "..turtle.getFuelLevel() )
- end
- end
- end
- end
- end
- -- vars --
- dist = tonumber ( Args[1] )
- posI = tonumber ( Args[1] )
- -- Checks --
- if dist < 1 then
- print ("Please enter a positive number!")
- return
- end
- -- funcs --
- -- part 1 --
- function func1()
- checkfuel()
- if turtle.detect() then
- turtle.dig()
- if turtle.detectDown() then
- turtle.digDown()
- turtle.forward()
- func2()
- end
- else
- if turtle.detectDown() then
- turtle.digDown()
- turtle.down()
- dist = dist - 1
- if turtle.detect() then
- turtle.dig()
- turtle.forward()
- end
- func2()
- else
- turtle.down()
- dist = dist -1
- fBuild()
- end
- end
- end
- function func2()
- if turtle.detect() then
- turtle.dig()
- if turtle.detectDown() then
- turtle.digDown()
- turtle.down()
- dist = dist - 1
- end
- end
- end
- -- build down--
- function fBuild()
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount > 0 then
- turtle.select( n )
- if turtle.placeDown() then
- turtle.forward()
- end
- end
- end
- end
- function fReturn()
- turtle.turnRight()
- turtle.turnRight()
- while posI > 0 do
- turtle.up()
- turtle.forward()
- posI = posI - 1
- end
- if posI == 0 then
- for n=1,16 do
- local nCount = turtle.getItemCount(n)
- if nCount > 0 then
- turtle.select( n )
- turtle.drop(nCount)
- end
- end
- end
- end
- -- program --
- term.clear()
- print ("========= starting excavation ========")
- print( "Fuel level is "..turtle.getFuelLevel() )
- while dist > 0 do
- func1()
- end
- if dist == 0 then
- fReturn()
- end
Advertisement
Add Comment
Please, Sign In to add comment