Advertisement
EphemeralKap

Untitled

Dec 5th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. -- 0 = Return, 1 = Maintenance, 2 = Farming, 3 = Critical
  2. local status = 0
  3. local n = 3
  4. local length = 9
  5. local stepsToGo = 9
  6. local stepsSoFar = 0
  7.  
  8. --Return to station
  9. function Return()
  10. if status == 0 then
  11. local front = GetBlock(1)
  12. local under = GetBlock(3)
  13.  
  14. if front == "minecraft:chest" and under == "minecraft:chest" then
  15. turtle.turnLeft()
  16. turtle.turnLeft()
  17. status = 1
  18. if front == "botania:flower" then
  19. turtle.dig()
  20. turtle.forward()
  21. elseif front == "botania:specialflower" then
  22. turtle.turnLeft()
  23. elseif front == "minecraft:chest" then
  24. turtle.turnLeft()
  25. turtle.dig()
  26. turtle.forward()
  27. turtle.turnRight()
  28. turtle.forward()
  29. turtle.turnLeft()
  30. status = 1
  31. else
  32. local under = GetBlock(3)
  33. if under == "minecraft:stone" or under == "minecraft:grass" then
  34. turtle.forward()
  35. elseif under == "minecraft:cobblestone" then
  36. turtle.back()
  37. turtle.turnLeft()
  38. else
  39. status = 3
  40. end
  41. end
  42. end
  43. end
  44.  
  45. -- Inspects the block infront, above or below the turtle.
  46. function GetBlock(side)
  47. if side == 1 then
  48. local s, d = turtle.inspect()
  49. if s then return d.name else return false end
  50. elseif side == 2 then
  51. local s, d = turtle.inspectUp()
  52. if s then return d.name else return false end
  53. elseif side == 3 then
  54. local s, d = turtle.inspectDown()
  55. if s then return d.name else return false end
  56. end
  57. end
  58.  
  59. function Refuel()
  60. print("Refueling..")
  61. turtle.select(1)
  62. if not turtle.refuel(3) then
  63. print("Fuel reserves low.. Returning home")
  64. status = 0
  65. end
  66. end
  67.  
  68. function PickFlowers()
  69. local front = GetBlock(1)
  70. if front == "botania:flower" then
  71. turtle.dig()
  72. turtle.forward()
  73. elseif front == "botania:specialflower" then
  74. turtle.turnLeft()
  75. status = 0
  76. return
  77. else
  78. turtle.forward()
  79. end
  80.  
  81. if stepsSoFar == stepsToGo then n = n - 1 end
  82. if n == 0 then stepsToGo = stepsToGo - 1 end
  83.  
  84. print("Togo: " .. stepsToGo .. " SoFar: " .. stepsSoFar .. "N: " .. n)
  85.  
  86. end
  87.  
  88. function GrabFuel()
  89. if turtle.getItemCount(1) > 0 then
  90. if turtle.getItemDetail(1).name ~= "minecraft:coal" then
  91. print("That's not fuel.. Ew!")
  92. turtle.select(1)
  93. turtle.drop()
  94. end
  95. end
  96. if turtle.getItemCount(1) < 16 and status == 1 then
  97. print("Grabbing Fuel..")
  98. turtle.select(1)
  99. turtle.suckDown()
  100. end
  101. end
  102.  
  103. function DropOff()
  104. turtle.turnLeft()
  105. turtle.turnLeft()
  106. for i=2,16 do
  107. if turtle.getItemCount(i) > 0 then
  108. turtle.select(i)
  109. turtle.dropUp()
  110. end
  111. end
  112. turtle.turnLeft()
  113. turtle.turnLeft()
  114. end
  115.  
  116. --main loop
  117. while true do
  118. if turtle.getFuelLevel() < 10 then
  119. Refuel()
  120. end
  121. if status == 0 then
  122. print("Finding home..")
  123. Return()
  124. end
  125. if status == 1 then
  126. n = 3
  127. stepsToGo = 9
  128. stepsSoFar = 0
  129.  
  130. print("Refueling.. Storing.. Polishing..")
  131. DropOff()
  132. GrabFuel()
  133. print("Maintenance completed!")
  134. status = 2
  135. end
  136. if status == 2 then
  137. print("Picking Flowers..")
  138. end
  139. if status == 3 then
  140. print("Critical error..")
  141. sleep(20)
  142. break
  143. end
  144. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement