Aarondmorgan

Fir Tree Turtle v3

Dec 31st, 2012
1,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. --Written by AaronDM
  2. --Autonomously plants, grows, harvests, and deposits any 2x2 tree
  3. --Run program, follow directions, input how many runs you would like to perform.
  4. --To see where to place chest, run once and note where turtle stops to dump items.
  5.  
  6. --Basic fuel check function
  7. function checkFuel()
  8. if turtle.getFuelLevel() < 100 then
  9. repeat
  10. turtle.select(16)
  11. turtle.refuel(2)
  12. turtle.select(1)
  13. until turtle.getFuelLevel() >= 100
  14. end --if
  15. end --checkFuel()
  16.  
  17. --Plants 4 Redwood saplings in a 2x2
  18. function plantTree()
  19. turtle.select(14)
  20. turtle.forward()
  21. turtle.place()
  22. turtle.back()
  23. turtle.place()
  24. turtle.turnRight()
  25. turtle.forward()
  26. turtle.turnLeft()
  27. turtle.forward()
  28. turtle.place()
  29. turtle.back()
  30. turtle.place()
  31. turtle.turnLeft()
  32. turtle.forward()
  33. turtle.turnRight()
  34. end --plantTree()
  35.  
  36. --Applies bonemeal and checks if tree has grown. If not, sleeps and repeats.
  37. function growTree()
  38. turtle.select(15)
  39. turtle.place()
  40. turtle.up()
  41. if turtle.forward() == true then
  42. repeat
  43. turtle.back()
  44. turtle.down()
  45. sleep(120)
  46. turtle.place()
  47. turtle.up()
  48. until turtle.forward() == false
  49. end --if
  50. turtle.down()
  51. end --growTree()
  52.  
  53. --Cuts down the Redwood. Up the left side, then down the right side.
  54. function cutTree()
  55. turtle.dig()
  56. sleep(0.25)
  57. turtle.forward()
  58. turtle.dig()
  59. local height = 0
  60. if turtle.detectUp() == true then
  61. repeat
  62. turtle.dig()
  63. turtle.digUp()
  64. turtle.up()
  65. height = height + 1
  66. until turtle.detectUp() == false
  67. end --if
  68. checkFuel()
  69. turtle.turnRight()
  70. if turtle.detect() == true then
  71. turtle.dig()
  72. end --if
  73. turtle.forward()
  74. turtle.turnLeft()
  75. if turtle.detectDown() == true then
  76. repeat
  77. turtle.dig()
  78. turtle.digDown()
  79. turtle.down()
  80. height = height - 1
  81. until height == 0
  82. end --if
  83. turtle.dig()
  84. end --cutTree()
  85.  
  86. --Deposits the first 7 slots in a chest behind the turtle.
  87. function dropOff()
  88. checkFuel()
  89. turtle.turnLeft()
  90. turtle.turnLeft()
  91. turtle.forward()
  92. turtle.forward()
  93. turtle.forward()
  94. turtle.forward()
  95. turtle.forward()
  96. turtle.select(1)
  97. turtle.drop()
  98. turtle.select(2)
  99. turtle.drop()
  100. turtle.select(3)
  101. turtle.drop()
  102. turtle.select(4)
  103. turtle.drop()
  104. turtle.select(5)
  105. turtle.drop()
  106. turtle.select(6)
  107. turtle.drop()
  108. turtle.select(7)
  109. turtle.drop()
  110. turtle.select(1)
  111. turtle.turnLeft()
  112. turtle.turnLeft()
  113. turtle.forward()
  114. turtle.forward()
  115. turtle.forward()
  116. turtle.forward()
  117. turtle.turnLeft()
  118. turtle.forward()
  119. turtle.turnRight()
  120. checkFuel()
  121. end --dropOff()
  122.  
  123. --Attempts to light leftover leaves on fire, then returns to original position.
  124. function burnTree()
  125. if turtle.detectUp() == false then
  126. repeat
  127. turtle.up()
  128. until turtle.detectUp() == true
  129. end
  130. turtle.down()
  131. turtle.select(13)
  132. turtle.placeUp()
  133. if turtle.detectDown() == false then
  134. repeat
  135. turtle.down()
  136. until turtle.detectDown() == true
  137. end
  138. turtle.select(1)
  139. end --burnTree()
  140.  
  141. function checkInventory()
  142. return turtle.getItemCount(13) >= 1 and turtle.getItemCount(14) >= 4 and turtle.getItemCount(15) >= 2 and turtle.getItemCount(16) >= 2
  143. end --checkInventory()
  144.  
  145. --Main Script
  146.  
  147. term.clear()
  148. print("Please confirm inventory.")
  149. print("Slot 13 = Flint and tender")
  150. print("Slot 14 = Saplings")
  151. print("Slot 15 = Bonemeal")
  152. print("Slot 16 = Fuel")
  153. print("Run how many times?")
  154. times=tonumber(read())
  155. for i=1,times do
  156. if not checkInventory() then
  157. term.clear()
  158. write("Please resupply.")
  159. shell.run("reboot")
  160. end
  161. checkFuel()
  162. plantTree()
  163. growTree()
  164. checkFuel()
  165. cutTree()
  166. checkFuel()
  167. dropOff()
  168. burnTree()
  169. sleep(400)
  170. end
Advertisement
Add Comment
Please, Sign In to add comment