Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArg = {...}
- local X, Y, Z = gps.getPosition()
- local Direction
- local Directions = {"N","E","S","W"}
- function GetDirection()
- local X1, Y1, Z1 = gps.getPosition()
- repeat
- turtle.turnRight()
- until turtle.detect() == false
- turtle.forward()
- local X2, Y2, Z2 = gps.getPosition()
- if X1 > X2 then
- Direction = "W"
- elseif X1 < X2 then
- Direction = "E"
- elseif Z1 > Z2 then
- Direction = "S"
- elseif Z1 < Z2 then
- Direction = "N"
- end
- turtle.backward()
- end
- function TurnTurtle(i)
- local I
- if Direction == "N" then I = 1 end
- if Direction == "E" then I = 2 end
- if Direction == "S" then I = 3 end
- if Direction == "W" then I = 4 end
- for t = 1, i do
- turtle.turnRight()
- if I == 4 then I = 1 else I = I + 1 end
- end
- Direction = Directions[I]
- end
- function setDirection(D)
- local I
- if Direction == "N" then I = 1 end
- if Direction == "E" then I = 2 end
- if Direction == "S" then I = 3 end
- if Direction == "W" then I = 4 end
- repeat
- turtle.turnRight()
- if I == 4 then I = 1 else I = I + 1 end
- Direction = Directions[I]
- until Direction == D
- end
- GetDirection()
- while true do
- X, Y, Z = gps.getPosition()
- if Y > tArg[2] then turtle.down() elseif Y < tArg[2] then turtle.up() end
- if turtle.detect() == true then
- local i = 0
- repeat
- TurnTurtle(1)
- i = i + 1
- until turtle.detect() == false or i == 4
- if i = 4 and turtle.detectup() == false then turtle.up() Y = Y + 1 end
- end
- if Direction == "N" or Direction == "S" and Z ~= tArg[3] then
- if Z > tArg[3] then
- if Direction == "N" then
- TurnTurtle(2)
- end
- turtle.forward()
- elseif Z < tArg[3] then
- if Direction == "S" then
- TurnTurtle(2)
- end
- turtle.forward()
- end
- elseif Direction == "E" or Direction == "W" and X ~= tArg[1] then
- if X > tArg[1] then
- if Direction == "E" then
- TurnTurtle(2)
- end
- turtle.forward()
- elseif X < tArg[1] then
- if Direction == "W" then
- TurnTurtle(2)
- end
- turtle.forward()
- end
- end
- if Y > tArg[2] then assert(turtle.down()) elseif Y < tArg[2] then assert(turtle.up())
- if X == tArg[1] and Y == tArg[2] and Z == tArg[3] then break end
- end
- setDirection(tArg[4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement