Advertisement
pson

MiningTunnels.Lua

Jun 17th, 2020 (edited)
1,356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1.  
  2. function forward()
  3.     while turtle.detect() do
  4.         turtle.dig()
  5.         sleep(0.5)
  6.     end
  7.     flag = turtle.forward()
  8.     while not flag do
  9.         turtle.attack()
  10.         sleep(0.5)
  11.         flag = turtle.forward()
  12.     end
  13. end
  14.  
  15. function up()
  16.     while turtle.detectUp() do
  17.         turtle.digUp()
  18.         sleep(0.5)
  19.     end
  20.     flag = turtle.up()
  21.     while not flag do
  22.         turtle.attackUp()
  23.         sleep(0.5)
  24.         flag = turtle.up()
  25.     end
  26. end
  27.  
  28. function down()
  29.     while turtle.detectDown() do
  30.         turtle.digDown()
  31.         sleep(0.5)
  32.     end
  33.     flag = turtle.down()
  34.     while not flag do
  35.         turtle.attackDown()
  36.         sleep(0.5)
  37.         flag = turtle.down()
  38.     end
  39. end
  40.  
  41. function restock() -- Try to refill slots 1 to 15
  42.     local i, j
  43.     for i=1,13,1 do
  44.         turtle.select(i)
  45.         for j=i+1,14,1 do
  46.             if turtle.compareTo(j) then
  47.                 turtle.select(j)
  48.                 turtle.transferTo(i)
  49.                 turtle.select(i)
  50.             end            
  51.         end
  52.     end
  53. end
  54.  
  55. function check_front()
  56.     if not turtle.detect() then
  57.         turtle.select(2)
  58.         turtle.place()
  59.     end
  60. end
  61.  
  62. function check_up()
  63.     if not turtle.detectUp() then
  64.         turtle.select(2)
  65.         turtle.placeUp()
  66.     end
  67. end
  68.  
  69. function check_down()
  70.     if not turtle.detectDown() then
  71.         turtle.select(2)
  72.         turtle.placeDown()
  73.     end
  74. end
  75.  
  76. function check()
  77.     turtle.turnLeft()
  78.     check_front()
  79.     turtle.turnRight()
  80.     turtle.turnRight()
  81.     check_front()
  82.     turtle.turnLeft()
  83. end
  84.  
  85. function upAndDown()
  86.     if turtle.getItemCount(2) < 16 then
  87.         restock()
  88.         if turtle.getItemCount(2) < 16 then
  89.             local i
  90.             up()
  91.             for i=1,8 do
  92.                 turtle.back()
  93.             end
  94.             down()
  95.             error()
  96.         end
  97.     end
  98.     check_down()
  99.     check()
  100.     up()
  101.     check()
  102.     up()
  103.     check()
  104.     check_up()
  105.     forward()
  106.     check_up()
  107.     check()
  108.     down()
  109.     check()
  110.     down()
  111.     check()
  112.     check_down()
  113. end
  114.  
  115. function section()
  116.     local i
  117.  
  118.     while turtle.getFuelLevel() < 30 do
  119.         turtle.select(1)
  120.         turtle.refuel(1)
  121.     end
  122.     upAndDown()
  123.     forward()
  124.     upAndDown()
  125.     forward()
  126.     turtle.select(15)
  127.     turtle.turnLeft()
  128.     turtle.turnLeft()
  129.     turtle.place()
  130.     turtle.turnLeft()
  131.     turtle.turnLeft()    
  132.     upAndDown()
  133.     forward()
  134.     upAndDown()
  135.     if turtle.getItemCount(13) > 0 then
  136.         restock()
  137.         turtle.turnLeft()
  138.         turtle.turnLeft()
  139.         turtle.select(16)
  140.         turtle.place()
  141.         for i=3,14,1 do
  142.             turtle.select(i)
  143.             turtle.drop()
  144.         end
  145.         turtle.turnLeft()
  146.         turtle.turnLeft()    
  147.     end
  148. end
  149.  
  150. function tunnel(...)
  151.     local args = {...}
  152.     if #args ~= 1 then
  153.         print "Usage: tunnel <length of tunnel>"
  154.         print "- Slot  1: Fuel"
  155.         print "- Slot  2: Wall filler"
  156.         print "- Slot 15: Torches"
  157.         print "- Slot 16: Chests"
  158.         error()
  159.     end
  160.  
  161.     local i=0
  162.     local tlen=tonumber(args[1])
  163.     while tlen > 0 do
  164.         section()
  165.         tlen = tlen-8
  166.         if tlen > 0 then
  167.             forward()
  168.         end
  169.         i = i+1
  170.     end
  171.     restock()
  172.     turtle.back()
  173.     turtle.select(2)
  174.     turtle.place()
  175.     turtle.up()
  176.     turtle.place()
  177.     turtle.up()
  178.     turtle.place()
  179.     turtle.down()
  180.     turtle.down()    
  181.     turtle.turnLeft()
  182.     turtle.turnLeft()
  183.     up()
  184.     i = (i*8)-2
  185.     while i > 0 do
  186.         while turtle.getFuelLevel() < 10 do
  187.             turtle.select(1)
  188.             turtle.refuel(1)
  189.         end    
  190.         turtle.forward()
  191.         i = i-1
  192.     end
  193.     turtle.select(16)        
  194.     turtle.placeDown()
  195.     for i=1,16,1 do
  196.         turtle.select(i)
  197.         turtle.dropDown()
  198.     end
  199. end
  200. tunnel(...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement