adamg765

Tunnel2021_2

Jan 21st, 2021 (edited)
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.98 KB | None | 0 0
  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.     sleep(.25)
  97.     tryUp()
  98.  
  99.     tryForwards()
  100.  
  101.     turtle.turnLeft()
  102.     dig_block_gravel()
  103.  
  104.     turtle.turnRight()
  105.     turtle.turnRight()
  106.     dig_block_gravel()
  107.  
  108.  
  109.     turtle.turnLeft()
  110.     tryDown()
  111.  
  112.     turtle.turnLeft()
  113.     turtle.dig()
  114.     if currDistance % 6 == 1 then
  115.         placeTorch()
  116.     end
  117.  
  118.     turtle.turnRight()
  119.     turtle.turnRight()
  120.     turtle.dig()
  121.     if currDistance % 6 == 1 then
  122.         placeTorch()
  123.     end
  124.  
  125.     turtle.turnLeft()
  126.     tryDown()
  127.  
  128.     if not turtle.detectDown() then
  129.         placeBlock()
  130.     end
  131.  
  132.     turtle.turnLeft()
  133.     tryForwards()
  134.  
  135.     if not turtle.detectDown() then
  136.         placeBlock()
  137.     end
  138.    
  139.  
  140.     turtle.turnRight()
  141.     turtle.turnRight()
  142.     tryForwards()
  143.     tryForwards()
  144.  
  145.     if not turtle.detectDown() then
  146.         placeBlock()
  147.     end
  148.  
  149.     turtle.turnLeft()
  150.     turtle.turnLeft()
  151.     tryForwards()
  152.  
  153.     turtle.turnRight()
  154. end
  155.  
  156.  
  157.  
  158. local curr_distance = 0
  159.  
  160. while(curr_distance <= distance)
  161. do
  162.     turtle.select(1)
  163.  
  164.     for i = curr_distance, distance-1, 1 do
  165.         clearSection(i)
  166.  
  167.         local slot = turtle.getSelectedSlot()
  168.        
  169.         if (slot ~= max_slot) then
  170.             local j = 0
  171.             while (turtle.getItemCount() > 0 and turtle.getSelectedSlot() ~= max_slot)
  172.             do
  173.                 turtle.select(slot + j)
  174.                 j = j + 1
  175.             end
  176.         end
  177.        
  178.         curr_distance = curr_distance + 1
  179.  
  180.         if (turtle.getSelectedSlot() == 16) then
  181.             break
  182.         else
  183.             turtle.select(slot)
  184.         end
  185.  
  186.     end
  187.     print(curr_distance)
  188.  
  189.     turtle.turnRight()
  190.     turtle.turnRight()
  191.  
  192.     for i = 1, curr_distance, 1 do
  193.         tryForwards()
  194.     end
  195.  
  196.     for i = 4, 16, 1 do
  197.         turtle.select(i)
  198.         turtle.drop()
  199.     end
  200.  
  201.     turtle.turnRight()
  202.     turtle.turnRight()
  203.  
  204.     if (curr_distance == distance) then
  205.         break
  206.     end
  207.  
  208.     for i = 1, curr_distance, 1 do
  209.         tryForwards()
  210.     end
  211. end
Advertisement
Add Comment
Please, Sign In to add comment