Advertisement
ivanzrer

Untitled

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