CCCPaste

MDC_Stairs_Cut3

-- This program digs a mining stairs with a five steps down per filght of stairs
-- Pastebin code = "31Vzy3bj"; Pastebin name is "MDC_Stairs_Cut3"

-- Place the turtle down on the right-forward end of the upper pad (a 2 stone x 2 stone)
-- Place coal into Turtle slot #1 to assure adequate fueling
-- Place stone into Turtle slot #2 to assure adequate placement resources
-- This program begins by asking you to indicate whether you want to cut an upper hall (H response) or stairs (S response)

if turtle.getFuelLevel() < 200 then
    print( "Your fuel level is less than 200; refueling with 240." )
    turtle.refuel(3)
    end

local function mv_fwd() -- This function moves the turtle forward one block
	if turtle.detect() then turtle.dig() else turtle.forward() end
	end

local function mv_up() -- This function moves the turtle up one block
	if turtle.detectUp() then turtle.digUp(); turtle.up() else turtle.up() end
	end

local function mv_dwn() -- This function moves the turtle down one block
	if turtle.detectDown() then turtle.digDown(); turtle.down() else turtle.down() end
	end

local function place_fwd() -- This function places a block if none is present in front of the turtle
	if not turtle.detect() then turtle.select(2); turtle.place() end -- check forward and place

local function place_up()
	if not turtle.detectUp() then turtle.select(2); turtle.placeUp() end -- check forward and place

local function fixHall() -- This function fixes one row of hallway
	place_fwd() -- Place block on right or left side for level one
	mv_up(); place_fwd() -- Move up and place block on right or left side for level two
	mv_up(); place_fwd() -- Move up and place block on right or left side for level three
	place_up() -- Place a block above level 3 if none is present
	turtle.down(); turtle.down(); turtle.turnLeft() -- Reset turtle to new starting position
	end

print ( "Checking Entry." )

text_input = { ... } -- Obtain indicator of either H: Hallway cutting or S: Stairway cutting

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

desired_length = 5 + 2
desired_depth = 5

while text_input[1] == "H" do

	for iter1 = 1, desired_length do -- Cut a hallway for the desired length while filling sides
		if iter1 <= desired_length then -- Move forward turn right in next row of hallway
			mv_fwd(); turtle.turnRight() end
		fixHall() -- Cut a column of hallway
		end

	for iter2 = 1, desired_length do -- Cut a return hallway back to the start for the desired length
		if iter2 = 1 then turtle.turnLeft(); mv_fwd(); fixHall() end -- Cut the start of the return hallway
		if iter1 <= desired_length then -- Move forward turn right in next row of the return hallway
			mv_fwd(); turtle.turnRight() end
		fixHall() -- Cut a column of hallway
		end
		mv_fwd(); turtle.turnLeft(); mv_fwd(); turtle.turnLeft(); -- Reposition turtle at original start
		
	text_input = "Done"

end

while text_input[1] == "S" do

	for iter1 = 0, ( desired_depth - 1 ) do

		if not turtle.detect() then turtle.forward() -- Position turtle
			else turtle.dig(); turtle.forward(); end

		for iter2 = iter1, ( desired_length - 1 ) do
			if not turtle.detectDown() then turtle.down(); turtle.turnRight() -- Position turtle
				else turtle.digDown(); turtle.down(); turtle.turnRight(); end
			if iter2 == iter1 then  -- Check down and cut or place if appropriate
				if not turtle.detectDown() then turtle.select(2); turtle.placeDown(); end
				else if turtle.detectDown() then turtle.digDown() end end
			if not turtle.detect() then turtle.select(2); turtle.place(); end -- Check right and place
			turtle.up(); turtle.turnLeft()

			if not ( iter2 == ( desired_length - 1 )) then
				if not turtle.detect() then turtle.forward() -- Position turtle
					else turtle.dig(); turtle.forward(); end
			end
		end

		turtle.turnLeft(); if not turtle.detect() then turtle.forward() else turtle.dig(); turtle.forward(); end
		turtle.turnLeft()

		for iter3 = iter1, ( desired_length - 1 ) do
			if not turtle.detectDown() then turtle.down(); turtle.turnRight()
				else turtle.digDown(); turtle.down(); turtle.turnRight(); end
			if not turtle.detect() then turtle.select(2); turtle.place(); end -- Check right and place
			if iter3 == ( desired_length - 1 ) then  -- Check down and cut or place if appropriate
				if not turtle.detectDown() then turtle.select(2); turtle.placeDown(); end
				else if turtle.detect() then turtle.digDown() end end
			turtle.up(); turtle.turnLeft()

			if not ( iter3 == ( desired_length - 1 )) then
				if not turtle.detect() then turtle.forward() -- Position turtle
					else turtle.dig(); turtle.forward(); end
				else turtle.turnLeft(); turtle.forward(); turtle.turnLeft(); turtle.down()
			end
		end
	end

	text_input = "Done"

end

print( "The program has ended successfully." )