Guest User

sugarcane

a guest
Jan 6th, 2017
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.77 KB | None | 0 0
  1. --SugarCane farm by janek222
  2. --Version 1.0 Beta
  3. --Variables
  4. local fuel = turtle.getFuelLevel()
  5. local distance
  6. local readlength
  7. local length = tonumber(readlength)
  8. local i = 1
  9. local success, data = turtle.inspect()
  10. local busy = false
  11. local cane = turtle.getItemCount(1)
  12. --Functions
  13. function start()
  14. busy = true
  15. turtle.digDown()
  16. turtle.select(8)
  17. turtle.placeDown()
  18. --Place chest /\
  19. turtle.forward()
  20. turtle.digDown()
  21. turtle.select(13)
  22. turtle.placeDown()
  23. --1
  24. turtle.forward()
  25. turtle.digDown()
  26. turtle.turnLeft()
  27. --2
  28. turtle.forward()
  29. turtle.digDown()
  30. turtle.select(14)
  31. turtle.placeDown()
  32. turtle.turnLeft()
  33. --3
  34. turtle.forward()
  35. turtle.digDown()
  36. turtle.turnLeft()
  37. --4
  38. turtle.forward()
  39. turtle.turnLeft()
  40. turtle.forward()
  41. turtle.forward()
  42. --2x2 infinite water source
  43. for i = 1,length do
  44. turtle.digDown()
  45. turtle.forward()
  46. end
  47. --Left row
  48. turtle.turnLeft()
  49. turtle.forward()
  50. turtle.turnLeft()
  51. for i = 1,length do
  52. turtle.forward()
  53. end
  54. turtle.turnLeft()
  55. turtle.forward()
  56. turtle.turnLeft()
  57. --Center
  58. turtle.back()
  59. turtle.select(13)
  60. turtle.place()
  61. os.sleep(1)
  62. turtle.select(14)
  63. turtle.place()
  64. --Refill buckets
  65. repeat
  66. turtle.forward()
  67. turtle.select(13)
  68. turtle.placeDown()
  69. turtle.forward()
  70. turtle.select(14)
  71. turtle.placeDown()
  72. distance = distance + 2
  73. turtle.back()
  74. turtle.select(13)
  75. turtle.placeDown()
  76. os.sleep(1)
  77. turtle.select(14)
  78. turtle.placeDown()
  79. turtle.forward()
  80. turtle.forward()
  81. until distance > length
  82. --Water rows
  83. for i = 1,length do
  84. turtle.back()
  85. turtle.turnLeft()
  86. turtle.select(3)
  87. turtle.place()
  88. turtle.turnRight()
  89. turtle.turnRight()
  90. turtle.place()
  91. turtle.turnLeft()
  92. busy = false
  93. end
  94. end
  95. function harvest()
  96. term.clear()
  97. print("Waiting for canes to grow... It'll take 10 minutes.")
  98. os.sleep(600)
  99. print("Harvesting...")
  100. busy = true
  101. turtle.up()
  102. turtle.up()
  103. for i = 1,length do
  104. turtle.forward()
  105. turtle.turnLeft()
  106. if data.name == minecraft:reeds then
  107. turtle.dig()
  108. print("Harvested 1 sugarcane block")
  109. end
  110. turtle.turnRight()
  111. turtle.turnRight()
  112. if data.name == minecraft:reeds then
  113. turtle.dig()
  114. print("Harvested 1 sugarcane block")
  115. end
  116. turtle.turnLeft()
  117. end
  118. turtle.down()
  119. turtle.turnLeft()
  120. turtle.turnLeft()
  121. for i = 1,length do
  122. turtle.turnLeft()
  123. if data.name == minecraft:reeds then
  124. turtle.dig()
  125. print("Harvested 1 sugarcane block")
  126. end
  127. turtle.turnRight()
  128. turtle.turnRight()
  129. if data.name == minecraft:reeds then
  130. turtle.dig()
  131. print("Harvested 1 sugarcane block")
  132. end
  133. turtle.turnLeft()
  134. turtle.forward()
  135. end
  136. end
  137. turtle.turnLeft()
  138. turtle.turnLeft()
  139. busy = false
  140. end
  141.  
  142. function chest()
  143. busy = true
  144. repeat
  145. turtle.back()
  146. until data.name == minecraft:chest
  147. turtle.select(1)
  148. turtle.dropDown()
  149. turtle.forward()
  150. turtle.forward()
  151. turtle.forward()
  152. busy = false
  153. end
  154. end
  155.  
  156. function getfuel()
  157. busy = true
  158. turtle.select(5)
  159. repeat
  160. turtle.back()
  161. until data.name == minecraft:chest
  162. turtle.suckDown()
  163. turtle.forward()
  164. turtle.forward()
  165. turtle.forward()
  166. busy = false
  167. end
  168. --Code
  169. print("SugarCane farm by janek222")
  170. write("Enter length of farm:")
  171. local readlength = read()
  172. term.clear()
  173. print("Need fuel for startup. Add it to slot 5 and press any key to continue.")
  174. os.pullEvent("key")
  175. repeat
  176. turtle.select(5)
  177. if turtle.refuel(0) then
  178. turtle.refuel(1)
  179. end
  180. until fuel > 3000
  181. term.clear()
  182. print("Materials needed:")
  183. print("Slot 3 - Sugar Cane")
  184. print("Slot 13,14 - Water Bucket")
  185. print("Slot 8 - Chest (1)")
  186. print("Slot 5 - Fuel")
  187. print("Beware! If you don't give the turtle enough materials it may behave very weird")
  188. print("Press any key to continue...")
  189. os.pullEvent("key")
  190. term.clear()
  191. start()
  192. while true do
  193. if fuel < 1000 and busy = false then
  194. print("Low fuel! Attempt to refuel...")
  195. turtle.select(5)
  196. repeat
  197. turtle.refuel(1)
  198. until fuel > 1500
  199. getfuel()
  200. else
  201. harvest()
  202. end
  203. end
Advertisement
Add Comment
Please, Sign In to add comment