Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local timeout = 10
- function forward()
- local t = 0
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- t = t + 1
- if t == timeout then return false end
- end
- return true
- end
- local function up()
- local t = 0
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- t = t + 1
- if t == timeout then return false end
- end
- return true
- end
- local function down()
- local t = 0
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- t = t + 1
- if t == timeout then return false end
- end
- return true
- end
- local function timesX(func, n)
- if func ~= nil then
- for i = 1, n do
- if not func() then return false end
- end
- end
- return true
- end
- local function shouldMove(x, z, dx, dz)
- return (x * dx > 0) or (z * dz > 0)
- end
- function goto(x, y, z)
- while turtle.y > y do if not down() then return false end end
- while turtle.y < y do if not up() then return false end end
- local xx = x - turtle.x
- local zz = z - turtle.z
- local dx, dz = turtle.dir()
- local f = shouldMove(xx, zz, dx, dz)
- local b = shouldMove(xx, zz, -dx, -dz)
- local l = shouldMove(xx, zz, dz, -dx)
- local r = shouldMove(xx, zz, -dz, dx)
- if f and not timesX(forward, xx * dx + zz * dz) then return false end
- if l then turtle.turnLeft() if not timesX(forward, xx * dz - zz * dx) then return false end end
- if r then turtle.turnRight() if not timesX(forward, zz * dx - xx * dz) then return false end end
- if b then
- if l then turtle.turnLeft()
- else
- if not r then turtle.turnRight() end
- turtle.turnRight()
- end
- if not timesX(forward, xx * -dx + zz * -dz) then return false end
- end
- return x == turtle.x and y == turtle.y and z == turtle.z
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement