Advertisement
Marlingaming

CC Tweaked Turtle Movement Manager

Feb 25th, 2022 (edited)
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.41 KB | None | 0 0
  1. local tArg = {...}
  2. local X, Y, Z = gps.getPosition()
  3. local Direction
  4.  
  5. local Directions = {"N","E","S","W"}
  6. function GetDirection()
  7. local X1, Y1, Z1 = gps.getPosition()
  8. repeat
  9. turtle.turnRight()
  10. until turtle.detect() == false
  11. turtle.forward()
  12. local X2, Y2, Z2 = gps.getPosition()
  13. if X1 > X2 then
  14. Direction = "W"
  15. elseif X1 < X2 then
  16. Direction = "E"
  17. elseif Z1 > Z2 then
  18. Direction = "S"
  19. elseif Z1 < Z2 then
  20. Direction = "N"
  21. end
  22. turtle.backward()
  23. end
  24.  
  25. function TurnTurtle(i)
  26. local I
  27. if Direction == "N" then I = 1 end
  28. if Direction == "E" then I = 2 end
  29. if Direction == "S" then I = 3 end
  30. if Direction == "W" then I = 4 end
  31. for t = 1, i do
  32. turtle.turnRight()
  33. if I == 4 then I = 1 else I = I + 1 end
  34. end
  35. Direction = Directions[I]
  36. end
  37.  
  38. function setDirection(D)
  39. local I
  40. if Direction == "N" then I = 1 end
  41. if Direction == "E" then I = 2 end
  42. if Direction == "S" then I = 3 end
  43. if Direction == "W" then I = 4 end
  44. repeat
  45. turtle.turnRight()
  46. if I == 4 then I = 1 else I = I + 1 end
  47. Direction = Directions[I]
  48. until Direction == D
  49. end
  50.  
  51. GetDirection()
  52. while true do
  53. X, Y, Z = gps.getPosition()
  54. if Y > tArg[2] then turtle.down() elseif Y < tArg[2] then turtle.up() end
  55. if turtle.detect() == true then
  56. local i = 0
  57. repeat
  58. TurnTurtle(1)
  59. i = i + 1
  60. until turtle.detect() == false or i == 4
  61. if i = 4 and turtle.detectup() == false then turtle.up() Y = Y + 1 end
  62. end
  63. if Direction == "N" or Direction == "S" and Z ~= tArg[3] then
  64. if Z > tArg[3] then
  65. if Direction == "N" then
  66. TurnTurtle(2)
  67. end
  68. turtle.forward()
  69. elseif Z < tArg[3] then
  70. if Direction == "S" then
  71. TurnTurtle(2)
  72. end
  73. turtle.forward()
  74. end
  75. elseif Direction == "E" or Direction == "W" and X ~= tArg[1] then
  76. if X > tArg[1] then
  77. if Direction == "E" then
  78. TurnTurtle(2)
  79. end
  80. turtle.forward()
  81. elseif X < tArg[1] then
  82. if Direction == "W" then
  83. TurnTurtle(2)
  84. end
  85. turtle.forward()
  86. end
  87. end
  88. if Y > tArg[2] then assert(turtle.down()) elseif Y < tArg[2] then assert(turtle.up())
  89. if X == tArg[1] and Y == tArg[2] and Z == tArg[3] then break end
  90. end
  91.  
  92. setDirection(tArg[4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement