Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. print("Excavator turtle reporting for duty!")
  2. print("How many 6x6 chunks should I excavate?")
  3. local max_excavations = tonumber(io.read())
  4. local z_pos = 0
  5. local fuel_limit = 20000
  6.  
  7. local dump_to_chest
  8. local find_fuel
  9. local refuel
  10. local try_down
  11. local move_to_next_layer
  12. local dig_forward
  13. local dig_layer
  14. local try_up
  15. local excavate
  16. local finished
  17.  
  18. dump_to_chest = function()
  19. -- dig above to ensure chest placement. Will continue to dig until detectUp() yields false.
  20. repeat
  21. turtle.digUp()
  22. sleep(0.6)
  23. until not turtle.detectUp()
  24. -- place Ender Chest
  25. turtle.select(1)
  26. turtle.placeUp()
  27. -- consume all fuel items up to max fuel limit
  28. refuel()
  29. -- dump to Ender Chest
  30. for slot = 2, 16 do
  31. turtle.select(slot)
  32. turtle.dropUp()
  33. end
  34. -- reclaim Ender Chest
  35. sleep(0.2)
  36. turtle.select(1)
  37. turtle.digUp()
  38. end
  39.  
  40. -- Look for and consume fuel sources, starting with slot 2
  41. find_fuel = function()
  42. for slot = 2, 16 do
  43. turtle.select(slot)
  44. if turtle.refuel(1) then
  45. return true
  46. end
  47. end
  48. return false
  49. end
  50.  
  51. -- Consume all fuel in inventory up to max limit
  52. refuel = function()
  53. while turtle.getFuelLevel() < fuel_limit do
  54. if not find_fuel() then
  55. break
  56. end
  57. end
  58. turtle.select(1)
  59. end
  60.  
  61. -- handles detecting finished condition (bedrock) and digging, attacking while moving down
  62. -- will return true if movement occurs, will return false if bedrock detected below
  63. try_down = function()
  64. if not turtle.down() then -- try moving down, if you can't
  65. if turtle.detectDown() then -- check for a block, if there's a block
  66. if not turtle.digDown() then -- try digging it, if you can't dig it
  67. return false
  68. else
  69. return try_down() -- try moving down now
  70. end
  71. else -- attack until whatever is there is dead or moved
  72. while turtle.attackDown() do
  73. sleep(0.5)
  74. end
  75. return try_down() -- then move down
  76. end
  77. end
  78. z_pos = z_pos + 1
  79. return true
  80. end
  81.  
  82. -- Proceed to mine next layer down
  83. move_to_next_layer = function()
  84. down_count = 0
  85. for try = 1, 3 do -- try moving down three times
  86. if try_down() then
  87. down_count = down_count + 1
  88. end
  89. end
  90. if down_count == 0 or down_count == 1 then -- if it can't move down enough to dig, call completion function
  91. finished()
  92. else
  93. dig_layer()
  94. end
  95. end
  96.  
  97. -- Dig and move forward, attacking and redigging if necessary
  98. dig_forward = function()
  99. if turtle.detect() then -- dig if there's a block in front
  100. turtle.dig()
  101. if turtle.getItemCount(16) > 0 then
  102. dump_to_chest()
  103. end
  104. end
  105. if turtle.detectUp() then -- dig up if there's a block up
  106. turtle.digUp()
  107. if turtle.getItemCount(16) > 0 then
  108. dump_to_chest()
  109. end
  110. end
  111. if turtle.detectDown() then -- dig down if there's a block down
  112. turtle.digDown()
  113. if turtle.getItemCount(16) > 0 then
  114. dump_to_chest()
  115. end
  116. end
  117. while turtle.detect() do -- keep digging and waiting if there's gravel/sand in front
  118. turtle.dig()
  119. sleep(0.6)
  120. end
  121. if turtle.getItemCount(16) > 0 then
  122. dump_to_chest()
  123. end
  124. while not turtle.forward() do -- if you can't move forward it's because of mobs (probably)
  125. turtle.attack()
  126. turtle.dig()
  127. sleep(0.5)
  128. end
  129. end
  130.  
  131. -- Dig a 6x6x3 layer
  132. dig_layer = function()
  133. for j = 1, 3 do
  134. for i = 1, 5 do
  135. dig_forward()
  136. end
  137. turtle.turnRight()
  138. end
  139. dig_forward()
  140. turtle.turnRight()
  141. for i = 1, 4 do
  142. dig_forward()
  143. end
  144. turtle.turnLeft()
  145. dig_forward()
  146. turtle.turnLeft()
  147. for i = 1, 4 do
  148. dig_forward()
  149. end
  150. turtle.turnRight()
  151. dig_forward()
  152. turtle.turnRight()
  153. for i = 1, 4 do
  154. dig_forward()
  155. end
  156. turtle.turnLeft()
  157. dig_forward()
  158. turtle.turnLeft()
  159. for i = 1, 4 do
  160. dig_forward()
  161. end
  162. turtle.turnRight()
  163. dig_forward()
  164. turtle.turnRight()
  165.  
  166. move_to_next_layer()
  167. end
  168.  
  169. try_up = function()
  170. if not turtle.up() then -- try moving up, if you can't
  171. if turtle.detectUp() then -- check for a block, if there's a block
  172. if not turtle.digUp() then -- try digging it, if you can't dig it (shouldn't happen going up)
  173. return false
  174. else
  175. return try_up() -- try moving up now
  176. end
  177. else -- attack until whatever is there is dead or moved
  178. while turtle.attackUp() do
  179. sleep(0.5)
  180. end
  181. return try_up() -- then move up
  182. end
  183. end
  184. return true
  185. end
  186.  
  187. excavate = function()
  188. -- move down twice to get below surface for first dig
  189. try_down()
  190. try_down()
  191. -- start digging, will keep moving to next layers
  192. dig_layer()
  193. end
  194.  
  195. finished = function()
  196. --dump to chest
  197. dump_to_chest()
  198. -- move back to origin
  199. for i = 1, z_pos do
  200. try_up()
  201. end
  202. if max_excavations > 1 then
  203. max_excavations = max_excavations - 1
  204. -- move forward for next iteration
  205. for i = 1, 6 do
  206. dig_forward()
  207. end
  208. z_pos = 0
  209. excavate()
  210. end
  211. for i = 1, 6 do -- move forward to be at next starting point
  212. dig_forward()
  213. end
  214. end
  215.  
  216. print("Fueling up!")
  217. refuel()
  218. print("Excavating...")
  219. excavate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement