Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function getFaceTo()
- local pos0 = vector.new(gps.locate())
- turtle.forward()
- local pos1 = vector.new(gps.locate())
- local dist = pos1 - pos0
- turtle.back()
- local faceto = ""
- if dist.x > 0 then
- faceto = "west"
- elseif dist.x < 0 then
- faceto = "east"
- elseif dist.z > 0 then
- faceto = "north"
- else
- faceto = "south"
- end
- return faceto
- end
- local function forBack(dist)
- d = dist
- if d < 0 then
- d = -d
- end
- for i=1, d do
- if dist > 0 then
- turtle.forward()
- else
- turtle.back()
- end
- end
- end
- local function upDown(dist)
- d = dist
- if d < 0 then
- d = -d
- end
- for i=1, d do
- if dist > 0 then
- turtle.up()
- else
- turtle.down()
- end
- end
- end
- local function moveAxisX(faceto, curpos, target)
- local dist = target - curpos
- if faceto == "north" then
- turtle.turnLeft()
- forBack(dist.x)
- turtle.turnRight()
- elseif faceto == "south" then
- turtle.turnRight()
- forBack(dist.x)
- turtle.turnLeft()
- elseif faceto == "east" then
- turtle.turnLeft()
- turtle.turnLeft()
- forBack(dist.x)
- turtle.turnRight()
- turtle.turnRight()
- else
- forBack(dist.x)
- end
- end
- local function moveAxisZ(faceto, curpos, target)
- local dist = target - curpos
- if faceto == "north" then
- forBack(dist.z)
- elseif faceto == "south" then
- turtle.turnLeft()
- turtle.turnLeft()
- forBack(dist.z)
- turtle.turnRight()
- turtle.turnRight()
- elseif faceto == "east" then
- turtle.turnLeft()
- forBack(dist.z)
- turtle.turnRight()
- else
- turtle.turnRight()
- forBack(dist.z)
- turtle.turnLeft()
- end
- end
- local function moveAxisY(curpos, target)
- local dist = target - curpos
- upDown(dist.y)
- end
- local function dispStatus(pos, target, faceto)
- print("pos:"..tostring(pos))
- print("faceTo:"..faceto)
- print("dist:"..tostring(target - pos))
- end
- rednet.open("left")
- while true do
- local sid, msg, dis = rednet.receive()
- name, x, y, z = msg:match("([^,]+),([^,]+),([^,]+),([^,]+)")
- print(name..":"..x..":"..y..":"..z)
- if name == os.getComputerLabel() then
- curpos = vector.new(gps.locate())
- faceto = getFaceTo()
- x = tonumber(x)
- y = tonumber(y)
- z = tonumber(z)
- target = vector.new(x, y, z)
- moveAxisZ(faceto, curpos, target)
- moveAxisY(curpos, target)
- moveAxisX(faceto, curpos, target)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment