Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. --Initialize variables
  2. local xParkLocation = -1
  3. local xCoord = xParkLocation
  4. local yParkLocation = 0
  5. local yCoord = yParkLocation
  6. local xMinCoord = 0
  7. local xMaxCoord = 5
  8. local yMinCoord = 0
  9. local yMaxCoord = 28
  10. local xStart = xMinCoord --Set the starting X location equal to the min X coordinate
  11. local xLimit = xMaxCoord --Sets the ending X location equal to the max X coordinate
  12. local xDirection = 1 --1 goes forward and -1 goes backward
  13. local stuckTimer = 3 --Number of seconds to delay before retrying move
  14.  
  15.  
  16. --Create harvest function
  17. local function harvest()
  18.  
  19. --Loop through all Y coordinates
  20. for y = yMinCoord, yMaxCoord, 1 do
  21.  
  22. --Loop through all X coordinates at the current Y coordinate
  23. for x = xStart, xLimit, xDirection do
  24.  
  25. --Till Dirt and Plant Seeds
  26. turtle.digDown()
  27. turtle.placeDown()
  28.  
  29. --Determine where the turtle should go based on its direction
  30. if xDirection == 1 then
  31.  
  32. --Make sure the turtle doesn't go past the max X coordinate
  33. if x < xMaxCoord then
  34.  
  35. --Move the turtle forward 1 block
  36.  
  37. while turtle.forward() == false do
  38.  
  39. print("Get out of my way!")
  40. sleep(stuckTimer)
  41.  
  42. end
  43.  
  44. --Update the X coordinate variable
  45. xCoord = xCoord + xDirection
  46.  
  47. else
  48.  
  49. --Make sure the turtle doesn't go past the max Y coordinate
  50. if yCoord < yMaxCoord then
  51.  
  52. --Move to the next row
  53. turtle.turnLeft()
  54. while turtle.forward() == false do
  55.  
  56. print("Get out of my way!")
  57. sleep(stuckTimer)
  58.  
  59. end
  60. turtle.turnLeft()
  61.  
  62. -- Set "for" loop variables
  63. --for next row
  64. xStart = xMaxCoord
  65. xLimit = xMinCoord
  66. xDirection = -1
  67.  
  68. end
  69.  
  70. end
  71.  
  72. else
  73.  
  74. --Make sure the turtle doesn't go past the min X coordinate
  75. if x > xMinCoord then
  76.  
  77. --Move the turtle forward 1 block
  78. while turtle.forward() == false do
  79.  
  80. print("Get out of my way!")
  81. sleep(stuckTimer)
  82.  
  83. end
  84.  
  85. xCoord = xCoord + xDirection
  86.  
  87. else
  88.  
  89. --Make sure the turtle doesn't go past the max Y coordinate
  90. if yCoord < yMaxCoord then
  91.  
  92. --Move to next row
  93. turtle.turnRight()
  94. while turtle.forward() == false do
  95.  
  96. print("Get out of my way!")
  97. sleep(stuckTimer)
  98.  
  99. end
  100.  
  101. turtle.turnRight()
  102.  
  103. -- Set "for" loop variables
  104. --for next row
  105. xStart = xMinCoord
  106. xLimit = xMaxCoord
  107. xDirection = 1
  108.  
  109. end
  110.  
  111. end
  112.  
  113. end
  114.  
  115. end
  116.  
  117. --Update the X coordinate variable
  118. if y < yMaxCoord then
  119.  
  120. yCoord = yCoord + 1
  121.  
  122. end
  123.  
  124. end
  125.  
  126. end
  127.  
  128.  
  129.  
  130. --Create return to storage function
  131. local function returnToStorage()
  132.  
  133. --Turn the turtle to face toward Y 0
  134. turtle.turnRight()
  135.  
  136. --Move the turtle to Y 0
  137. for y = yCoord, yParkLocation, -1 do
  138.  
  139. --Make sure the turtle doesn't go past the min Y coordinate
  140. if y > yMinCoord then
  141.  
  142. --Move the turtle forward 1 block
  143. while turtle.forward() == false do
  144.  
  145. print("Get out of my way!")
  146. sleep(stuckTimer)
  147.  
  148. end
  149.  
  150. end
  151.  
  152. end
  153.  
  154. --Turn the turtle to face toward X 0
  155. turtle.turnLeft()
  156.  
  157. --Move the turtle to X -1
  158. for x = xCoord, xParkLocation, -1 do
  159.  
  160. --Make sure the turtle doesn't go past the X park coordinate
  161. if x >= xParkLocation then
  162.  
  163. --Move the turtle back 1 block
  164. while turtle.back() == false do
  165.  
  166. print("Get out of my way!")
  167. sleep(stuckTimer)
  168.  
  169. end
  170.  
  171.  
  172. end
  173.  
  174. end
  175.  
  176. end
  177.  
  178.  
  179. --Exit storage
  180. while turtle.forward() == false do
  181.  
  182. print("Get out of my way!")
  183. sleep(stuckTimer)
  184.  
  185. end
  186.  
  187. --Select seed slot
  188. turtle.select(5)
  189.  
  190. --Harvest
  191. harvest()
  192.  
  193. --Return to storage
  194. returnToStorage()
  195.  
  196. --Write to the console window
  197. print( "Harvest Complete" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement