mdc_tjc

MDC_Tunnel_Liner

Feb 11th, 2026 (edited)
6,100
0
Never
5
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- This program creates a tunnel liner to facilitate mining via 5 x 5 tunnels
  2. -- Pastebin code = "yqYhZdbF"; Pastebin name is "MDC_Tunnel_Liner"
  3.  
  4. -- Place the turtle down on the right-forward end of the tunnel cut.
  5. -- Place coal into Turtle slot #14 to assure adequate fueling
  6. -- Place stone into Turtle slot #15 and #16 to assure adequate placement resources
  7. -- This program begins by asking you how many two-block sections you want to cut
  8.  
  9. local function mv_fwd() -- This function moves the turtle forward one block
  10.     if turtle.detect() then turtle.dig(); turtle.forward() else turtle.forward() end
  11.     end
  12.  
  13. local function mv_up() -- This function moves the turtle up one block
  14.     if turtle.detectUp() then turtle.digUp(); turtle.up() else turtle.up() end
  15.     end
  16.  
  17. local function mv_dwn() -- This function moves the turtle down one block
  18.     if turtle.detectDown() then turtle.digDown(); turtle.down() else turtle.down() end
  19.     end
  20.  
  21. local function sel_slot() -- This function selects the active slot for placing blocks
  22.     turtle.select(15)
  23.     if turtle.getItemCount() < 3 then turtle.select(16) end
  24.     end
  25.  
  26. local function place_fwd() -- This function places a block if none is present in front of the turtle
  27.     if not turtle.detect() then sel_slot(); turtle.place() end -- check forward and place
  28.     end
  29.  
  30. local function place_up()
  31.     if not turtle.detectUp() then sel_slot(); turtle.placeUp() end -- check up and place
  32.     end
  33.  
  34. local function place_dwn()
  35.     if not turtle.detectDown() then sel_slot(); turtle.placeDown() end -- check down and place
  36.     end
  37.  
  38. if turtle.getFuelLevel() < 200 then
  39.     print( "Your fuel level is less than 200; refueling with 240." )
  40.     turtle.select(14); turtle.refuel(3)
  41.     end
  42.  
  43. text_input = { ... } -- Obtain the number of two-block sections desired
  44.  
  45. print ( "Checking Data Entered." )
  46.  
  47. if ( tonumber( text_input[1] ) < 1 ) then
  48.     print( "Error: You must respond with a positive number." )
  49.     return
  50.     end
  51.  
  52. desired_sets = tonumber( text_input[1] )
  53. desired_height = 5
  54. desired_width = 5
  55.  
  56. while desired_sets > 0 do
  57.  
  58.     for iter1 = 1, desired_sets do -- Cut a hallway for the desired length while filling sides
  59.  
  60.         mv_fwd(); turtle.turnRight() -- Position turtle for initial cutting and placing
  61.  
  62.         for iter2 = 1, ( desired_height + 1 ) do -- Cut and place blocks up right side
  63.             place_fwd(); mv_up()
  64.         end
  65.  
  66.         turtle.turnLeft(); turtle.turnLeft(); -- Position turtle for cutting and placing on top of tunnel
  67.         mv_dwn(); mv_dwn()
  68.  
  69.         for iter3 = 1, ( desired_width + 1 ) do -- Cut and place blocks across the top
  70.             place_up(); mv_fwd()
  71.         end
  72.  
  73.         turtle.turnLeft(); turtle.turnLeft(); mv_fwd(); mv_fwd(); turtle.turnLeft(); turtle.turnLeft();
  74.  
  75.         for iter4 = 1, desired_height do -- Cut and place blocks down the left side
  76.             if not ( iter4 == desired_height ) then place_fwd(); mv_dwn() else place_fwd() end
  77.         end
  78.  
  79.         turtle.turnRight(); mv_fwd(); turtle.turnLeft()  -- Position turtle for cutting and placing up the left side
  80.  
  81.         for iter5 = 1, ( desired_height + 1 ) do -- Cut and place blocks up the 2nd left side
  82.             place_fwd(); mv_up()
  83.         end
  84.  
  85.         turtle.turnRight(); turtle.turnRight(); mv_dwn(); mv_dwn()
  86.  
  87.         for iter6 = 1, ( desired_width + 1 ) do -- Cut and place blocks back across the top
  88.             place_up(); mv_fwd()
  89.         end
  90.  
  91.         turtle.turnLeft(); turtle.turnLeft(); mv_fwd(); mv_fwd(); turtle.turnLeft(); turtle.turnLeft();
  92.  
  93.         for iter4 = 1, desired_height do -- Cut and place blocks down the right side
  94.             if not ( iter4 == desired_height ) then place_fwd(); mv_dwn() else place_fwd() end
  95.         end
  96.  
  97.  
  98.         turtle.turnLeft(); desired_sets = ( desired_sets - 1 )
  99.  
  100.     end
  101.  
  102. end
  103.  
  104. print( "The program has ended successfully." )
Tags: tunnel
Advertisement