SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- This program digs a mining stairs with a five levels down per filght of stairs |
| 1 | + | -- This program digs a mining stairway with a flight of stairs five steps deep and two wide |
| 2 | - | -- Pastebin code = "TaFFELNp"; Pastebin name is "MDC_Stairs_Cut2" |
| 2 | + | -- Pastebin code = "31Vzy3bj"; Pastebin name is "MDC_Stairs_Cut3" |
| 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) |
| 4 | + | -- Place the turtle down on the right-forward end of the upper pad (a 2 stone x 2 stone) |
| 5 | - | -- Place coal into Turtle slot #1 to assure adequate fueling |
| 5 | + | -- Place coal into Turtle slot #14 to assure adequate fueling |
| 6 | - | -- Place stone into Turtle slot #2 and #3 to assure adequate placement resources |
| 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) | |
| 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 | - | turtle.refuel(3) |
| 11 | + | |
| 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 | - | if not turtle.detect() then turtle.select(2); turtle.place() end -- Check right and place |
| 15 | + | |
| 16 | ||
| 17 | - | if not turtle.detectUp() -- Move up |
| 17 | + | local function mv_dwn() -- This function moves the turtle down one block |
| 18 | - | then turtle.up() |
| 18 | + | if turtle.detectDown() then turtle.digDown(); turtle.down() else turtle.down() end |
| 19 | - | else turtle.digUp(); turtle.up() end |
| 19 | + | |
| 20 | - | if not turtle.detect() then turtle.select(2); turtle.place() end -- Check right and place |
| 20 | + | |
| 21 | local function sel_slot() -- This function selects the active slot for placing blocks | |
| 22 | - | if not turtle.detectUp() -- Move up |
| 22 | + | turtle.select(15) |
| 23 | - | then turtle.up() |
| 23 | + | if turtle.getItemCount() < 3 then turtle.select(16) end |
| 24 | - | else turtle.digUp(); turtle.up() end |
| 24 | + | |
| 25 | - | if not turtle.detect() then turtle.select(2); turtle.place() end -- Check right and place |
| 25 | + | |
| 26 | - | if not turtle.detectUp() then turtle.select(2); turtle.placeUp() end -- Check up and place |
| 26 | + | local function place_fwd() -- This function places a block if none is present in front of the turtle |
| 27 | - | turtle.turnLeft(); turtle.down(); turtle.down() |
| 27 | + | if not turtle.detect() then sel_slot(); turtle.place() end -- check forward and place |
| 28 | - | if not turtle.detect() |
| 28 | + | |
| 29 | - | then turtle.forward(); turtle.turnRight() |
| 29 | + | |
| 30 | - | else turtle.dig(); turtle.forward(); turtle.turnRight() end |
| 30 | + | local function place_up() |
| 31 | if not turtle.detectUp() then sel_slot(); turtle.placeUp() end -- check up and place | |
| 32 | end | |
| 33 | - | print ( "Checking Entry." ) |
| 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 | |
| 39 | place_fwd() -- Place block on right or left side for level one | |
| 40 | mv_up(); place_fwd() -- Move up and place block on right or left side for level two | |
| 41 | mv_up(); place_fwd() -- Move up and place block on right or left side for level three | |
| 42 | place_up() -- Place a block above level 3 if none is present | |
| 43 | turtle.down(); turtle.down(); turtle.turnLeft() -- Reset turtle to new starting position | |
| 44 | end | |
| 45 | ||
| 46 | - | if not turtle.detect() -- Move forward and turn right |
| 46 | + | |
| 47 | - | then turtle.forward(); turtle.turnRight() |
| 47 | + | |
| 48 | - | else turtle.dig(); turtle.forward(); turtle.turnRight() end |
| 48 | + | turtle.select(14); turtle.refuel(3) |
| 49 | end | |
| 50 | - | for iter1 = 1, desired_length do |
| 50 | + | |
| 51 | - | fixHall() -- Fix hallway for desired length |
| 51 | + | |
| 52 | ||
| 53 | print ( "Checking Data Entered." ) | |
| 54 | ||
| 55 | if not (( text_input[1] == "S" ) or ( text_input[1] == "H" )) then | |
| 56 | - | if not turtle.detect() -- Reposition turtle for second cut |
| 56 | + | |
| 57 | - | then turtle.forward(); turtle.turnLeft() |
| 57 | + | |
| 58 | - | else turtle.dig(); turtle.forward(); turtle.turnLeft() end |
| 58 | + | |
| 59 | - | if not turtle.detect() |
| 59 | + | |
| 60 | - | then turtle.forward(); turtle.turnRight() |
| 60 | + | if not (( text_input[2] == "Y" ) or ( text_input[2] == "N" )) then |
| 61 | - | else turtle.dig(); turtle.forward(); turtle.turnright() end |
| 61 | + | print( "Error: You must respond with either a Y to return the turtle to the start or an N for no." ) |
| 62 | return | |
| 63 | - | for iter1 = 1, desired_length do |
| 63 | + | |
| 64 | - | fixHall() -- Fix hallway for desired length |
| 64 | + | |
| 65 | desired_length = 5 + 2 | |
| 66 | desired_depth = 5 | |
| 67 | - | turtle.turnLeft(); turtle.turnLeft(); turtle.forward(); turtle.turnLeft() |
| 67 | + | |
| 68 | - | text_input = "Done" |
| 68 | + | |
| 69 | ||
| 70 | for iter1 = 1, desired_length do -- Cut a hallway for the desired length while filling sides | |
| 71 | if iter1 <= desired_length then -- Move forward turn right in next row of hallway | |
| 72 | mv_fwd(); turtle.turnRight() end | |
| 73 | fixHall() -- Cut a column of hallway | |
| 74 | if iter1 == desired_length then fixHall() end | |
| 75 | end | |
| 76 | - | if not turtle.detect() then turtle.forward() -- Position turtle |
| 76 | + | |
| 77 | - | else turtle.dig(); turtle.forward(); end |
| 77 | + | for iter2 = 1, ( desired_length - 1 ) do -- Cut a return hallway back to the start for the desired length |
| 78 | if iter2 == 1 then mv_fwd(); turtle.turnRight(); fixHall(); -- Cut the start of the return hallway | |
| 79 | fixHall() end | |
| 80 | - | if not turtle.detectDown() then turtle.down(); turtle.turnRight() -- Position turtle |
| 80 | + | if iter2 <= desired_length then -- Move forward turn right in next row of the return hallway |
| 81 | - | else turtle.digDown(); turtle.down(); turtle.turnRight(); end |
| 81 | + | mv_fwd(); turtle.turnRight() end |
| 82 | - | if iter2 == iter1 then -- Check down and cut or place if appropriate |
| 82 | + | fixHall() -- Cut a column of hallway |
| 83 | - | if not turtle.detectDown() then turtle.select(2); turtle.placeDown(); end |
| 83 | + | |
| 84 | - | else if turtle.detectDown() then turtle.digDown() end end |
| 84 | + | mv_fwd(); turtle.turnLeft(); mv_fwd(); turtle.turnLeft(); -- Reposition turtle at original start |
| 85 | - | if not turtle.detect() then turtle.select(2); turtle.place(); end -- Check right and place |
| 85 | + | |
| 86 | - | turtle.up(); turtle.turnLeft() |
| 86 | + | text_input[1] = "Done" |
| 87 | ||
| 88 | - | if not ( iter2 == ( desired_length - 1 )) then |
| 88 | + | |
| 89 | - | if not turtle.detect() then turtle.forward() -- Position turtle |
| 89 | + | |
| 90 | - | else turtle.dig(); turtle.forward(); end |
| 90 | + | |
| 91 | ||
| 92 | for iter1 = 0, ( desired_depth - 1 ) do | |
| 93 | ||
| 94 | - | turtle.turnLeft(); if not turtle.detect() then turtle.forward() else turtle.dig(); turtle.forward(); end |
| 94 | + | mv_fwd(); mv_dwn() -- Position turtle to start the cut |
| 95 | - | turtle.turnLeft() |
| 95 | + | |
| 96 | for iter2 = iter1, ( desired_length - 1 ) do | |
| 97 | if iter2 == iter1 then place_dwn() end -- Check down and place if appropriate | |
| 98 | - | if not turtle.detectDown() then turtle.down(); turtle.turnRight() |
| 98 | + | turtle.turnRight(); place_fwd(); turtle.turnLeft() -- Cut block if required and position turtle |
| 99 | - | else turtle.digDown(); turtle.down(); turtle.turnRight(); end |
| 99 | + | if (iter1 == ( desired_depth - 1 )) and (iter2 > (desired_length -3 )) then place_dwn() end |
| 100 | - | if not turtle.detect() then turtle.select(2); turtle.place(); end -- Check right and place |
| 100 | + | -- Place the last two blocks in the last iteration |
| 101 | - | if iter3 == ( desired_length - 1 ) then -- Check down and cut or place if appropriate |
| 101 | + | |
| 102 | - | if not turtle.detectDown() then turtle.select(2); turtle.placeDown(); end |
| 102 | + | if not ( iter2 == ( desired_length - 1 )) then mv_fwd() end -- Position turtle |
| 103 | - | else if turtle.detect() then turtle.digDown() end end |
| 103 | + | |
| 104 | - | turtle.up(); turtle.turnLeft() |
| 104 | + | |
| 105 | place_fwd() -- Place at the end | |
| 106 | - | if not ( iter3 == ( desired_length - 1 )) then |
| 106 | + | -- if iter1 == ( desired_depth - 1 ) then mv_dwn(); place_fwd(); mv_up() end -- Place at the end |
| 107 | - | if not turtle.detect() then turtle.forward() -- Position turtle |
| 107 | + | turtle.turnLeft(); mv_fwd(); turtle.turnRight(); place_fwd(); turtle.turnLeft(); turtle.turnLeft() |
| 108 | - | else turtle.dig(); turtle.forward(); end |
| 108 | + | -- Position turtle and pace at the end |
| 109 | - | else turtle.turnLeft(); turtle.forward(); turtle.turnLeft(); turtle.down() |
| 109 | + | -- if iter1 == ( desired_depth - 1 ) then mv_dwn(); place_fwd(); mv_up() end -- Place at the end |
| 110 | -- turtle.turnLeft(); place_fwd(); turtle.turnLeft() -- place at end and position turtle | |
| 111 | ||
| 112 | for iter3 = iter1, ( desired_length - 1 ) do | |
| 113 | turtle.turnRight(); place_fwd(); turtle.turnLeft() -- Check right and place | |
| 114 | - | text_input = "Done" |
| 114 | + | if ( iter1 == ( desired_depth - 1 ) and ( iter3 < 7 )) then place_dwn() end |
| 115 | -- Place the last two blocks in the last iteration | |
| 116 | if iter3 == (desired_length - 1 ) then place_dwn() end -- Check down and cut or place if appropriate | |
| 117 | ||
| 118 | if not ( iter3 == ( desired_length - 1 )) then mv_fwd() -- Position turtle if not the last position | |
| 119 | else turtle.turnLeft(); mv_fwd(); turtle.turnLeft() -- Position turtle if done | |
| 120 | end | |
| 121 | end | |
| 122 | end | |
| 123 | ||
| 124 | text_input[1] = "Done" | |
| 125 | ||
| 126 | end | |
| 127 | ||
| 128 | if text_input[2] == "Y" then | |
| 129 | ||
| 130 | for iter = 1, 5 do turtle.up() end -- Move turtle to original position | |
| 131 | turtle.turnLeft(); turtle.turnLeft() | |
| 132 | for iter = 1, 5 do turtle.forward() end | |
| 133 | turtle.turnLeft(); turtle.turnLeft() | |
| 134 | ||
| 135 | end | |
| 136 | ||
| 137 | print( "The program has ended successfully." ) |