Advertisement
Necrotico

Computercraft Simple Tunnel

Aug 30th, 2021 (edited)
1,260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | None | 0 0
  1. -- Simple Tunnel
  2. -- pastebin get ZBceps6U simpleTunnel
  3. -- simpleTunnel 75
  4.  
  5. -- DESCRIPTION
  6. --  Like the default tunnel program, but instead of mining a 3x2 tunnel, this program will mine a 1x2 tunnel.
  7.  
  8.  
  9. local argv = {...}
  10. local mine_dist = tonumber(argv[1])
  11.  
  12. local CONST_TORCH_INTERVAL = 8
  13.  
  14. local curr_dist = 0
  15.  
  16. local function check_fuel()
  17.     if turtle.getFuelLevel() < 80 then
  18.         turtle.select(1)
  19.         turtle.refuel(1)
  20.     end
  21. end
  22.  
  23. local function select_cobble()
  24.     for s=2, 16 do
  25.         local item_data = turtle.getItemDetail(s)
  26.         if item_data then
  27.             if item_data.name == "minecraft:cobblestone" then
  28.                 turtle.select(s)
  29.                 return true
  30.             end
  31.         end
  32.     end
  33.     return false
  34. end
  35.  
  36. local function select_torch()
  37.     for s=2, 16 do
  38.         local item_data = turtle.getItemDetail(s)
  39.         if item_data then
  40.             if item_data.name == "minecraft:torch" then
  41.                 turtle.select(s)
  42.                 return true
  43.             end
  44.         end
  45.     end
  46.     return false
  47. end
  48.  
  49. local function tick()
  50.     check_fuel()
  51.     while not turtle.forward() do
  52.         turtle.dig()
  53.     end
  54.     if turtle.detectUp() then
  55.         turtle.digUp()
  56.     end
  57.     if (not turtle.detectDown()) and select_cobble() then
  58.         turtle.placeDown()
  59.     end
  60.     if (curr_dist > 0 and curr_dist % CONST_TORCH_INTERVAL == 0) and select_torch() then
  61.         if (not turtle.placeUp()) and select_cobble() then
  62.             turtle.up()
  63.             turtle.turnLeft()
  64.             turtle.place()
  65.             turtle.turnRight()
  66.             turtle.down()
  67.             select_torch()
  68.             turtle.placeUp()
  69.         end
  70.     end
  71.     curr_dist = curr_dist + 1
  72. end
  73.  
  74. print("Beginning tunnel of length " .. tostring(mine_dist))
  75. while curr_dist < mine_dist do
  76.     tick()
  77. end
  78. print("Success!")
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement