Advertisement
CainDonaghey

Tree Turtle Initial Release v1.03

Jun 21st, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.85 KB | None | 0 0
  1. --Changelog v1.01
  2. -- Fixed tree growing in turtle
  3. -- Possibly fixed random crashes
  4.  
  5. --Changelog v1.02
  6. -- Added basic session support,
  7. -- - if the server crashed while it was planting bonemeal it will return to its original position.
  8.  
  9. --Changelog v1.03
  10. -- Removed rebooting the turtle, will now run on it's own. (Damnit h variable)
  11.  
  12. if(turtle.detect()) then
  13. turtle.down()
  14. if turtle.detect() then
  15. print("I've crashed, woops.")
  16. for i=1,7 do
  17. turtle.back()
  18. end
  19. turtle.turnLeft()
  20. for i=1,8 do turtle.back() end
  21. end
  22. end
  23.  
  24. if (turtle.detect() and not turtle.detectDown()) then
  25. print("Detected crash, going back.")
  26. while not turtle.detectDown() do
  27. turtle.back()
  28. end
  29. turtle.turnLeft()
  30. for i=1,8 do turtle.back() end
  31. end
  32.  
  33. h = 0
  34. function checkFuel()
  35. if turtle.getFuelLevel() < 200 then
  36. print("Turtle refueling.")
  37. turtle.select(4)
  38. turtle.turnLeft()
  39. turtle.turnLeft()
  40. turtle.suck()
  41. if turtle.refuel() then
  42. print("Turtle refueled.")
  43. else
  44. print("The turtle could not refuel.")
  45. turtle.turnLeft()
  46. turtle.turnLeft()
  47. checkFuel()
  48. end
  49. turtle.turnLeft()
  50. turtle.turnLeft()
  51. checkFuel()
  52. end
  53. end
  54.  
  55. function newFuel()
  56. turtle.select(16)
  57. if turtle.refuel() then
  58. print("Turtle refueled.")
  59. else
  60. print("Turtle could not refuel. Retrying in 10 seconds..")
  61. sleep(10)
  62. newFuel()
  63. end
  64. end
  65.  
  66. function checkSapling()
  67. print("Checking Saplings.")
  68. if turtle.getItemCount(1) < 8 then
  69. print("Need moar saplings.")
  70. turtle.select(1)
  71. turtle.turnLeft()
  72. turtle.suck()
  73. if turtle.getItemCount(1) < 8 then
  74. turtle.suck()
  75. end
  76. turtle.select(2)
  77. turtle.drop()
  78. turtle.select(3)
  79. turtle.drop()
  80. turtle.select(1)
  81. turtle.turnRight()
  82. end
  83. end
  84.  
  85.  
  86. function checkBonemeal()
  87. turtle.select(14)
  88. print("Attempting to get bonemeal..")
  89. if turtle.getItemCount(14) < 1 then
  90. if turtle.suckUp() then
  91. print("Got bonemeal!")
  92. sleep(5)
  93. os.reboot()
  94. end
  95. end
  96. if turtle.getItemCount(14) < 2 then
  97. print(".. need moar bonemeal.")
  98. if turtle.suckUp() then
  99. turtle.select(15)
  100. turtle.dropUp()
  101. sleep(5)
  102. os.reboot()
  103. end
  104. end
  105. end
  106.  
  107. function moveToPosition()
  108. print("Awayyyyyyy!")
  109. for i=1,8 do turtle.forward() turtle.attack() end
  110. turtle.turnRight()
  111. for i=1,7 do turtle.forward() turtle.attack() end
  112. end
  113.  
  114. function placeSapling()
  115. turtle.select(1)
  116. if not turtle.detect() then
  117. for i=1,2 do turtle.forward() end
  118. turtle.turnLeft()
  119. turtle.place()
  120. turtle.turnRight()
  121. turtle.back()
  122. turtle.place()
  123. turtle.turnLeft()
  124. turtle.place()
  125. turtle.turnRight()
  126. turtle.back()
  127. turtle.place()
  128. turtle.select(14)
  129. else
  130. print("Saplings were already there, ignoring.")
  131. end
  132. sleep(2)
  133. print("Attempting to bonemeal..")
  134. turtle.place()
  135. end
  136.  
  137. function checkTree()
  138. turtle.select(16)
  139. turtle.digUp()
  140. turtle.up()
  141. if not turtle.detect() then
  142. print("Tree hasen't grown, sleeping.")
  143. print("Every day I'm shufflin'")
  144. turtle.down()
  145. sleep(3)
  146. turtle.select(14)
  147. turtle.place()
  148. checkTree()
  149. end
  150.  
  151. turtle.down()
  152. turtle.select(5)
  153. turtle.dig()
  154. turtle.forward()
  155. turtle.turnLeft()
  156. while turtle.detectUp() do
  157. turtle.dig()
  158. turtle.digUp()
  159. turtle.up()
  160. h = h + 1
  161. end
  162. turtle.turnRight()
  163. turtle.dig()
  164. turtle.forward()
  165. turtle.turnLeft()
  166. turtle.select(5)
  167. for i = 1,h do
  168. turtle.digDown()
  169. turtle.down()
  170. turtle.dig()
  171. end
  172. turtle.turnRight()
  173. for i=1,9 do turtle.back() turtle.attack() end
  174. turtle.turnLeft()
  175. for i=1,8 do turtle.back() turtle.attack() end
  176. turtle.turnRight()
  177.  
  178. turtle.select(6)
  179. if turtle.getFuelLevel() < 500 then
  180. turtle.transferTo(16, 64)
  181. print("Kept some fuel. Eating it.")
  182. turtle.select(16)
  183. turtle.refuel()
  184. end
  185.  
  186. for i=5,9 do
  187. turtle.select(i)
  188. turtle.drop()
  189. end
  190. turtle.turnLeft()
  191. print("Yay!")
  192. os.reboot()
  193. end
  194.  
  195. if redstone.getInput("bottom") then
  196. print("Stopped.")
  197. print("Checking turtle in 10 seconds.")
  198. sleep(10)
  199. os.reboot()
  200. end
  201.  
  202. while true do
  203. if turtle.getFuelLevel() < 100 then
  204. newFuel()
  205. end
  206. checkBonemeal()
  207. checkSapling()
  208. moveToPosition()
  209. placeSapling()
  210. checkTree()
  211. h = 0
  212. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement