Advertisement
crawfeesh

farmer Final

Feb 29th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. local arg1, arg2 = ...
  2. limX = tonumber(arg1)
  3. limZ = tonumber(arg2)
  4. area = limX * limZ
  5. relX = 0
  6. relZ = 0
  7. facing = 0
  8.  
  9. function plant()
  10. seedSlot = selectSeeds()
  11. if seeds == 0
  12. then
  13. print("Seeds not found.")
  14. return false
  15. end
  16. turtle.select(seedSlot)
  17. placed = turtle.placeDown()
  18. return placed
  19. end
  20.  
  21. function selectSeeds()
  22. for i = 1, 16, 1
  23. do
  24. turtle.select(i)
  25. data = turtle.getItemDetail()
  26. if data
  27. then
  28. name = turtle.getItemDetail().name
  29. if name == "minecraft:wheat_seeds"
  30. then
  31. return i
  32. end
  33. end
  34. end
  35. return 0
  36. end
  37.  
  38. function harvest()
  39. if turtle.detectDown()
  40. then
  41. local success, data = turtle.inspectDown()
  42. if data.name == "minecraft:wheat"
  43. then
  44. if data.metadata == 7
  45. then
  46. turtle.digDown()
  47. end
  48. end
  49. end
  50. end
  51.  
  52. function turnTo(dir)
  53. if facing > dir
  54. then
  55. turtle.turnRight()
  56. facing = facing - 1
  57. turnTo(dir)
  58. end
  59. if facing < dir
  60. then
  61. turtle.turnLeft()
  62. facing = facing + 1
  63. turnTo(dir)
  64. end
  65. if facing == dir
  66. then
  67. return
  68. end
  69. end
  70.  
  71. function goUp()
  72. turnTo(0)
  73. turtle.forward()
  74. relZ = relZ + 1
  75. end
  76.  
  77. function goDown()
  78. turnTo(2)
  79. turtle.forward()
  80. relZ = relZ - 1
  81. end
  82.  
  83. function goLeft()
  84. turnTo(1)
  85. turtle.forward()
  86. relX = relX - 1
  87. end
  88.  
  89. function goRight()
  90. turnTo(3)
  91. turtle.forward()
  92. relX = relX + 1
  93. end
  94.  
  95. function printPos()
  96. print("Walking Pos (", tostring(relX), ", ", tostring(relZ), ").\n")
  97. end
  98.  
  99. function walkField()
  100. while relZ < limZ
  101. do
  102. goUp()
  103. printPos()
  104. harvest()
  105. plant()
  106.  
  107. while relX < limX
  108. do
  109. goRight()
  110. printPos()
  111. harvest()
  112. plant()
  113. end
  114.  
  115. if relZ < limZ
  116. then
  117.  
  118. goUp()
  119. printPos()
  120. harvest()
  121. plant()
  122.  
  123. while relX > 1
  124. do
  125. goLeft()
  126. printPos()
  127. harvest()
  128. plant()
  129. end
  130. end
  131. end
  132. end
  133.  
  134. function returnToOrigin()
  135. while relX > 0
  136. do
  137. goLeft()
  138. end
  139. while relZ > 0
  140. do
  141. goDown()
  142. end
  143. end
  144.  
  145. function depositItems()
  146. for i = 1, 16, 1
  147. do
  148. turtle.select(i)
  149. turtle.drop()
  150. end
  151. end
  152.  
  153. function grabSeeds()
  154. i = 1
  155. remaining = area
  156. while remaining > 64
  157. do
  158. turtle.select(i)
  159. turtle.suckDown(64)
  160. i = i + 1
  161. remaining = remaining - 64
  162. end
  163. turtle.suckDown(remaining)
  164. end
  165.  
  166. function feedFuel()
  167. print("Refueling...")
  168. turnTo(3)
  169. while (turtle.getFuelLevel() < 2000)
  170. do
  171. turtle.suck(4)
  172. turtle.refuel(4)
  173. end
  174. print("Complete.\n")
  175. end
  176.  
  177. function execute()
  178. feedFuel()
  179. grabSeeds()
  180. walkField()
  181. returnToOrigin()
  182. depositItems()
  183. turnTo(0)
  184. end
  185.  
  186. function main()
  187. while (true)
  188. do
  189. os.queueEvent("fakeEvent")
  190. os.pullEvent()
  191. if redstone.getInput("left")
  192. then
  193. execute()
  194. end
  195. end
  196. end
  197.  
  198. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement