Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program digs a mining stairs with a five levels down per filght of stairs
- -- Pastebin code = "X2qas41t"; Pastebin name is "MDC_Mining_Stairs"
- -- This program assumes that you place the turtle down on the forward end of the upper pad (a 2 stone x 2 stone)
- -- Place coal into Turtle slot #1 to assure adequate fueling
- -- This program begins by asking you to indicate whether you want to cut an upper Hallway (H response)
- -- or Stairs (S response)
- -- Definition of program functions follows:
- local function tryDig() -- This function digs forward one block
- while turtle.detect() do
- if turtle.dig() then
- sleep(0.2)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp() -- This function digs up one block
- while turtle.detectUp() do
- if turtle.digUp() then
- sleep(0.2)
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown() -- This function digs down one block
- while turtle.detectDown() do
- if turtle.digDown() then
- sleep(0.2)
- else
- return false
- end
- end
- return true
- end
- -- Main loop of program follows:
- if turtle.getFuelLevel() < 200 then
- print( "Your fuel level is less than 200; refueling with 240.")
- turtle.refuel(3)
- end
- print( "Enter either S or H for Stairs or Hallway mining." )
- print ( "Checking Entry." )
- local text_input = { ... } -- Obtain indicator of either H: Hallway cutting or S: Stairway cuttaing
- if not (( text_input[1] == "S" ) or ( text_input[1] == "H" )) then
- print( "Error: You must respond with either a H for Hallway cutting or a S for Stairway cutting." )
- return
- end
- local cut_type = text_input[1]
- local desired_length = 5 + 2
- local stairs_depth = 5
- while ( cut_type == "H" ) do
- turtle.up()
- tryDigUp()
- tryDigDown()
- for iter1 = 1, desired_length do -- This begins the Hallway cutting
- tryDig()
- turtle.forward()
- tryDigUp()
- tryDigDown()
- end
- turtle.turnLeft()
- tryDig()
- turtle.forward()
- tryDigUp()
- tryDigDown()
- turtle.turnLeft()
- for iter2 = 1, desired_length do -- This begins the Hallway return cutting
- tryDig()
- turtle.forward()
- tryDigUp()
- tryDigDown()
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.down()
- cut_type = "Done"
- end
- local cut_pass = 0
- if ( cut_type == "S" ) then turtle.forward() end
- while ( cut_type == "S" ) do
- for iter1 = 1, stairs_depth do -- This begins cutting the stairs
- for iter2 = 1, ( desired_length - cut_pass ) do -- This cuts the stairs away
- tryDigDown()
- if ( iter2 < desired_length ) then turtle.forward() end
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- for iter3 = 1, ( desired_length - cut_pass ) do -- This cuts the stairs back
- tryDigDown()
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- turtle.forward()
- turtle.down()
- cut_pass = cut_pass + 1
- end
- turtle.turnRight()
- cut_type = "Done"
- end
- print( "Successful end of the program." )
Advertisement