Advertisement
Guest User

Untitled

a guest
Nov 14th, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. facing = 0
  2.  
  3. function checkFuel()
  4. fuel = turtle.getFuelLevel()
  5. if fuel < 10 then
  6. turtle.refuel(1)
  7. end
  8. end
  9.  
  10. function moveForward(num)
  11. for i = 0, num do
  12. turtle.forward()
  13. end
  14. end
  15.  
  16. function moveUp(num)
  17. for i = 0, num do
  18. turtle.up()
  19. end
  20. end
  21.  
  22. function moveDown(num)
  23. for i = 0, num do
  24. turtle.down()
  25. end
  26. end
  27.  
  28. function checkDirection()
  29. x, y, z = gps.locate()
  30. turtle.forward()
  31. comX, comY, comZ = gps.locate()
  32. turle.back()
  33. if x ~= comX then
  34. if x > comX then
  35. facing = 3
  36. else
  37. facing = 1
  38. end
  39. end
  40. if z ~= comZ then
  41. if z > comZ then
  42. facing = 2
  43. else
  44. facing = 0
  45. end
  46. end
  47. end
  48.  
  49. function moveX(num)
  50. if num < 0 then
  51. turn = facing - 3
  52. if turn == -2 then
  53. turtle.turnLeft()
  54. turtle.turnLeft()
  55. elseif turn == -1 then
  56. turle.turnRight()
  57. elseif turn == -3 then
  58. turtle.turnLeft()
  59. end
  60. moveForward(math.abs(num))
  61. else
  62. turn = facing - 1
  63. if turn == 2 then
  64. turtle.turnLeft()
  65. turtle.turnLeft()
  66. elseif turn == -1 then
  67. turle.turnRight()
  68. elseif turn == 1 then
  69. turtle.turnLeft()
  70. end
  71. moveForward(math.abs(num))
  72. end
  73. end
  74.  
  75. function moveY(num)
  76. if num < 0 then
  77. moveUp(math.abs(num))
  78. else
  79. moveDown(math.abs(num))
  80. end
  81. end
  82.  
  83. function moveZ(num)
  84. if num < 0 then
  85. turn = facing - 0
  86. if turn == 2 then
  87. turtle.turnLeft()
  88. turtle.turnLeft()
  89. elseif turn == 3 then
  90. turle.turnRight()
  91. elseif turn == 1 then
  92. turtle.turnLeft()
  93. end
  94. moveForward(math.abs(num))
  95. else
  96. turn = facing - 2
  97. if turn == -2 then
  98. turtle.turnLeft()
  99. turtle.turnLeft()
  100. elseif turn == -1 then
  101. turle.turnRight()
  102. elseif turn == 1 then
  103. turtle.turnLeft()
  104. end
  105. moveForward(math.abs(num))
  106. end
  107. end
  108.  
  109. function goto(toX, toY, toZ)
  110. x, y, z = gps.locate()
  111. comX = toX - x
  112. comY = toY - y
  113. comZ = toZ - z
  114. checkDirection()
  115. moveY(comY)
  116. if comX > comZ then
  117. moveX(comX)
  118. else
  119. moveZ(comZ)
  120. end
  121. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement