Advertisement
EphemeralKap

Untitled

Dec 7th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 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 then
  130. if HasSeeds() then
  131. Replant()
  132. end
  133. else
  134. if under.name == "minecraft:wheat" and under.metadata == 7 then
  135. print("Found mature plant, harvesting..")
  136. turtle.placeDown()
  137. end
  138. end
  139. end
  140.  
  141. function Farm()
  142. -- Are we full yet?
  143. local front = GetBlock(1)
  144. if turtle.getItemCount(16) > 0 then
  145. status = 0
  146. elseif not front then
  147. turtle.forward()
  148. sleep(0.1)
  149. turtle.suckDown()
  150. CheckPlant()
  151. elseif front.name == "immersiveengineering:metal_decoration1"
  152. or front.name == "minecraft:hardened_clay" then
  153. CheckPlant()
  154. if j == 0 then
  155. j = 1
  156. turtle.turnLeft()
  157. turtle.forward()
  158. CheckPlant()
  159. sleep(0.1)
  160. turtle.suckDown()
  161. turtle.turnLeft()
  162. elseif j == 1 then
  163. j = 0
  164. turtle.turnRight()
  165. local front2 = GetBlock(1)
  166. if not front2 then
  167. turtle.forward()
  168. CheckPlant()
  169. sleep(0.1)
  170. turtle.suckDown()
  171. turtle.turnRight()
  172. elseif front2.name == "immersiveengineering:metal_decoration1"
  173. or front2.name == "minecraft:hardened_clay" then
  174. status = 0
  175. n = n + 1
  176. end
  177. end
  178. end
  179. end
  180.  
  181. -- Main Loop
  182. while true do
  183. if turtle.getFuelLevel() < 10 then
  184. Refuel()
  185. end
  186. if status == 0 then
  187. print("Finding home..")
  188. Return()
  189. end
  190. if status == 1 then
  191. print("Refueling.. Storing.. Polishing..")
  192. DropOff()
  193. GrabFuel()
  194. print("Maintenance completed!")
  195. turtle.forward()
  196. turtle.up()
  197. status = 2
  198. if n % 2 == 0 and n > 0 then
  199. for i = 1,5 do
  200. print("Waiting: " .. 5-i .. " seconds for the plants to grow..")
  201. sleep(1)
  202. end
  203. n = 1
  204. end
  205. end
  206. if status == 2 then
  207. Farm()
  208. end
  209. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement