Advertisement
EphemeralKap

Untitled

Dec 5th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 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 row = row - 1 end
  85. if row == 0 then stepsToGo = stepsToGo - 1 end
  86.  
  87. print("Togo: " .. stepsToGo .. " SoFar:" .. stepsSoFar .. "N: " .. row)
  88.  
  89. end
  90.  
  91. function GrabFuel()
  92. if turtle.getItemCount(1) > 0 then
  93. if turtle.getItemDetail(1).name ~= "minecraft:coal" then
  94. print("That's not fuel.. Ew!")
  95. turtle.select(1)
  96. turtle.drop()
  97. end
  98. end
  99. if turtle.getItemCount(1) < 16 and status == 1 then
  100. print("Grabbing Fuel..")
  101. turtle.select(1)
  102. turtle.suckDown()
  103. end
  104. end
  105.  
  106. function DropOff()
  107. turtle.turnLeft()
  108. turtle.turnLeft()
  109. for i=2,16 do
  110. if turtle.getItemCount(i) > 0 then
  111. turtle.select(i)
  112. turtle.dropUp()
  113. end
  114. end
  115. turtle.turnLeft()
  116. turtle.turnLeft()
  117. end
  118.  
  119. --main loop
  120. while true do
  121. if turtle.getFuelLevel() < 10 then
  122. Refuel()
  123. end
  124. if status == 0 then
  125. print("Finding home..")
  126. Return()
  127. end
  128. if status == 1 then
  129. n = 3
  130. stepsToGo = 9
  131. stepsSoFar = 0
  132.  
  133. print("Refueling.. Storing.. Polishing..")
  134. DropOff()
  135. GrabFuel()
  136. print("Maintenance completed!")
  137. status = 2
  138. end
  139. if status == 2 then
  140. PickFlowers()
  141. end
  142. if status == 3 then
  143. print("Critical error..")
  144. sleep(20)
  145. break
  146. end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement