Advertisement
djgaven588

Turtle - Spruce Farm

Mar 11th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. local treeSize = 2
  2. local treeCount = 2
  3. local treeDistance = 4
  4.  
  5. local function refuel()
  6. local currentSlot = turtle.getSelectedSlot()
  7. turtle.select(1)
  8. if not turtle.refuel(1) then
  9. print("Waiting for fuel!")
  10. while not turtle.refuel(1) do
  11. end
  12. end
  13. turtle.select(currentSlot)
  14. end
  15.  
  16. local function moveForward()
  17. refuel()
  18. return turtle.forward()
  19. end
  20.  
  21. local function moveUp()
  22. refuel()
  23. turtle.up()
  24. end
  25.  
  26. local function moveDown()
  27. refuel()
  28. turtle.down()
  29. end
  30.  
  31. local function moveBack()
  32. refuel()
  33. turtle.back()
  34. end
  35.  
  36. local function moveForwardForce()
  37. while not moveForward() do
  38. turtle.dig()
  39. end
  40. end
  41.  
  42. local function harvestTree()
  43. print("Harvesting tree")
  44. turtle.dig()
  45. turtle.forward()
  46. turtle.select(3)
  47. if treeSize == 1 then
  48. print("Tree Size 1")
  49. local treeHeight = 1
  50. while turtle.compareUp() do
  51. turtle.digUp()
  52. moveUp()
  53. treeHeight = treeHeight + 1
  54. end
  55. print("Tree Height:",treeHeight)
  56. while turtle.detectDown() == false do
  57. moveDown()
  58. end
  59. turtle.back()
  60. turtle.select(2)
  61. turtle.place()
  62. elseif treeSize == 2 then
  63. while turtle.compareUp() do
  64. turtle.dig()
  65. turtle.digUp()
  66. moveUp()
  67. end
  68. turtle.dig()
  69. turtle.turnRight()
  70. turtle.dig()
  71. moveForward()
  72. turtle.turnLeft()
  73. while turtle.compareDown() do
  74. turtle.dig()
  75. turtle.digDown()
  76. moveDown()
  77. end
  78. turtle.dig()
  79. turtle.select(2)
  80. turtle.place()
  81. turtle.turnLeft()
  82. moveForward()
  83. turtle.turnRight()
  84. turtle.place()
  85. turtle.turnRight()
  86. turtle.place()
  87. turtle.turnLeft()
  88. moveBack()
  89. turtle.place()
  90. end
  91. end
  92.  
  93. local function doTreeIteration()
  94. turtle.turnLeft()
  95. turtle.select(2)
  96. if turtle.compare() then
  97. print("Tree not ready.")
  98. end
  99. turtle.select(3)
  100. if turtle.compare() then
  101. print("Harvesting tree")
  102. harvestTree()
  103. else
  104. error("Unexpected tree grew!")
  105. end
  106. turtle.turnRight()
  107. end
  108.  
  109. local function doInventoryManagement()
  110. turtle.turnLeft()
  111. turtle.select(1)
  112. turtle.suck(turtle.getItemSpace())
  113. turtle.turnRight()
  114. turtle.turnRight()
  115. turtle.select(2)
  116. turtle.suck(turtle.getItemSpace())
  117. turtle.turnLeft()
  118. for i=4,16,1 do
  119. turtle.select(i)
  120. turtle.dropDown()
  121. end
  122. end
  123.  
  124. local function runPath()
  125. moveForwardForce()
  126. doTreeIteration()
  127. for i=2,treeCount,1 do
  128. for j=1,treeDistance,1 do
  129. moveForwardForce()
  130. end
  131. doTreeIteration()
  132. end
  133. turtle.turnLeft()
  134. turtle.turnLeft()
  135. for i=2,treeCount,1 do
  136. for j=1,treeDistance,1 do
  137. moveForwardForce()
  138. end
  139. end
  140. moveForwardForce()
  141. turtle.turnRight()
  142. turtle.turnRight()
  143. doInventoryManagement()
  144. end
  145.  
  146. runPath()
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement