Advertisement
EphemeralKap

Untitled

Dec 7th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 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.suckUp(16)
  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.drop()
  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"
  60. or GetBlock(1) == "minecraft:hardened_clay" then
  61. status = 0
  62. n = n + 1
  63. else
  64. turtle.forward()
  65. turtle.digDown()
  66. turtle.turnRight()
  67. end
  68. end
  69. else
  70. turtle.forward()
  71. turtle.digDown()
  72. end
  73. end
  74.  
  75. -- Returns the turtle to the station
  76. function Return()
  77. if status == 0 then
  78. front = GetBlock(1)
  79. if front == "immersiveengineering:metal_decoration1" then
  80. turtle.turnLeft()
  81. elseif front == "minecraft:hardened_clay" then
  82. if GetBlock(3) == "minecraft:chest" then
  83. turtle.turnLeft()
  84. turtle.forward()
  85. turtle.down()
  86. turtle.down()
  87. turtle.back()
  88. status = 1
  89. else
  90. turtle.turnLeft()
  91. turtle.forward()
  92. end
  93. else
  94. turtle.forward()
  95. end
  96. end
  97. end
  98.  
  99. -- Inspects the block infront, above or below the turtle.
  100. function GetBlock(side)
  101. if side == 1 then
  102. local s, d = turtle.inspect()
  103. if s then return d.name else return false end
  104. elseif side == 2 then
  105. local s, d = turtle.inspectUp()
  106. if s then return d.name else return false end
  107. elseif side == 3 then
  108. local s, d = turtle.inspectDown()
  109. if s then return d.name else return false end
  110. end
  111. end
  112.  
  113.  
  114. -- Main Loop
  115. while true do
  116. if turtle.getFuelLevel() < 10 then
  117. Refuel()
  118. end
  119. if status == 0 then
  120. print("Finding home..")
  121. Return()
  122. end
  123. if status == 1 then
  124. print("Refueling.. Storing.. Polishing..")
  125. DropOff()
  126. GrabFuel()
  127. print("Maintenance completed!")
  128. turtle.forward()
  129. turtle.up()
  130. turtle.up()
  131. status = 2
  132. if n % 2 == 0 and n > 0 then
  133. for i = 1,120 do
  134. print("Waiting: " .. 60-i .. " seconds for the plants to grow..")
  135. sleep(1)
  136. end
  137. n = 1
  138. end
  139. end
  140. if status == 2 then
  141. print("Searching for hemp..")
  142. Farm()
  143. end
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement