-- imports
local cl = require("collect")
local tu = require("turn")
-- definition
local function goTo(x, y, z, xd, zd)
while depth > y do
if turtle.up() then
depth = depth - 1
elseif turtle.digUp() or turtle.attackUp() then
cl.collect()
else
sleep(0.5)
end
end
if xPos > x then
while xDir ~= -1 do
tu.turnLeft()
end
while xPos > x do
if turtle.forward() then
xPos = xPos - 1
elseif turtle.dig() or turtle.attack() then
cl.collect()
else
sleep(0.5)
end
end
elseif xPos < x then
while xDir ~= 1 do
tu.turnLeft()
end
while xPos < x do
if turtle.forward() then
xPos = xPos + 1
elseif turtle.dig() or turtle.attack() then
cl.collect()
else
sleep(0.5)
end
end
end
if zPos > z then
while zDir ~= -1 do
tu.turnLeft()
end
while zPos > z do
if turtle.forward() then
zPos = zPos - 1
elseif turtle.dig() or turtle.attack() then
cl.collect()
else
sleep(0.5)
end
end
elseif zPos < z then
while zDir ~= 1 do
tu.turnLeft()
end
while zPos < z do
if turtle.forward() then
zPos = zPos + 1
elseif turtle.dig() or turtle.attack() then
cl.collect()
else
sleep(0.5)
end
end
end
while depth < y do
if turtle.down() then
depth = depth + 1
elseif turtle.digDown() or turtle.attackDown() then
cl.collect()
else
sleep(0.5)
end
end
while zDir ~= zd or xDir ~= xd do
tu.turnLeft()
end
end
-- export
return { goTo = goTo }
Comments