Advertisement
EphemeralKap

Untitled

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