Advertisement
EphemeralKap

Untitled

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