Advertisement
EphemeralKap

Untitled

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