Advertisement
EphemeralKap

Untitled

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