Advertisement
EphemeralKap

Untitled

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