adamg765

Tunnel2021

Jan 21st, 2021
418
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. local function smart_dig_up()
  42.     if turtle.detectUp() then
  43.         turtle.digUp()
  44.     else
  45.         return
  46.     end
  47.  
  48.     local slot = turtle.getSelectedSlot()
  49.     local i = 0
  50.  
  51.     if (slot != max_slot) then
  52.         while (turtle.getItemCount() > 0 and slot != max_slot)
  53.         do
  54.             turtle.select(slot + i)
  55.             i = i + 1
  56.         end
  57.     end
  58. end
  59.  
  60. local function smart_dig_down()
  61.     if turtle.detectDown() then
  62.         turtle.digDown()
  63.     else
  64.         return
  65.     end
  66.  
  67.     local slot = turtle.getSelectedSlot()
  68.     local i = 0
  69.  
  70.     if (slot != max_slot) then
  71.         while (turtle.getItemCount() > 0 and slot != max_slot)
  72.         do
  73.             turtle.select(slot + i)
  74.             i = i + 1
  75.         end
  76.     end
  77. end
  78.  
  79.  
  80. local function tryForwards()
  81.     refuel()
  82.     while not turtle.forward() do
  83.         if turtle.detect() then
  84.             smart_dig_forward()
  85.         end
  86.         sleep(0.5)
  87.     end
  88. end
  89.  
  90. local function tryDown()
  91.     refuel()
  92.     while not turtle.down() do
  93.         if turtle.detectDown() then
  94.             smart_dig_down()
  95.         end
  96.         sleep(0.5)
  97.     end
  98. end
  99.  
  100. local function tryUp()
  101.     refuel()
  102.     while not turtle.up() do
  103.         if turtle.detectUp() then
  104.             smart_dig_up()
  105.         end
  106.         sleep(0.5)
  107.     end
  108. end
  109.  
  110. local function dig_block_gravel()
  111.     smart_dig_forward()
  112.     sleep(.5)
  113.     while turtle.detect() do
  114.         smart_dig_forward()
  115.     end
  116. end
  117.  
  118. local function placeTorch()
  119.     local prev = turtle.getSelectedSlot()
  120.     turtle.select(torches)
  121.     turtle.place()
  122.     turtle.select(prev)
  123. end
  124.  
  125. local function placeBlock()
  126.     local prev = turtle.getSelectedSlot()
  127.     turtle.select(place_block)
  128.     turtle.placeDown()
  129.     turtle.select(prev)
  130. end
  131.  
  132. local function clearSection(currDistance)
  133.     tryUp()
  134.     tryUp()
  135.  
  136.     tryForwards()
  137.  
  138.     turtle.turnLeft()
  139.     dig_block_gravel()
  140.  
  141.     turtle.turnRight()
  142.     turtle.turnRight()
  143.     dig_block_gravel()
  144.  
  145.  
  146.     turtle.turnLeft()
  147.     tryDown()
  148.  
  149.     turtle.turnLeft()
  150.     smart_dig_forward()
  151.     if currDistance % 6 == 0 then
  152.         turtle.turnRight()
  153.         turtle.turnRight()
  154.         placeTorch()
  155.         turtle.turnRight()
  156.         turtle.turnRight()
  157.     end
  158.  
  159.     turtle.turnRight()
  160.     turtle.turnRight()
  161.     smart_dig_forward()
  162.     if currDistance % 6 == 0 then
  163.         turtle.turnRight()
  164.         turtle.turnRight()
  165.         placeTorch()
  166.         turtle.turnRight()
  167.         turtle.turnRight()
  168.     end
  169.  
  170.     turtle.turnLeft()
  171.     tryDown()
  172.  
  173.     if not turtle.detectDown() then
  174.         placeBlock()
  175.     end
  176.  
  177.     turtle.turnLeft()
  178.     tryForwards()
  179.  
  180.     if not turtle.detectDown() then
  181.         placeBlock()
  182.     end
  183.    
  184.  
  185.     turtle.turnRight()
  186.     turtle.turnRight()
  187.     tryForwards()
  188.     tryForwards()
  189.  
  190.     if not turtle.detectDown() then
  191.         placeBlock()
  192.     end
  193.  
  194.     turtle.turnLeft()
  195.     turtle.turnLeft()
  196.     tryForwards()
  197.  
  198.     turtle.turnRight()
  199.  
  200. end
  201.  
  202. turtle.select(1)
  203.  
  204. local curr_distance = 1
  205.  
  206. while(curr_distance <= distance)
  207. do
  208.     for i = curr_distance, distance, 1 do
  209.         clearSection(i)
  210.         if (turtle.getSelectedSlot() == 16) then
  211.             break
  212.         end
  213.     end
  214.  
  215.     turtle.turnRight()
  216.     turtle.turnRight()
  217.  
  218.     for i = 1, curr_distance, 1 do
  219.         tryForwards()
  220.     end
  221.  
  222.     for i = 3, 16, 1 do
  223.         turtle.select(i)
  224.         turtle.drop()
  225.     end
  226.  
  227.     if (curr_distance == distance) then
  228.         break
  229.     end
  230.  
  231.     for i = 1, curr_distance, 1 do
  232.         tryForwards()
  233.     end
  234. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×