EphemeralKap

Untitled

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