Advertisement
EphemeralKap

Untitled

Dec 7th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.72 KB | None | 0 0
  1. local status = 0
  2. -- 0 = Returning, 1 = Maintenance, 2 = Farming, 3 = Critical
  3. local n = 0
  4. local j = 0
  5.  
  6. --todo fix return, fix farm
  7.  
  8. -- Refuels the turtle if fuel levels are low
  9. function Refuel() --fin?
  10. print("Refueling..")
  11. turtle.select(1)
  12. if not turtle.refuel(3) then
  13. print("Fuel reserves low.. Returning home")
  14. status = 0
  15. end
  16. end
  17.  
  18. -- Grabs fuel from fuelchest above the turtle, drops anything in slot 1 if it's not coal
  19. function GrabFuel() --fin?
  20. if turtle.getItemCount(1) > 0 then
  21. if turtle.getItemDetail(1).name ~= "minecraft:coal" then
  22. print("That's not fuel.. Ew!")
  23. turtle.select(1)
  24. turtle.drop()
  25. end
  26. end
  27. if turtle.getItemCount(1) < 16 and status == 1 then
  28. print("Grabbing Fuel..")
  29. turtle.select(1)
  30. turtle.suckUp(16)
  31. end
  32. end
  33.  
  34. function DropOff()
  35. turtle.turnLeft()
  36. for i = 2, 16 do
  37. if turtle.getItemCount(i) > 0 then
  38. if turtle.getItemDetail(i).name == "minecraft:wheat_seed" then
  39. turtle.select(i)
  40. turtle.drop()
  41. elseif turtle.getItemDetail(i).name == "minecraft:coal" then
  42. turtle.select(i)
  43. turtle.dropUp()
  44. else
  45. turtle.select(i)
  46. turtle.dropDown()
  47. end
  48. end
  49. end
  50. turtle.select(2)
  51. turtle.suck()
  52. turtle.select(3)
  53. turtle.suck()
  54. turtle.turnRight()
  55. end
  56.  
  57. -- Inspects the block infront, above or below the turtle.
  58. function GetBlock(side) -- fin
  59. if side == 1 then
  60. local s, d = turtle.inspect()
  61. if s then return d else return false end
  62. elseif side == 2 then
  63. local s, d = turtle.inspectUp()
  64. if s then return d else return false end
  65. elseif side == 3 then
  66. local s, d = turtle.inspectDown()
  67. if s then return d else return false end
  68. end
  69. end
  70.  
  71. -- Returns the turtle to the station
  72. function Return() --fin?
  73. if status == 0 then
  74. local front = GetBlock(1)
  75. if front and front.name == "immersiveengineering:metal_decoration1" then
  76. turtle.turnLeft()
  77. elseif front and front.name == "minecraft:hardened_clay" then
  78. turtle.turnLeft()
  79. turtle.forward()
  80. elseif front and front.name == "minecraft:chest" then
  81. turtle.turnLeft()
  82. turtle.forward()
  83. turtle.turnRight()
  84. turtle.forward()
  85. turtle.turnLeft()
  86. turtle.down()
  87. turtle.back()
  88. status = 1
  89. else
  90. turtle.forward()
  91. end
  92. end
  93. end
  94.  
  95. function GetSeedCount()
  96. local seed1 = turtle.getItemCount(2)
  97. local seed2 = turtle.getItemCount(3)
  98. if seed1 > 0 and turtle.getItemDetail(2).name ~= "minecraft:wheat_seed" then seed1 = 0 end
  99. if seed2 > 0 and turtle.getItemDetail(3).name ~= "minecraft:wheat_seed" then seed2 = 0 end
  100. return seed1, seed2
  101. end
  102.  
  103. function HasSeeds()
  104. local seed1, seed2 = GetSeedCount()
  105. if seed1 == 0 and seed2 == 0 then return false else return true end
  106. end
  107.  
  108. function Replant()
  109. local seed1, seed2 = GetSeedCount()
  110. for i=2,3 do
  111. if seed1 > 0 then
  112. print("Found seed1")
  113. turtle.select(2)
  114. turtle.placeDown()
  115. elseif seed2 > 0 then
  116. print("Found seed2")
  117. turtle.select(3)
  118. turtle.placeDown()
  119. end
  120. end
  121. end
  122.  
  123. -- Checks if plant is ready to be harvested, or if soil needs retilling/replanting
  124. function CheckPlant()
  125. print("Inspecting farmland..")
  126. local under = GetBlock(3)
  127. if not under and HasSeeds() then
  128. turtle.digDown()
  129. Replant()
  130. elseif under.name == "minecraft:wheat" and under.metadata == 7 then
  131. print("Found mature plant, harvesting..")
  132. turtle.placeDown()
  133. end
  134. end
  135.  
  136. function Farm()
  137. -- Are we full yet?
  138. local front = GetBlock(1)
  139. if turtle.getItemCount(16) > 0 then
  140. status = 0
  141. elseif not front then
  142. turtle.forward()
  143. sleep(0.1)
  144. turtle.suckDown()
  145. CheckPlant()
  146. elseif front.name == "immersiveengineering:metal_decoration1"
  147. or front.name == "minecraft:hardened_clay" then
  148. CheckPlant()
  149. if j == 0 then
  150. j = 1
  151. turtle.turnLeft()
  152. turtle.forward()
  153. CheckPlant()
  154. sleep(0.1)
  155. turtle.suckDown()
  156. turtle.turnLeft()
  157. elseif j == 1 then
  158. j = 0
  159. turtle.turnRight()
  160. local front2 = GetBlock(1)
  161. if not front2 then
  162. turtle.forward()
  163. CheckPlant()
  164. sleep(0.1)
  165. turtle.suckDown()
  166. turtle.turnRight()
  167. elseif front2.name == "immersiveengineering:metal_decoration1"
  168. or front2.name == "minecraft:hardened_clay" then
  169. status = 0
  170. n = n + 1
  171. end
  172. end
  173. end
  174. end
  175.  
  176. -- Main Loop
  177. while true do
  178. if turtle.getFuelLevel() < 10 then
  179. Refuel()
  180. end
  181. if status == 0 then
  182. print("Finding home..")
  183. Return()
  184. end
  185. if status == 1 then
  186. print("Refueling.. Storing.. Polishing..")
  187. DropOff()
  188. GrabFuel()
  189. print("Maintenance completed!")
  190. turtle.forward()
  191. turtle.up()
  192. status = 2
  193. if n % 2 == 0 and n > 0 then
  194. for i = 1,5 do
  195. print("Waiting: " .. 5-i .. " seconds for the plants to grow..")
  196. sleep(1)
  197. end
  198. n = 1
  199. end
  200. end
  201. if status == 2 then
  202. Farm()
  203. end
  204. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement