Saereth

TurtleTreeFarm+Leaves

May 20th, 2014
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function f(loc)
  2. while not turtle[loc]() do
  3. sleep(0.5)
  4. end
  5. end
  6. function up() f("up") end
  7. function down() f("down") end
  8. function fw() f("forward") end
  9. function back() f("back") end
  10. function l() f("turnLeft") end
  11. function r() f("turnRight") end
  12. function d() turtle.dig() end
  13. function du() turtle.digUp() end
  14. function dd() turtle.digDown() end
  15. function c(x)
  16. for i=1,x do d() fw() du() dd() end
  17. end
  18.  
  19. function makeTree()
  20. if turtle.getItemCount(1)==0 then
  21. print("Not enough Saplings.")
  22. return
  23. end
  24.  
  25. if turtle.getItemCount(2)==0 then
  26. print("Not enough BoneMeal.")
  27. return
  28. end
  29. turtle.select(1)
  30. turtle.place()
  31. sleep(1)
  32. turtle.select(2)
  33. turtle.place()
  34. sleep(1)
  35. end
  36.  
  37.  
  38. function fuel()
  39. if turtle.getFuelLevel() <= 10 then
  40. turtle.select(16)
  41. turtle.refuel(1)
  42. print("Fuel less than 10, refueling.")
  43. sleep(2)
  44. return
  45. elseif turtle.getFuelLevel() == "unlimited" then
  46. print("This turtle does not use fuel to move")
  47. sleep(2)
  48. return
  49. end
  50. end
  51.  
  52. function resetPos()
  53. print("Resetting position.")
  54. sleep(2)
  55. r=0
  56. while r==0 do
  57. fuel()
  58. turtle.down()
  59. if turtle.detectDown()==true then
  60. r=1
  61. end
  62. end
  63. turtle.back()
  64. end
  65.  
  66. --function cutTree()
  67. -- sleep(2)
  68.  
  69. -- fuel()
  70. --print("Cutting Tree.")
  71. -- sleep(2)
  72. -- turtle.dig()
  73. -- turtle.forward()
  74. -- y=1
  75. -- while y==1 do
  76. -- fuel()
  77. -- turtle.digUp()
  78. -- turtle.up()
  79. -- if turtle.detectUp()==false then
  80. -- y=0
  81. -- end
  82. -- end
  83. --
  84. --resetPos()
  85. --end
  86.  
  87. function cutTree()
  88. print("tree cut")
  89. hi = 0
  90. while not turtle.detectUp() do
  91. up() hi=hi+1
  92. end
  93. du() up() du() up() du() l() l()
  94. c(1) r() c(2) r() c(4) r() c(4) r()
  95. c(4) r() c(1) r() c(3) l() c(2) l()
  96. c(2) back() l() c(1) l() down()
  97. for r=1,hi do dd() down() end
  98. dd() turtle.placeDown() back()
  99. down() down()
  100. print(hi)
  101. end
  102.  
  103. function checkMats()
  104. -- Checking saplings slot
  105. print("Checking for mats.")
  106. sleep(2)
  107. if turtle.getItemCount(1)==0 then
  108. print("Not enough Saplings.")
  109. s=1
  110. turtle.turnLeft()
  111. turtle.select(1)
  112. turtle.suck()
  113. turtle.turnRight()
  114. if turtle.getItemCount(1)>0 then
  115. s=0
  116. end
  117. end
  118.  
  119. -- Checking bonemeal slot
  120. if turtle.getItemCount(2)==0 then
  121. print("Not enough bonemeal.")
  122. turtle.turnLeft()
  123. turtle.turnLeft()
  124. turtle.select(1)
  125. turtle.suck()
  126. turtle.turnRight()
  127. turtle.turnRight()
  128. end
  129.  
  130. -- Checking fuel slot
  131. if turtle.getItemCount(16)<=10 then
  132. print("Not enough Fuel.")
  133. turtle.turnRight()
  134. turtle.select(1)
  135. turtle.suck()
  136. turtle.turnLeft()
  137. end
  138.  
  139.  
  140.  
  141. end
  142.  
  143. function checkStop()
  144. if s==0 then
  145. shell.exit()
  146. end
  147. end
  148.  
  149. function ConsolidateMats()
  150. turtle.turnLeft()
  151. print("Consolidating saplings.")
  152. for i=3,15 do
  153. turtle.select(i)
  154.  
  155. if turtle.compareTo(1) then -- It's a sapling not in slot one
  156. turtle.drop() -- put it in the chest to our left
  157. end
  158. end
  159. turtle.turnRight()
  160.  
  161. print("Sending all other mats to processing.")
  162. sleep(2)
  163. for i=3,15 do
  164. turtle.select(i)
  165. turtle.dropDown()
  166. end
  167. end
  168.  
  169. while true do
  170. fuel()
  171. makeTree()
  172. checkMats()
  173. cutTree()
  174. ConsolidateMats()
  175. checkStop()
  176. end
Advertisement
Add Comment
Please, Sign In to add comment