Zero_Burn

Lumberjack

May 1st, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. --2x2 lumberjack program (Original program by AaronDM, Heavily edited by ZeroBurn)
  2. --Chops down 2x2 trees such as Redwood or Fir and deposits them in a nearby chest
  3. --(currently in extra special mode for my tree chopping build)
  4.  
  5. local isGrown = false
  6.  
  7. local tArgs = { ... }
  8.  
  9. function ascend()
  10. for i=1, 4 do
  11. turtle.up()
  12. end --for
  13. end --ascend()
  14.  
  15. function descend()
  16. for i=1, 4 do
  17. turtle.down()
  18. end --for
  19. end --descend()
  20.  
  21. --Basic fuel check function
  22. function checkFuel()
  23. if turtle.getFuelLevel() < 100 then
  24. repeat
  25. turtle.select(16)
  26. turtle.refuel(2)
  27. turtle.select(1)
  28. until turtle.getFuelLevel() >= 100
  29. end --if
  30. end --checkFuel()
  31.  
  32. --Plants 4 Redwood saplings in a 2x2
  33. function plantTree()
  34. print("Planting Tree")
  35. turtle.select(15)
  36. turtle.forward()
  37. turtle.place()
  38. turtle.back()
  39. turtle.place()
  40. turtle.turnRight()
  41. turtle.forward()
  42. turtle.turnLeft()
  43. turtle.forward()
  44. turtle.place()
  45. turtle.back()
  46. turtle.place()
  47. turtle.turnLeft()
  48. turtle.forward()
  49. turtle.turnRight()
  50. isGrown = false
  51. end --plantTree()
  52.  
  53. --Uses Bonemeal to grow tree. (Only runs if there is Bonemeal in 13)
  54. function growTree()
  55. turtle.select(13)
  56. turtle.place()
  57. end --growTree()
  58.  
  59. --Alternate checking for if the tree has grown. (If there are no saplings in 14)
  60. function altCheckTree()
  61. turtle.up()
  62. isGrown = not turtle.forward()
  63. if isGrown == false then
  64. repeat
  65. turtle.back()
  66. turtle.down()
  67. sleep(30)
  68. turtle.up()
  69. isGrown = turtle.foward()
  70. until isGrown == true
  71. end --if
  72. turtle.down()
  73. end --growTree()
  74.  
  75. function checkTree()
  76. if turtle.getItemCount(13) >= 1 then
  77. growTree()
  78. end
  79. if turtle.getItemCount(14) >= 1 then
  80. turtle.select(14)
  81. isGrown = not turtle.compare()
  82. print("Is Grown: "..tostring(isGrown))
  83. else
  84. altCheckTree()
  85. end --if
  86. end --checkTree()
  87.  
  88. --Cuts down the Redwood. Up the left side, then down the right side.
  89. function cutTree()
  90. print("Chopping Down Tree")
  91. turtle.select(1)
  92. turtle.dig()
  93. sleep(0.25)
  94. turtle.forward()
  95. turtle.dig()
  96. local height = 0
  97. if turtle.detectUp() == true then
  98. repeat
  99. turtle.dig()
  100. turtle.digUp()
  101. turtle.up()
  102. height = height + 1
  103. until turtle.detectUp() == false
  104. end --if
  105. checkFuel()
  106. turtle.turnRight()
  107. if turtle.detect() == true then
  108. turtle.dig()
  109. end --if
  110. turtle.forward()
  111. turtle.turnLeft()
  112. if turtle.detectDown() == true then
  113. repeat
  114. turtle.dig()
  115. turtle.digDown()
  116. turtle.down()
  117. height = height - 1
  118. until height <= 0
  119. end --if
  120. turtle.dig()
  121. end --cutTree()
  122.  
  123. --Deposits the first 7 slots in a chest behind the turtle.
  124. function dropOff()
  125. --local distance = 0
  126. checkFuel()
  127. turtle.turnLeft()
  128. turtle.forward()
  129. turtle.turnLeft()
  130. turtle.forward()
  131. --while turtle.forward() do
  132. -- distance = distance + 1
  133. --end --while
  134. for i=1, 8 do
  135. turtle.select(i)
  136. turtle.drop()
  137. end
  138. turtle.select(1)
  139. turtle.turnLeft()
  140. turtle.turnLeft()
  141. --distance = distance - 1
  142. --while distance > 0 do
  143. -- turtle.forward()
  144. -- distance = distance - 1
  145. --end --while
  146. checkFuel()
  147. end --dropOff()
  148.  
  149. function checkInventory()
  150. return turtle.getItemCount(15) >= 4 and turtle.getItemCount(16) >= 2
  151. end --checkInventory()
  152.  
  153. function getInventory()
  154. turtle.select(14)
  155. while turtle.getItemCount(14) < 64 do
  156. turtle.suck()
  157. end --while
  158. turtle.transferTo(15, 4)
  159. turtle.transferTo(1, 59)
  160. turtle.select(1)
  161. turtle.drop()
  162. turtle.turnRight()
  163. if turtle.getItemCount(16) == 0 then
  164. turtle.select(16)
  165. turtle.suck()
  166. end --if
  167. turtle.turnLeft()
  168. end --getInventory()
  169.  
  170. --Main Script
  171.  
  172. term.clear()
  173. print("Please confirm inventory.")
  174. print("Slot 13 = Bonemeal [Optional]")
  175. print("Slot 14 = Test Sapling [Optional; Only need one]")
  176. print("Slot 15 = Planting Saplings [Minimum 4]")
  177. print("Slot 16 = Fuel [Minimum 2]")
  178. if #tArgs < 1 then
  179. print("Run how many times?")
  180. times = tonumber(read())
  181. else
  182. times = tonumber(tArgs[1])
  183. print("Running "..times.." times")
  184. end
  185. if times == 0 then
  186. cutTree()
  187. checkFuel()
  188. return true
  189. end
  190. for i=1, times do
  191. getInventory()
  192. if not checkInventory() then
  193. term.clear()
  194. write("Please resupply.")
  195. return
  196. end
  197. checkFuel()
  198. ascend()
  199. if not turtle.detect() then
  200. plantTree()
  201. else
  202. print("Skipping Planting Tree")
  203. end
  204. if isGrown == false then
  205. repeat
  206. print("Is Grown: "..tostring(isGrown))
  207. checkTree()
  208. sleep(15)
  209. until isGrown == true
  210. end
  211. checkFuel()
  212. cutTree()
  213. checkFuel()
  214. dropOff()
  215. descend()
  216. end
  217. print("Complete")
  218. return
Advertisement
Add Comment
Please, Sign In to add comment