Advertisement
EphemeralKap

Untitled

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