Advertisement
EphemeralKap

Untitled

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