mdc_tjc

MDC_Stairs_Cut2

Jan 30th, 2026 (edited)
3,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.37 KB | None | 0 0
  1. -- This program digs a mining stairs with a five levels down per filght of stairs
  2. -- Pastebin code = "TaFFELNp"; Pastebin name is "MDC_Stairs_Cut2"
  3.  
  4. -- This program assumes that you place the turtle down on the forward end of the upper pad (a 2 stone x 2 stone)
  5. -- Place coal into Turtle slot #1 to assure adequate fueling
  6. -- Place stone into Turtle slot #2 and #3 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. if turtle.getFuelLevel() < 200 then
  10.     print( "Your fuel level is less than 200; refueling with 240." )
  11.     turtle.refuel(3)
  12.     end
  13.  
  14. local function fixHall() -- This function fixes one row of hallway
  15.     if not turtle.detect() then turtle.select(2); turtle.place() end -- Check right and place
  16.  
  17.     if not turtle.detectUp() -- Move up
  18.         then turtle.up()
  19.         else turtle.digUp(); turtle.up() end
  20.     if not turtle.detect() then turtle.select(2); turtle.place() end -- Check right and place
  21.  
  22.     if not turtle.detectUp() -- Move up
  23.         then turtle.up()
  24.         else turtle.digUp(); turtle.up() end
  25.     if not turtle.detect() then turtle.select(2); turtle.place() end -- Check right and place
  26.     if not turtle.detectUp() then turtle.select(2); turtle.placeUp() end -- Check up and place
  27.     turtle.turnLeft(); turtle.down(); turtle.down()
  28.     if not turtle.detect()
  29.         then turtle.forward(); turtle.turnRight()
  30.         else turtle.dig(); turtle.forward(); turtle.turnRight() end
  31.     end
  32.  
  33. print ( "Checking Entry." )
  34.  
  35. local text_input = { ... } -- Obtain indicator of either H: Hallway cutting or S: Stairway cutting
  36. print( "1 text_input = ", text_input )
  37. if not (( text_input[1] == "S" ) or ( text_input[1] == "H" )) then
  38.     print( "Error: You must respond with either a H for Hallway cutting or a S for Stairway cutting." )
  39.     return
  40.     end
  41.  
  42. local desired_length = 5 + 2
  43. local desired_depth = 5
  44.  
  45. while text_input == "H" do
  46.     if not turtle.detect() -- Move forward and turn right
  47.         then turtle.forward(); turtle.turnRight()
  48.         else turtle.dig(); turtle.forward(); turtle.turnRight() end
  49.  
  50.     for iter1 = 1, desired_length do
  51.         fixHall() -- Fix hallway for desired length
  52.         end
  53.  
  54.     turtle.turnLeft(); turtle.turnLeft()
  55.  
  56.     if not turtle.detect() -- Reposition turtle for second cut
  57.             then turtle.forward(); turtle.turnLeft()
  58.             else turtle.dig(); turtle.forward(); turtle.turnLeft() end
  59.     if not turtle.detect()
  60.             then turtle.forward(); turtle.turnRight()
  61.             else turtle.dig(); turtle.forward(); turtle.turnright() end
  62.  
  63.     for iter1 = 1, desired_length do
  64.         fixHall() -- Fix hallway for desired length
  65.         end
  66.  
  67.     turtle.turnLeft(); turtle.turnLeft(); turtle.forward(); turtle.turnLeft()
  68.     text_input = "Done"
  69.  
  70. end
  71.  
  72. print( "2 text_input = ", text_input )
  73. while text_input == "S" do
  74.  
  75.     print( "3 text_input = ", text_input )
  76.     for iter1 = 1, 1 do
  77.  
  78.         print( "Outer Loop")
  79.         if not turtle.detect() then turtle.forward() -- Position turtle
  80.             else turtle.dig(); turtle.forward(); end       
  81.  
  82.         for iter2 = 0, ( desired_length - 1 ) do
  83.             if not turtle.detectDown() then turtle.down(); turtle.turnRight()
  84.                 else turtle.digDown(); turtle.down(); turtle.turnRight(); end
  85.             if not turtle.detect() then turtle.select(2); turtle.place(); end -- Check right and place
  86.             turtle.up(); turtle.turnLeft()
  87.        
  88.         end
  89.  
  90.     end
  91.  
  92.     text_input = "Done"
  93.  
  94. end
  95.  
  96. print( "The program has ended successfully." )
Advertisement