Plieax

treefarm

Apr 28th, 2024 (edited)
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. local function left()
  2. turtle.turnLeft()
  3. if turtle.detect() then
  4. --turtle.dig()
  5. end
  6. turtle.suck()
  7. turtle.forward()
  8. turtle.turnRight()
  9. end
  10.  
  11. local function right()
  12. turtle.turnRight()
  13. if turtle.detect() then
  14. --turtle.dig()
  15. end
  16. turtle.suck()
  17. turtle.forward()
  18. turtle.turnLeft()
  19. end
  20.  
  21. local function forward()
  22. if turtle.detect() then
  23. --turtle.dig()
  24. end
  25. turtle.suck()
  26. turtle.forward()
  27. end
  28.  
  29. local function back()
  30. turtle.suck()
  31. turtle.back()
  32. end
  33.  
  34. local function up()
  35. if turtle.detectUp() then
  36. turtle.digUp()
  37. end
  38. turtle.up()
  39. end
  40.  
  41. local function down()
  42. turtle.down()
  43. end
  44.  
  45. local function empty()
  46. turtle.turnLeft()
  47. turtle.turnLeft()
  48.  
  49. for i=1, 16 do
  50. local item= turtle.getItemDetail(i)
  51. if item and item.name == "minecraft:spruce_log" then
  52. turtle.select(i)
  53. turtle.drop(item.amount)
  54. end
  55. end
  56.  
  57. turtle.turnRight()
  58. turtle.turnRight()
  59. end
  60.  
  61. local function clear()
  62. turtle.turnRight()
  63. for i=1, 16 do
  64. local item= turtle.getItemDetail(i)
  65. if i > 1 and item and (item.name == "minecraft:spruce_sapling" or item.name == "twigs:twig") then
  66. turtle.select(i)
  67. turtle.drop(item.amount)
  68. end
  69. end
  70. turtle.turnLeft()
  71. end
  72.  
  73. local function goRefuel()
  74. left()
  75. forward()
  76. up()
  77. left()
  78. turtle.suckDown(10)
  79. right()
  80. down()
  81. back()
  82. right()
  83. end
  84.  
  85. local function breakTree()
  86. local count = -1
  87. turtle.down()
  88. while ( turtle.detect() ) do
  89. turtle.dig()
  90. if (turtle.detectUp()) then
  91. turtle.digUp()
  92. end
  93. turtle.up()
  94. count = count + 1
  95. end
  96.  
  97. for i=count, 0, -1 do
  98. turtle.down()
  99. end
  100. end
  101.  
  102. local function plantTree()
  103. if not turtle.detect() and turtle.getItemDetail(1) and turtle.getItemDetail(1).name == "minecraft:spruce_sapling" then
  104. turtle.select(1)
  105. turtle.place(1)
  106. end
  107. end
  108.  
  109. local function collectItems()
  110. for i=1, 3 do
  111. turtle.forward()
  112. turtle.suck()
  113. turtle.turnLeft()
  114. turtle.forward()
  115. turtle.suck()
  116. turtle.turnRight()
  117. turtle.turnRight()
  118. turtle.forward()
  119. turtle.forward()
  120. turtle.suck()
  121. turtle.turnLeft()
  122. turtle.turnLeft()
  123. turtle.forward()
  124. turtle.turnRight()
  125. end
  126.  
  127. for i=1, 3 do
  128. turtle.back()
  129. end
  130. end
  131.  
  132. local function refuel()
  133. for i=1, 16 do
  134. local item = turtle.getItemDetail(i)
  135. if item and item.name == "minecraft:charcoal" then
  136. turtle.select(i)
  137. turtle.refuel()
  138. end
  139. end
  140. end
  141.  
  142. local x = 1
  143. local y = 1
  144.  
  145. while true do
  146. term.clear()
  147. term.setCursorPos(1,1)
  148. term.write(x .. " , " .. y)
  149. term.setCursorPos(1,2)
  150. term.write(turtle.getFuelLevel())
  151.  
  152. turtle.select(1)
  153.  
  154. if x == 6 and y == 6 then
  155. left()
  156. for i=1 , 10 do
  157. back()
  158. end
  159. right()
  160. empty()
  161. clear()
  162. goRefuel()
  163. refuel()
  164.  
  165. sleep(300)
  166.  
  167. x = 1
  168. y = 1
  169. elseif y == 2 or y == 4 or y == 6 then
  170. if x ~= 6 then
  171. left()
  172. left()
  173. x = x + 1
  174. else
  175. left()
  176. forward()
  177. forward()
  178. right()
  179. x = 1
  180. y = y + 1
  181. end
  182. else
  183. if x ~= 6 then
  184. right()
  185. right()
  186. x = x + 1
  187. else
  188. right()
  189. forward()
  190. forward()
  191. left()
  192. x = 1
  193. y = y + 1
  194. end
  195. end
  196.  
  197. plantTree()
  198. up()
  199.  
  200.  
  201. if turtle.detect() then
  202. down()
  203. if x == 1 and y == 1 then
  204. else
  205. breakTree()
  206. end
  207.  
  208. plantTree()
  209. else
  210. down()
  211. end
  212.  
  213. end
  214.  
Advertisement
Add Comment
Please, Sign In to add comment