EphemeralKap

Untitled

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