Advertisement
EphemeralKap

Untitled

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