-- This program digs a mining stairway with a flight of stairs five steps deep and two wide
-- 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 #14 to assure adequate fueling
-- Place stone into Turtle slot #15 and #16 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)
local function mv_fwd() -- This function moves the turtle forward one block
if turtle.detect() then turtle.dig(); turtle.forward() 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 sel_slot() -- This function selects the active slot for placing blocks
turtle.select(15)
if turtle.getItemCount() < 3 then turtle.select(16) 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 sel_slot(); turtle.place() end -- check forward and place
end
local function place_up()
if not turtle.detectUp() then sel_slot(); turtle.placeUp() end -- check up and place
end
local function place_dwn()
if not turtle.detectDown() then sel_slot(); turtle.placeDown() end -- check down and place
end
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
if turtle.getFuelLevel() < 200 then
print( "Your fuel level is less than 200; refueling with 240." )
turtle.select(14); turtle.refuel(3)
end
text_input = { ... } -- Obtain indicator of either H: Hallway cutting or S: Stairway cutting
print ( "Checking Data Entered." )
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
if not (( text_input[2] == "Y" ) or ( text_input[2] == "N" )) then
print( "Error: You must respond with either a Y to return the turtle to the start or an N for no." )
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
if iter1 == desired_length then fixHall() end
end
for iter2 = 1, ( desired_length - 1 ) do -- Cut a return hallway back to the start for the desired length
if iter2 == 1 then mv_fwd(); turtle.turnRight(); fixHall(); -- Cut the start of the return hallway
fixHall() end
if iter2 <= 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[1] = "Done"
end
while text_input[1] == "S" do
for iter1 = 0, ( desired_depth - 1 ) do
mv_fwd(); mv_dwn() -- Position turtle to start the cut
for iter2 = iter1, ( desired_length - 1 ) do
if iter2 == iter1 then place_dwn() end -- Check down and place if appropriate
turtle.turnRight(); place_fwd(); turtle.turnLeft() -- Cut block if required and position turtle
if (iter1 == ( desired_depth - 1 )) and (iter2 > (desired_length -3 )) then place_dwn() end
-- Place the last two blocks in the last iteration
if not ( iter2 == ( desired_length - 1 )) then mv_fwd() end -- Position turtle
end
place_fwd() -- Place at the end
-- if iter1 == ( desired_depth - 1 ) then mv_dwn(); place_fwd(); mv_up() end -- Place at the end
turtle.turnLeft(); mv_fwd(); turtle.turnRight(); place_fwd(); turtle.turnLeft(); turtle.turnLeft()
-- Position turtle and pace at the end
-- if iter1 == ( desired_depth - 1 ) then mv_dwn(); place_fwd(); mv_up() end -- Place at the end
-- turtle.turnLeft(); place_fwd(); turtle.turnLeft() -- place at end and position turtle
for iter3 = iter1, ( desired_length - 1 ) do
turtle.turnRight(); place_fwd(); turtle.turnLeft() -- Check right and place
if ( iter1 == ( desired_depth - 1 ) and ( iter3 < 7 )) then place_dwn() end
-- Place the last two blocks in the last iteration
if iter3 == (desired_length - 1 ) then place_dwn() end -- Check down and cut or place if appropriate
if not ( iter3 == ( desired_length - 1 )) then mv_fwd() -- Position turtle if not the last position
else turtle.turnLeft(); mv_fwd(); turtle.turnLeft() -- Position turtle if done
end
end
end
text_input[1] = "Done"
end
if text_input[2] == "Y" then
for iter = 1, 5 do turtle.up() end -- Move turtle to original position
turtle.turnLeft(); turtle.turnLeft()
for iter = 1, 5 do turtle.forward() end
turtle.turnLeft(); turtle.turnLeft()
end
print( "The program has ended successfully." )
Comments
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|👍
/👎
0 B
|0 👍
/0 👎
0 B
|👍
/👎