mdc_tjc

MDC_Stairs_Cut3

Feb 8th, 2026 (edited)
5,937
0
Never
9
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- This program digs a mining stairway with a flight of stairs five steps deep and two wide
  2. -- Pastebin code = "31Vzy3bj"; Pastebin name is "MDC_Stairs_Cut3"
  3.  
  4. -- Place the turtle down on the right-forward end of the upper pad (a 2 stone x 2 stone)
  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 to indicate whether you want to cut an upper hall (H response) or stairs (S response)
  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. local function fixHall() -- This function fixes one row of hallway
  39.     place_fwd() -- Place block on right or left side for level one
  40.     mv_up(); place_fwd() -- Move up and place block on right or left side for level two
  41.     mv_up(); place_fwd() -- Move up and place block on right or left side for level three
  42.     place_up() -- Place a block above level 3 if none is present
  43.     turtle.down(); turtle.down(); turtle.turnLeft() -- Reset turtle to new starting position
  44.     end
  45.  
  46. if turtle.getFuelLevel() < 200 then
  47.     print( "Your fuel level is less than 200; refueling with 240." )
  48.     turtle.select(14); turtle.refuel(3)
  49.     end
  50.  
  51. text_input = { ... } -- Obtain indicator of either H: Hallway cutting or S: Stairway cutting
  52.  
  53. print ( "Checking Data Entered." )
  54.  
  55. if not (( text_input[1] == "S" ) or ( text_input[1] == "H" )) then
  56.     print( "Error: You must respond with either a H for Hallway cutting or a S for Stairway cutting." )
  57.     return
  58.     end
  59.  
  60. if not (( text_input[2] == "Y" ) or ( text_input[2] == "N" )) then
  61.     print( "Error: You must respond with either a Y to return the turtle to the start or an N for no." )
  62.     return
  63.     end
  64.  
  65. desired_length = 5 + 2
  66. desired_depth = 5
  67.  
  68. while text_input[1] == "H" do
  69.  
  70.     for iter1 = 1, desired_length do -- Cut a hallway for the desired length while filling sides
  71.         if iter1 <= desired_length then -- Move forward turn right in next row of hallway
  72.             mv_fwd(); turtle.turnRight() end
  73.         fixHall() -- Cut a column of hallway
  74.         if iter1 == desired_length then fixHall() end
  75.         end
  76.  
  77.     for iter2 = 1, ( desired_length - 1 ) do -- Cut a return hallway back to the start for the desired length
  78.         if iter2 == 1 then mv_fwd(); turtle.turnRight(); fixHall();  -- Cut the start of the return hallway
  79.             fixHall() end
  80.         if iter2 <= desired_length then -- Move forward turn right in next row of the return hallway
  81.             mv_fwd(); turtle.turnRight() end
  82.         fixHall() -- Cut a column of hallway
  83.         end
  84.         mv_fwd(); turtle.turnLeft(); mv_fwd(); turtle.turnLeft(); -- Reposition turtle at original start
  85.        
  86.     text_input[1] = "Done"
  87.  
  88. end
  89.  
  90. while text_input[1] == "S" do
  91.  
  92.     for iter1 = 0, ( desired_depth - 1 ) do
  93.  
  94.         mv_fwd(); mv_dwn() -- Position turtle to start the cut
  95.  
  96.         for iter2 = iter1, ( desired_length - 1 ) do
  97.             if iter2 == iter1 then place_dwn() end -- Check down and place if appropriate
  98.             turtle.turnRight(); place_fwd(); turtle.turnLeft() -- Cut block if required and position turtle
  99.             if (iter1 == ( desired_depth - 1 )) and (iter2 > (desired_length -3 )) then place_dwn() end
  100.                 -- Place the last two blocks in the last iteration
  101.  
  102.             if not ( iter2 == ( desired_length - 1 )) then mv_fwd() end -- Position turtle
  103.         end
  104.  
  105.         place_fwd() -- Place at the end
  106. --      if iter1 == ( desired_depth - 1 ) then mv_dwn(); place_fwd(); mv_up() end -- Place at the end
  107.         turtle.turnLeft(); mv_fwd(); turtle.turnRight(); place_fwd(); turtle.turnLeft(); turtle.turnLeft()
  108.             -- Position turtle and pace at the end
  109. --      if iter1 == ( desired_depth - 1 ) then mv_dwn(); place_fwd(); mv_up() end -- Place at the end
  110. --      turtle.turnLeft(); place_fwd(); turtle.turnLeft() -- place at end and position turtle
  111.  
  112.         for iter3 = iter1, ( desired_length - 1 ) do
  113.             turtle.turnRight(); place_fwd(); turtle.turnLeft()  -- Check right and place
  114.             if ( iter1 == ( desired_depth - 1 ) and ( iter3 < 7 )) then place_dwn() end
  115.                 -- Place the last two blocks in the last iteration
  116.             if iter3 == (desired_length - 1 ) then place_dwn() end -- Check down and cut or place if appropriate
  117.  
  118.             if not ( iter3 == ( desired_length - 1 )) then mv_fwd() -- Position turtle if not the last position
  119.                 else turtle.turnLeft(); mv_fwd(); turtle.turnLeft() -- Position turtle if done
  120.             end
  121.         end
  122.     end
  123.  
  124.     text_input[1] = "Done"
  125.  
  126. end
  127.  
  128. if text_input[2] == "Y" then
  129.  
  130.     for iter = 1, 5 do turtle.up() end -- Move turtle to original position
  131.     turtle.turnLeft(); turtle.turnLeft()
  132.     for iter = 1, 5 do turtle.forward() end
  133.     turtle.turnLeft(); turtle.turnLeft()
  134.  
  135.     end
  136.  
  137. print( "The program has ended successfully." )
Advertisement