dxbydt

RubberMiner

Jul 17th, 2013
532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. direction="left"
  2. home=true
  3.  
  4. function sweep()
  5. for i = 1, 7 do
  6. turtle.dig()
  7. turtle.up()
  8. end
  9. turtle.dig()
  10. for i = 1, 8 do
  11. turtle.down()
  12. end
  13. end
  14.  
  15. function rotate()
  16. turtle.turnRight()
  17. turtle.forward()
  18. turtle.turnLeft()
  19. turtle.forward()
  20. turtle.turnLeft()
  21. end
  22.  
  23. function harvest()
  24. for i = 1, 4 do
  25. sweep()
  26. rotate()
  27. end
  28. end
  29.  
  30. function dumpItems()
  31. for i = 1, 16 do
  32. turtle.select(i)
  33. turtle.drop()
  34. end
  35. end
  36.  
  37. function toggleDirection()
  38. if direction=="left" then
  39. print("Direction set to right")
  40. direction="right"
  41. else
  42. print("Direction set to left")
  43. direction="left"
  44. end
  45. end
  46.  
  47. function turn()
  48. if direction=="left" then
  49. print("turn left")
  50. turtle.turnLeft()
  51. else
  52. print("turn right")
  53. turtle.turnRight()
  54. end
  55. end
  56.  
  57. function turnBack()
  58. if direction == "left" then
  59. print("turnBack right")
  60. turtle.turnRight()
  61. else
  62. print("turnBack left")
  63. turtle.turnLeft()
  64. end
  65. end
  66.  
  67. function goHome()
  68. turn()
  69. turn()
  70. while turtle.forward() do
  71. end
  72. if direction=="left" then
  73. turtle.turnLeft()
  74. while turtle.forward() do
  75. end
  76. turtle.turnRight()
  77. end
  78. turtle.turnRight()
  79. turtle.forward()
  80. turtle.turnLeft()
  81. turtle.forward()
  82. turtle.turnLeft()
  83. dumpItems()
  84. turtle.turnLeft()
  85. print("Sleeping for 5min to recharge")
  86. sleep(300)
  87. end
  88.  
  89. function goEdge()
  90. print("Going to edge of wall")
  91. while turtle.forward() do
  92. end
  93. end
  94.  
  95. function goDown()
  96. print("Going down")
  97. while turtle.down() do
  98. end
  99. end
  100.  
  101. function resume()
  102. goDown()
  103. if turtle.detect() then
  104. turtle.turnRight()
  105. end
  106. goEdge()
  107. turtle.turnRight()
  108. goEdge()
  109. while not checkStartCorner() do
  110. goNextCorner()
  111. end
  112. turtle.turnRight()
  113. turtle.forward()
  114. turtle.turnLeft()
  115. turtle.forward()
  116. turtle.turnLeft()
  117. dumpItems()
  118. turtle.turnLeft()
  119. print("Sleeping for 5min to recharge")
  120. sleep(300)
  121. end
  122.  
  123. function checkStartCorner()
  124. print("Checking for start corner")
  125. turtle.up()
  126. if turtle.detect() then
  127. turtle.down()
  128. return true
  129. end
  130. turtle.down()
  131. return false
  132. end
  133.  
  134. function goNextCorner()
  135. print("Going to next corner")
  136. turtle.turnRight()
  137. goEdge()
  138. end
  139.  
  140. function nextTree()
  141. print("Finding next tree")
  142. if home then
  143. print("Home now")
  144. turtle.forward()
  145. home=false
  146. return true
  147. else
  148. turn()
  149. turtle.forward()
  150. if not turtle.forward() then
  151. print("Reached end of row, finding new row")
  152. turnBack()
  153. turtle.forward()
  154. turtle.forward()
  155. if turtle.detect()then
  156. print("Reached last row, going home")
  157. goHome()
  158. direction="left"
  159. home=true
  160. return false
  161. end
  162. turtle.down()
  163. turnBack()
  164. turtle.forward()
  165. turn()
  166. toggleDirection()
  167. else
  168. turnBack()
  169. end
  170. return true
  171. end
  172. end
  173.  
  174. if not turtle.detectUp() then
  175. resume()
  176. end
  177. while true do
  178. print("Starting Tapping Route...")
  179. while nextTree() do
  180. harvest()
  181. end
  182. end
Advertisement
Add Comment
Please, Sign In to add comment