Advertisement
ivanzrer

harvester_v1

Sep 14th, 2024
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. args = {...}
  2. length = args[1]
  3. width = args[2]
  4. print("Fuel level:", turtle.getFuelLevel())
  5. stopRequired = false
  6.  
  7.  
  8. function preparation ()
  9. --refuel
  10. print("refueling...")
  11. turtle.select(1)
  12. turtle.suck(64)
  13. turtle.refuel()
  14. turtle.drop(turtle.getItemCount())
  15.  
  16. --get seed
  17. print("getting seed...")
  18. turtle.turnLeft()
  19. turtle.forward()
  20. turtle.turnRight()
  21. turtle.select(1)
  22. turtle.suck(10)
  23.  
  24. --move into start position
  25. print("moving to start pos..")
  26. turtle.turnLeft()
  27. print("turning left..")
  28. turtle.forward()
  29. print("moving forward..")
  30. turtle.turnRight()
  31. print("turning right..")
  32. turtle.forward()
  33. print("moving forward..")
  34. turtle.forward()
  35. print("moving forward..")
  36. end
  37.  
  38.  
  39. -- harvest
  40. function harvestPlant ()
  41. local success, data = turtle.inspectDown()
  42. if success then
  43. local blockName = data.name
  44. local state = data.state or {}
  45.  
  46. -- debug?
  47. print("Block name:", blockName)
  48. for k, v in pairs(state) do
  49. print(k, v)
  50. end
  51.  
  52. if blockName == "supplementaries:flax" then
  53. local growthStage = state.age or 0
  54. if growthStage == 7 then
  55. turtle.digDown()
  56. plantNew()
  57. end
  58. end
  59. end
  60. end
  61.  
  62.  
  63. -- plant
  64. function plantNew ()
  65. turtle.down()
  66. local slotSelected = 0
  67. turtle.select(1)
  68. slotSelected = 1
  69. if turtle.getItemCount(1) < 1 then
  70. slotSelected = slotSelected + 1
  71. if slotSelected > 17 then
  72. turtle.select(slotSelected)
  73. else
  74. print("turtle is empty")
  75. turtle.select(1)
  76. turtle.up()
  77. turtle.up()
  78. stopRequired = true
  79. end
  80. else
  81. turtle.placeDown()
  82. turtle.up()
  83. end
  84. end
  85.  
  86. -- dump inventory
  87. function dumpInv ()
  88. print("Beginning dump sequence...")
  89. turtle.select(2)
  90. dumping = true
  91. while dumping == true do
  92. if turtle.compareTo(1) then
  93. if turtle.getSelectedSlot() < 16 then
  94. turtle.select(turtle.getSelectedSlot() + 1)
  95. else
  96. dumping = false
  97. end
  98. end
  99. turtle.dropDown()
  100. if turtle.getSelectedSlot() < 16 then
  101. turtle.select(turtle.getSelectedSlot() + 1)
  102. else
  103. dumping = false
  104. end
  105. end
  106. --reposition for seed dump
  107. turtle.turnRight()
  108. turtle.forward()
  109. turtle.forward()
  110. turtle.forward()
  111. turtle.down()
  112. turtle.turnRight()
  113. turtle.forward()
  114. turtle.turnRight()
  115.  
  116. --seed dump
  117. print("Dumping seeds...")
  118. turtle.select(1)
  119. while turtle.getSelectedSlot() < 16 do
  120. turtle.drop()
  121. turtle.select(turtle.getSelectedSlot() + 1)
  122. end
  123. turtle.select(1)
  124. --reposition for new round
  125. print("Repositioning...")
  126. turtle.turnRight()
  127. turtle.forward()
  128. turtle.turnLeft()
  129.  
  130. end
  131. -- movePlan
  132. function movePlan (length, width)
  133. turtle.up()
  134. turtle.up()
  135. turtle.forward()
  136. for i=1, width,1 do
  137. for i=1, length,1 do
  138. harvestPlant()
  139. turtle.forward()
  140. end
  141. moveBack(length)
  142. end
  143. turtle.turnRight()
  144. for i=1, width,1 do
  145. turtle.forward()
  146. end
  147. turtle.forward()
  148. turtle.forward()
  149. turtle.down()
  150. dumpInv()
  151. end
  152.  
  153. -- backtrack
  154. function moveBack (n)
  155. print("Line complete, backtracking...")
  156. for i=1, n,1 do
  157. turtle.back()
  158. end
  159. turtle.turnLeft()
  160. turtle.forward()
  161. turtle.turnRight()
  162. end
  163.  
  164.  
  165. -- argument handling
  166. if length == "-help" then
  167. print("usage is [harvester x y] where x is the length of the field to be harvested and y is the width.")
  168. print("the script assumes a pre-planted field, and will only bring 10 extra seeds.")
  169. elseif width then
  170. -- main
  171. while stopRequired == false do
  172. preparation()
  173. if turtle.getFuelLevel() < 10 then
  174. stopRequired = true
  175. end
  176. movePlan(length, width)
  177. print("waiting for 180 seconds...")
  178. os.sleep(180)
  179. end
  180. else
  181. print("Invalid argument, see -help.")
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement