EphemeralKap

Untitled

Dec 5th, 2017
132
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. turtle.select(1)
  9. if not turtle.refuel(3) then
  10. print("Fuel reserves low.. Returning home")
  11. status = 0
  12. end
  13. end
  14.  
  15. -- Grabs fuel from fuelchest under the turtle, drops anything in slot 1 if it's not coal
  16. function GrabFuel()
  17. if turtle.getItemCount(1) > 0 then
  18. if turtle.getItemDetail(1).name ~= "minecraft:coal" then
  19. print("That's not fuel.. Ew!")
  20. turtle.select(1)
  21. turtle.drop()
  22. end
  23. end
  24. if turtle.getItemCount(1) < 16 and status == 1 then
  25. print("Grabbing Fuel..")
  26. turtle.select(1)
  27. turtle.suckDown()
  28. end
  29. end
  30.  
  31. -- Stores everything but fuel in the dropoff chest above the turtle
  32. function DropOff()
  33. n = n + 1
  34. for i=2,16 do
  35. if turtle.getItemCount(i) > 0 then
  36. turtle.select(i)
  37. turtle.dropUp()
  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" then
  48. turtle.digDown()
  49. turtle.turnLeft()
  50. turtle.forward()
  51. turtle.digDown()
  52. turtle.turnLeft()
  53. else
  54. turtle.forward()
  55. turtle.digDown()
  56. end
  57. end
  58.  
  59. -- Returns the turtle to the station
  60. function Return()
  61. if status == 0 then
  62. front = GetBlock(1)
  63. if front == "immersiveengineering:metal_decoration1" then
  64. turtle.turnLeft()
  65. elseif front == "minecraft:hardened_clay" then
  66. if GetBlock(3) == "minecraft:chest" then
  67. turtle.turnLeft()
  68. turtle.forward()
  69. turtle.down()
  70. turtle.down()
  71. turtle.back()
  72. status = 1
  73. else
  74. turtle.turnLeft()
  75. turtle.forward()
  76. end
  77. else
  78. turtle.forward()
  79. end
  80. end
  81. end
  82.  
  83. -- Inspects the block infront, above or below the turtle.
  84. function GetBlock(side)
  85. if side == 1 then
  86. local s, d = turtle.inspect()
  87. if s then return d.name else return false end
  88. elseif side == 2 then
  89. local s, d = turtle.inspectUp()
  90. if s then return d.name else return false end
  91. elseif side == 3 then
  92. local s, d = turtle.inspectDown()
  93. if s then return d.name else return false end
  94. end
  95. end
  96.  
  97.  
  98. -- Main Loop
  99. while true do
  100. if turtle.getFuelLevel() < 10 then
  101. refuel()
  102. end
  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