Advertisement
EphemeralKap

Untitled

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