EphemeralKap

Untitled

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