Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dn = 15
- local length, walk = ...
- local delay = 0.25
- if length == nil then
- print("No length argument was given")
- return false -- Closes Program
- end
- if walk == 'true' then
- walk = true
- else
- walk = false
- end
- X = 0
- Y = 0
- Z = 0
- O = 0
- function left(q)
- if q == nil then q = 1 end
- for i=1,q do
- turtle.turnLeft()
- if O == 0 then
- O = 3
- else
- O = O - 1
- end
- end
- return true
- end
- function right(q)
- if q == nil then q = 1 end
- for i=1,q do
- turtle.turnRight()
- if O == 3 then
- O = 0
- else
- O = O + 1
- end
- end
- return true
- end
- function up(q)
- if q == nil then q = 1 end
- for i=1,q do
- while not turtle.up() do
- digUp()
- turtle.up()
- sleep(delay)
- end
- Y = Y + 1
- end
- return true
- end
- function down(q)
- if q == nil then q = 1 end
- for i=1,q do
- while not turtle.down() do
- digDown()
- turtle.attackDown()
- sleep(delay)
- end
- Y = Y - 1
- end
- return true
- end
- function forward(q)
- if q == nil then q = 1 end
- for i=1,q do
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- sleep(delay)
- end
- if O == 0 then
- X = X + 1
- elseif O == 1 then
- Z = Z + 1
- elseif O == 2 then
- X = X - 1
- elseif O == 3 then
- Z = Z - 1
- end
- end
- return true
- end
- function back()
- right()
- right()
- forward()
- left()
- left()
- return true
- end
- function orient(arg1)
- while arg1 ~= O do
- right()
- end
- return true
- end
- function dig()
- while turtle.detect() do
- turtle.dig()
- sleep(delay)
- end
- return true
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- sleep(delay)
- end
- return true
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- sleep(delay)
- end
- return true
- end
- function go(lx,ly,lz)
- if X < lx then
- orient(0)
- for i=1,(lx-X) do
- forward()
- end
- end
- if X > lx then
- orient(2)
- for i=1,X-lx do
- forward()
- end
- end
- if Y < ly then
- for i=1,ly-Y do
- up()
- end
- end
- if Y > ly then
- for i=1,Y-ly do
- down()
- end
- end
- if Z < lz then
- orient(1)
- for i=1,lz-Z do
- forward()
- end
- end
- if Z > lz then
- orient(3)
- for i=1,Z-lz do
- forward()
- end
- end
- end
- function deposit()
- for i=1,16 do
- turtle.select(i)
- while turtle.drop() == false and turtle.getItemCount() ~= 0 do
- sleep(1)
- end
- turtle.drop()
- end
- turtle.select(1)
- return true
- end
- function mine()
- dig()
- forward()
- digUp()
- digDown()
- up()
- left()
- dig()
- right(2)
- dig()
- down()
- dig()
- left(2)
- dig()
- down()
- dig()
- right(2)
- dig()
- left()
- up()
- end
- function check()
- if turtle.getItemCount(15) == 0 then
- return false
- else
- return true
- end
- end
- function notify(include)
- if X % dn == 0 and X ~= 0 then
- print("The turtle has traveled "..X.."/"..length+include.." blocks so far")
- end
- return true
- end
- local dni = 0
- if walk then
- while turtle.detect() == false do
- forward()
- dni = dni + 1
- notify(dni) -- Notifies Distance
- end
- end
- for i=1,length do
- mine()
- notify(dni) -- Notifies Distance
- if check() then -- Checks if turtle should deposit items
- local lx,ly,lz = X,Y,Z
- go(0,0,0)
- orient(2) -- Faces Chest
- deposit()
- orient(0)
- go(lx,ly,lz)
- end
- end
- go(0,0,0)
- orient(2)
- deposit()
- orient(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement