View difference between Paste ID: yqYhZdbF and 31Vzy3bj
SHOW: | | - or go back to the newest paste.
1-
-- This program digs a mining stairway with a flight of stairs five steps deep and two wide
1+
-- This program creates a tunnel liner to facilitate mining via 5 x 5 tunnels
2-
-- Pastebin code = "31Vzy3bj"; Pastebin name is "MDC_Stairs_Cut3"
2+
-- Pastebin code = "yqYhZdbF"; Pastebin name is "MDC_Tunnel_Liner"
3
4-
-- Place the turtle down on the right-forward end of the upper pad (a 2 stone x 2 stone)
4+
-- Place the turtle down on the right-forward end of the tunnel cut.
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)
7+
-- This program begins by asking you how many two-block sections you want to cut
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
38+
39-
	place_fwd() -- Place block on right or left side for level one
39+
40-
	mv_up(); place_fwd() -- Move up and place block on right or left side for level two
40+
41-
	mv_up(); place_fwd() -- Move up and place block on right or left side for level three
41+
42-
	place_up() -- Place a block above level 3 if none is present
42+
43-
	turtle.down(); turtle.down(); turtle.turnLeft() -- Reset turtle to new starting position
43+
text_input = { ... } -- Obtain the number of two-block sections desired
44
45
print ( "Checking Data Entered." )
46
47
if ( tonumber( text_input[1] ) < 1 ) then
48
    print( "Error: You must respond with a positive number." )
49
	return
50
    end
51-
text_input = { ... } -- Obtain indicator of either H: Hallway cutting or S: Stairway cutting
51+
52
desired_sets = tonumber( text_input[1] )
53
desired_height = 5
54
desired_width = 5
55-
if not (( text_input[1] == "S" ) or ( text_input[1] == "H" )) then
55+
56-
    print( "Error: You must respond with either a H for Hallway cutting or a S for Stairway cutting." )
56+
while desired_sets > 0 do
57
58
	for iter1 = 1, desired_sets do -- Cut a hallway for the desired length while filling sides
59
60-
if not (( text_input[2] == "Y" ) or ( text_input[2] == "N" )) then
60+
		mv_fwd(); turtle.turnRight() -- Position turtle for initial cutting and placing
61-
    print( "Error: You must respond with either a Y to return the turtle to the start or an N for no." )
61+
62
		for iter2 = 1, ( desired_height + 1 ) do -- Cut and place blocks up right side
63
			place_fwd(); mv_up()
64
		end
65-
desired_length = 5 + 2
65+
66-
desired_depth = 5
66+
		turtle.turnLeft(); turtle.turnLeft(); -- Position turtle for cutting and placing on top of tunnel
67
		mv_dwn(); mv_dwn()
68-
while text_input[1] == "H" do
68+
69
		for iter3 = 1, ( desired_width + 1 ) do -- Cut and place blocks across the top
70-
	for iter1 = 1, desired_length do -- Cut a hallway for the desired length while filling sides
70+
			place_up(); mv_fwd()
71-
		if iter1 <= desired_length then -- Move forward turn right in next row of hallway
71+
72-
			mv_fwd(); turtle.turnRight() end
72+
73-
		fixHall() -- Cut a column of hallway
73+
		turtle.turnLeft(); turtle.turnLeft(); mv_fwd(); mv_fwd(); turtle.turnLeft(); turtle.turnLeft();
74-
		if iter1 == desired_length then fixHall() end
74+
75
		for iter4 = 1, desired_height do -- Cut and place blocks down the left side
76
			if not ( iter4 == desired_height ) then place_fwd(); mv_dwn() else place_fwd() end
77-
	for iter2 = 1, ( desired_length - 1 ) do -- Cut a return hallway back to the start for the desired length
77+
78-
		if iter2 == 1 then mv_fwd(); turtle.turnRight(); fixHall();  -- Cut the start of the return hallway
78+
79-
			fixHall() end
79+
		turtle.turnRight(); mv_fwd(); turtle.turnLeft()  -- Position turtle for cutting and placing up the left side
80-
		if iter2 <= desired_length then -- Move forward turn right in next row of the return hallway
80+
81-
			mv_fwd(); turtle.turnRight() end
81+
		for iter5 = 1, ( desired_height + 1 ) do -- Cut and place blocks up the 2nd left side
82-
		fixHall() -- Cut a column of hallway
82+
			place_fwd(); mv_up()
83
		end
84-
		mv_fwd(); turtle.turnLeft(); mv_fwd(); turtle.turnLeft(); -- Reposition turtle at original start
84+
85-
		
85+
		turtle.turnRight(); turtle.turnRight(); mv_dwn(); mv_dwn()
86-
	text_input[1] = "Done"
86+
87
		for iter6 = 1, ( desired_width + 1 ) do -- Cut and place blocks back across the top
88
			place_up(); mv_fwd()
89
		end
90-
while text_input[1] == "S" do
90+
91
		turtle.turnLeft(); turtle.turnLeft(); mv_fwd(); mv_fwd(); turtle.turnLeft(); turtle.turnLeft();
92-
	for iter1 = 0, ( desired_depth - 1 ) do
92+
93
		for iter4 = 1, desired_height do -- Cut and place blocks down the right side
94-
		mv_fwd(); mv_dwn() -- Position turtle to start the cut
94+
			if not ( iter4 == desired_height ) then place_fwd(); mv_dwn() else place_fwd() end
95
		end
96-
		for iter2 = iter1, ( desired_length - 1 ) do
96+
97-
			if iter2 == iter1 then place_dwn() end -- Check down and place if appropriate
97+
98-
			turtle.turnRight(); place_fwd(); turtle.turnLeft() -- Cut block if required and position turtle
98+
		turtle.turnLeft(); desired_sets = ( desired_sets - 1 )
99-
			if (iter1 == ( desired_depth - 1 )) and (iter2 > (desired_length -3 )) then place_dwn() end 
99+
100-
				-- Place the last two blocks in the last iteration
100+
101
102-
			if not ( iter2 == ( desired_length - 1 )) then mv_fwd() end -- Position turtle
102+
103
104
print( "The program has ended successfully." )