Advertisement
EphemeralKap

Untitled

Dec 7th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.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. local cornerBlock = "immersiveengineering:metal_decoration1"
  6. local railBlock = "minecraft:hardened_clay"
  7. local harvestBlock = "harvestcraft:pameggplantcrop"
  8. local storageBlock = "minecraft:chest"
  9. local harvestAge = 3
  10. local harvestMethod = 1 -- 1 = PlaceMethod, 2 = DigMethod
  11.  
  12. --todo fix return, fix farm
  13.  
  14. -- Refuels the turtle if fuel levels are low
  15. function Refuel() --fin?
  16. print("Refueling..")
  17. turtle.select(1)
  18. if not turtle.refuel(3) then
  19. print("Fuel reserves low.. Returning home")
  20. status = 0
  21. end
  22. end
  23.  
  24. -- Grabs fuel from fuelchest above the turtle, drops anything in slot 1 if it's not coal
  25. function GrabFuel() --fin?
  26. if turtle.getItemCount(1) > 0 then
  27. if turtle.getItemDetail(1).name ~= "minecraft:coal" then
  28. print("That's not fuel.. Ew!")
  29. turtle.select(1)
  30. turtle.drop()
  31. end
  32. end
  33. if turtle.getItemCount(1) < 16 and status == 1 then
  34. print("Grabbing Fuel..")
  35. turtle.select(1)
  36. turtle.suckUp(16)
  37. end
  38. end
  39.  
  40. --Drops the harvested item into storage below
  41. function DropOff()
  42. for i = 2, 16 do
  43. if turtle.getItemCount(i) > 0 then
  44. turtle.select(i)
  45. turtle.dropDown()
  46. end
  47. end
  48. end
  49.  
  50. -- Inspects the block infront, above or below the turtle.
  51. function GetBlock(side) -- fin
  52. if side == 1 then
  53. local s, d = turtle.inspect()
  54. if s then return d else return false end
  55. elseif side == 2 then
  56. local s, d = turtle.inspectUp()
  57. if s then return d else return false end
  58. elseif side == 3 then
  59. local s, d = turtle.inspectDown()
  60. if s then return d else return false end
  61. end
  62. end
  63.  
  64. -- Returns the turtle to the station
  65. function Return() --fin?
  66. if status == 0 then
  67. local front = GetBlock(1)
  68. if front and front.name == railBlock then
  69. turtle.turnLeft()
  70. elseif front and front.name == cornerBlock then
  71. turtle.turnLeft()
  72. turtle.forward()
  73. elseif front and front.name == storageBlock then
  74. turtle.turnLeft()
  75. turtle.forward()
  76. turtle.turnRight()
  77. turtle.forward()
  78. turtle.turnLeft()
  79. turtle.down()
  80. turtle.back()
  81. status = 1
  82. else
  83. turtle.forward()
  84. end
  85. end
  86. end
  87.  
  88. -- Checks if plant is ready to be harvested
  89. function CheckPlant()
  90. print("Inspecting farmland..")
  91. local under = GetBlock(3)
  92. if under then
  93. if under.name == harvestBlock then
  94. if harvestAge ~= nil then
  95. if under.metadata == harvestAge then
  96. if harvestMethod == 1 then
  97. turtle.placeDown()
  98. elseif harvestMethod == 2 then
  99. turtle.digDown()
  100. end
  101. end
  102. else
  103. turtle.digDown()
  104. end
  105. end
  106. end
  107. end
  108.  
  109. function Farm()
  110. -- Are we full yet?
  111. local front = GetBlock(1)
  112. if turtle.getItemCount(16) > 0 then
  113. status = 0
  114. elseif not front then
  115. turtle.forward()
  116. CheckPlant()
  117. elseif front.name == railBlock or front.name == cornerBlock then
  118. CheckPlant()
  119. if j == 0 then
  120. j = 1
  121. turtle.turnLeft()
  122. turtle.forward()
  123. CheckPlant()
  124. turtle.turnLeft()
  125. elseif j == 1 then
  126. j = 0
  127. turtle.turnRight()
  128. local front2 = GetBlock(1)
  129. if not front2 then
  130. turtle.forward()
  131. CheckPlant()
  132. turtle.turnRight()
  133. elseif front2.name == railBlock or front2.name == cornerBlock then
  134. status = 0
  135. n = n + 1
  136. end
  137. end
  138. end
  139. end
  140.  
  141. -- Main Loop
  142. while true do
  143. if turtle.getFuelLevel() < 10 then
  144. Refuel()
  145. end
  146. if status == 0 then
  147. print("Finding home..")
  148. Return()
  149. end
  150. if status == 1 then
  151. print("Refueling.. Storing.. Polishing..")
  152. DropOff()
  153. GrabFuel()
  154. print("Maintenance completed!")
  155. turtle.forward()
  156. turtle.up()
  157. status = 2
  158. if n % 2 == 0 and n > 0 then
  159. for i = 1,5 do
  160. print("Waiting: " .. 5-i .. " seconds for the plants to grow..")
  161. sleep(1)
  162. end
  163. n = 1
  164. end
  165. end
  166. if status == 2 then
  167. Farm()
  168. end
  169. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement