Advertisement
EphemeralKap

Untitled

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