Advertisement
EphemeralKap

Untitled

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