Jharii

baleTunnel

Jan 24th, 2013
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. -- baleTunnel length tunnels gap
  2. --
  3. -- OOOOOOOOOOOOOOO
  4. --   C    C    C
  5. --   T    t    t
  6. -- OXXXOOXXXOOXXXO
  7. -- OXXXOOXXXOOXXXO
  8. -- OXXXOOXXXOOXXXO
  9. -- ---
  10. -- O - Unmined block
  11. -- C - Chest
  12. -- T - Turtle starting point
  13. -- t - Turtle starting points of subsequent tunnels beyond the first
  14. -- X - Desgnated for mining
  15. -- ---
  16. -- The concept behind this is to have the turtle do the lion's share of mining and to manually spot
  17. -- check the unmined blocks that are remaining.  A very effective method is to work in tandem with two
  18. -- turtles in the following manner:
  19. --
  20. -- OXXXOOXXXOOXXXO
  21. -- OXXXOOXXXOOXXXO
  22. -- OXXXOOXXXOOXXXO
  23. --   t    t    T
  24. --   C    C    C
  25. --   T    t    t
  26. -- OXXXOOXXXOOXXXO
  27. -- OXXXOOXXXOOXXXO
  28. -- OXXXOOXXXOOXXXO
  29. -- ---
  30. -- Two directions are mined at the same time while you mine along with them, cleaning the floors,
  31. -- ceilings, and walls in between.
  32.  
  33.  
  34. local tArgs = { ... }
  35. length = tonumber(tArgs[1]) or 24
  36. tunnels = tonumber(tArgs[2]) or 1
  37. gap = tonumber(tArgs[3]) or 2
  38.  
  39. gap = gap + 3 -- takes into account tunnel width
  40.  
  41. counter = 0
  42.  
  43. function betterDig()
  44.   success = false
  45.   while turtle.detect() do
  46.     if turtle.dig() then
  47.       success = true
  48.       counter = counter + 1
  49.     elseif turtle.attack() then
  50.     else
  51.       return success
  52.     end    
  53.     -- waits for falling blocks
  54.     sleep(.5)
  55.   end
  56.   return success
  57. end
  58.  
  59. function betterDigUp()
  60.   success = false
  61.   while turtle.detectUp() do
  62.     if turtle.digUp() then
  63.       success = true
  64.       counter = counter + 1
  65.     elseif turtle.attackUp() then
  66.     else
  67.       return success
  68.     end
  69.     -- waits for falling blocks
  70.     sleep(.5)
  71.   end
  72.   return success
  73. end
  74.  
  75. function digLeftRight()
  76.   turtle.turnLeft()
  77.   betterDig()
  78.   turtle.turnRight()
  79.   turtle.turnRight()
  80.   betterDig()
  81.   turtle.turnLeft()
  82. end
  83.  
  84. function digForward()
  85.   betterDig()
  86.   turtle.forward()
  87. end
  88.  
  89. function digUp()
  90.   betterDigUp()
  91.   turtle.up()
  92. end
  93.  
  94. function returnHome()
  95.   turtle.turnLeft()
  96.   turtle.turnLeft()
  97.   for i = 1,length do
  98.     turtle.forward()
  99.   end
  100. end
  101.  
  102. function placeTorch()
  103.     turtle.select(16)
  104.     turtle.turnRight()
  105.     turtle.place()
  106.     turtle.turnLeft()
  107.     turtle.select(1)
  108. end
  109.  
  110. for t = 1,tunnels do
  111.   for i = 1,length do
  112.     digForward()
  113.     digUp()
  114.     digUp()
  115.     digLeftRight()
  116.     turtle.down()
  117.     digLeftRight()
  118.     turtle.down()
  119.     digLeftRight()
  120.  
  121.     if i%8 == 0 then
  122.       placeTorch()
  123.     end
  124.   end
  125.  
  126.   returnHome()
  127.  
  128.   for i = 1,15 do
  129.     if turtle.getItemCount(i) > 0 then
  130.       turtle.select(i)
  131.       turtle.drop()
  132.     end
  133.   end
  134.  
  135.   if t < tunnels then
  136.     turtle.turnRight()
  137.     for i = 1,gap do
  138.       digForward()
  139.     end
  140.     turtle.turnRight()
  141.   end
  142. end
  143.  
  144. print("Job's done.")
  145. print(counter .. " total blocks mined.")
Advertisement
Add Comment
Please, Sign In to add comment