mdc_tjc

MDC_Mining_Stairs

Jan 24th, 2026 (edited)
3,309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.17 KB | None | 0 0
  1. -- This program digs a mining stairs with a five levels down per filght of stairs
  2. -- Pastebin code = "X2qas41t"; Pastebin name is "MDC_Mining_Stairs"
  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. -- This program begins by asking you to indicate whether you want to cut an upper Hallway (H response)
  7. --   or Stairs (S response)
  8.  
  9. -- Definition of program functions follows:
  10.  
  11. local function tryDig() -- This function digs forward one block
  12.     while turtle.detect() do
  13.         if turtle.dig() then
  14.             sleep(0.2)
  15.         else
  16.             return false
  17.         end
  18.     end
  19.     return true
  20.     end
  21.  
  22. local function tryDigUp() -- This function digs up one block
  23.     while turtle.detectUp() do
  24.         if turtle.digUp() then
  25.             sleep(0.2)
  26.         else
  27.             return false
  28.         end
  29.     end
  30.     return true
  31. end
  32.  
  33. local function tryDigDown() -- This function digs down one block
  34.     while turtle.detectDown() do
  35.         if turtle.digDown() then
  36.             sleep(0.2)
  37.         else
  38.             return false
  39.         end
  40.     end
  41.     return true
  42. end
  43.  
  44. -- Main loop of program follows:
  45.  
  46. if turtle.getFuelLevel() < 200 then
  47.     print( "Your fuel level is less than 200; refueling with 240.")
  48.     turtle.refuel(3)
  49.     end
  50.  
  51. print( "Enter either S or H for Stairs or Hallway mining." )
  52. print ( "Checking Entry." )
  53.  
  54. local text_input = { ... } -- Obtain indicator of either H: Hallway cutting or S: Stairway cuttaing
  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. local cut_type = text_input[1]
  61.  
  62. local desired_length = 5 + 2
  63. local stairs_depth = 5
  64.  
  65. while ( cut_type == "H" ) do
  66.  
  67.     turtle.up()
  68.     tryDigUp()
  69.     tryDigDown()
  70.  
  71.     for iter1 = 1, desired_length do -- This begins the Hallway cutting
  72.         tryDig()
  73.         turtle.forward()
  74.         tryDigUp()
  75.         tryDigDown()
  76.     end
  77.  
  78.     turtle.turnLeft()
  79.     tryDig()
  80.     turtle.forward()
  81.     tryDigUp()
  82.     tryDigDown()
  83.     turtle.turnLeft()
  84.  
  85.     for iter2 = 1, desired_length do -- This begins the Hallway return cutting
  86.         tryDig()
  87.         turtle.forward()
  88.         tryDigUp()
  89.         tryDigDown()
  90.     end
  91.  
  92.     turtle.turnLeft()
  93.     turtle.forward()
  94.     turtle.turnLeft()
  95.     turtle.down()
  96.     cut_type = "Done"
  97.  
  98. end
  99.  
  100. local cut_pass = 0
  101.  
  102. if ( cut_type == "S" ) then turtle.forward() end
  103. while ( cut_type == "S" ) do
  104.  
  105.     for iter1 = 1, stairs_depth do -- This begins cutting the stairs
  106.  
  107.         for iter2 = 1, ( desired_length - cut_pass ) do -- This cuts the stairs away
  108.             tryDigDown()
  109.             if ( iter2 < desired_length ) then turtle.forward() end
  110.         end
  111.  
  112.         turtle.turnLeft()
  113.         turtle.forward()
  114.         turtle.turnLeft()
  115.  
  116.         for iter3 = 1, ( desired_length - cut_pass ) do -- This cuts the stairs back
  117.             tryDigDown()
  118.             turtle.forward()
  119.         end
  120.  
  121.         turtle.turnLeft()
  122.         turtle.forward()
  123.         turtle.turnLeft()
  124.         turtle.forward()
  125.         turtle.forward()
  126.         turtle.down()
  127.  
  128.         cut_pass = cut_pass + 1
  129.  
  130.     end
  131.  
  132.     turtle.turnRight()
  133.     cut_type = "Done"
  134.  
  135. end
  136.  
  137. print( "Successful end of the program." )
  138.  
  139.  
  140.  
  141.  
  142.  
Tags: mining
Advertisement