adamg765

Tunnel2021_2

Jan 21st, 2021 (edited)
449
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local args = {...}
  2. local distance = tonumber(args[1])
  3. local fuel = 1
  4. local torches = 2
  5. local place_block = 3
  6. local max_slot = 16
  7.  
  8. local function refuel()
  9.     if turtle.getFuelLevel() == 0 then
  10.         local prev = turtle.getSelectedSlot()
  11.         turtle.select(fuel)
  12.         if not turtle.refuel(1) then
  13.             print('Need more fuel')
  14.             while not turtle.refuel(1) do
  15.                 sleep(1)
  16.             end
  17.         end
  18.         turtle.select(prev)
  19.     end
  20. end
  21.  
  22. -- local function smart_dig_forward()
  23. --     if turtle.detect() then
  24. --         turtle.dig()
  25. --     else
  26. --         return
  27. --     end
  28.  
  29. --     local slot = turtle.getSelectedSlot()
  30. --     local i = 0
  31.  
  32. --     if (slot != max_slot) then
  33. --         while (turtle.getItemCount() > 0 and slot != max_slot)
  34. --         do
  35. --             turtle.select(slot + i)
  36. --             i = i + 1
  37. --         end
  38. --     end
  39. -- end
  40.  
  41.  
  42. local function tryForwards()
  43.     refuel()
  44.     while not turtle.forward() do
  45.         if turtle.detect() then
  46.             turtle.dig()
  47.         end
  48.         sleep(0.5)
  49.     end
  50. end
  51.  
  52. local function tryDown()
  53.     refuel()
  54.     while not turtle.down() do
  55.         if turtle.detectDown() then
  56.             turtle.digDown()
  57.         end
  58.         sleep(0.5)
  59.     end
  60. end
  61.  
  62. local function tryUp()
  63.     refuel()
  64.     while not turtle.up() do
  65.         if turtle.detectUp() then
  66.             turtle.digUp()
  67.         end
  68.         sleep(0.5)
  69.     end
  70. end
  71.  
  72. local function dig_block_gravel()
  73.     turtle.dig()
  74.     sleep(.5)
  75.     while turtle.detect() do
  76.         turtle.dig()
  77.     end
  78. end
  79.  
  80. local function placeTorch()
  81.     local prev = turtle.getSelectedSlot()
  82.     turtle.select(torches)
  83.     turtle.place()
  84.     turtle.select(prev)
  85. end
  86.  
  87. local function placeBlock()
  88.     local prev = turtle.getSelectedSlot()
  89.     turtle.select(place_block)
  90.     turtle.placeDown()
  91.     turtle.select(prev)
  92. end
  93.  
  94. local function clearSection(currDistance)
  95.     tryUp()
  96.     tryUp()
  97.  
  98.     tryForwards()
  99.  
  100.     turtle.turnLeft()
  101.     dig_block_gravel()
  102.  
  103.     turtle.turnRight()
  104.     turtle.turnRight()
  105.     dig_block_gravel()
  106.  
  107.  
  108.     turtle.turnLeft()
  109.     tryDown()
  110.  
  111.     turtle.turnLeft()
  112.     turtle.dig()
  113.     if currDistance % 6 == 1 then
  114.         placeTorch()
  115.     end
  116.  
  117.     turtle.turnRight()
  118.     turtle.turnRight()
  119.     turtle.dig()
  120.     if currDistance % 6 == 1 then
  121.         placeTorch()
  122.     end
  123.  
  124.     turtle.turnLeft()
  125.     tryDown()
  126.  
  127.     if not turtle.detectDown() then
  128.         placeBlock()
  129.     end
  130.  
  131.     turtle.turnLeft()
  132.     tryForwards()
  133.  
  134.     if not turtle.detectDown() then
  135.         placeBlock()
  136.     end
  137.    
  138.  
  139.     turtle.turnRight()
  140.     turtle.turnRight()
  141.     tryForwards()
  142.     tryForwards()
  143.  
  144.     if not turtle.detectDown() then
  145.         placeBlock()
  146.     end
  147.  
  148.     turtle.turnLeft()
  149.     turtle.turnLeft()
  150.     tryForwards()
  151.  
  152.     turtle.turnRight()
  153. end
  154.  
  155.  
  156.  
  157. local curr_distance = 0
  158.  
  159. while(curr_distance <= distance)
  160. do
  161.     turtle.select(1)
  162.  
  163.     for i = curr_distance, distance-1, 1 do
  164.         clearSection(i)
  165.  
  166.         local slot = turtle.getSelectedSlot()
  167.        
  168.         if (slot ~= max_slot) then
  169.             local j = 0
  170.             while (turtle.getItemCount() > 0 and turtle.getSelectedSlot() ~= max_slot)
  171.             do
  172.                 turtle.select(slot + j)
  173.                 j = j + 1
  174.             end
  175.         end
  176.        
  177.         curr_distance = curr_distance + 1
  178.  
  179.         if (turtle.getSelectedSlot() == 16) then
  180.             break
  181.         else
  182.             turtle.select(slot)
  183.         end
  184.  
  185.     end
  186.     print(curr_distance)
  187.  
  188.     turtle.turnRight()
  189.     turtle.turnRight()
  190.  
  191.     for i = 1, curr_distance, 1 do
  192.         tryForwards()
  193.     end
  194.  
  195.     for i = 4, 16, 1 do
  196.         turtle.select(i)
  197.         turtle.drop()
  198.     end
  199.  
  200.     turtle.turnRight()
  201.     turtle.turnRight()
  202.  
  203.     if (curr_distance == distance) then
  204.         break
  205.     end
  206.  
  207.     for i = 1, curr_distance, 1 do
  208.         tryForwards()
  209.     end
  210. end
RAW Paste Data