Advertisement
EphemeralKap

Untitled

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