SHOW:
|
|
- or go back to the newest paste.
| 1 | --local tArgs = { ... }
| |
| 2 | --if #tArgs ~= 1 then | |
| 3 | -- print( "Usage: tunnel <length>" ) | |
| 4 | -- return | |
| 5 | --end | |
| 6 | ||
| 7 | ||
| 8 | -- Mine in a quarry pattern until we hit something we can't dig | |
| 9 | --local length = tonumber( tArgs[1] ) | |
| 10 | local length = tonumber(6) | |
| 11 | if length < 1 then | |
| 12 | print( "Tunnel length must be positive" ) | |
| 13 | return | |
| 14 | end | |
| 15 | ||
| 16 | local depth = length | |
| 17 | local collected = 0 | |
| 18 | ||
| 19 | local function collect() | |
| 20 | collected = collected + 1 | |
| 21 | if math.fmod(collected, 25) == 0 then | |
| 22 | print( "Mined "..collected.." items." ) | |
| 23 | end | |
| 24 | end | |
| 25 | ||
| 26 | local function tryDig() | |
| 27 | while turtle.detect() do | |
| 28 | if turtle.dig() then | |
| 29 | collect() | |
| 30 | sleep(0.5) | |
| 31 | else | |
| 32 | return false | |
| 33 | end | |
| 34 | end | |
| 35 | return true | |
| 36 | end | |
| 37 | ||
| 38 | local function tryDigUp() | |
| 39 | while turtle.detectUp() do | |
| 40 | if turtle.digUp() then | |
| 41 | collect() | |
| 42 | sleep(0.5) | |
| 43 | else | |
| 44 | return false | |
| 45 | end | |
| 46 | end | |
| 47 | return true | |
| 48 | end | |
| 49 | ||
| 50 | local function tryDigDown() | |
| 51 | while turtle.detectDown() do | |
| 52 | if turtle.digDown() then | |
| 53 | collect() | |
| 54 | sleep(0.5) | |
| 55 | else | |
| 56 | return false | |
| 57 | end | |
| 58 | end | |
| 59 | return true | |
| 60 | end | |
| 61 | local function refuel() | |
| 62 | local fuelLevel = turtle.getFuelLevel() | |
| 63 | if fuelLevel == "unlimited" or fuelLevel > 0 then | |
| 64 | return | |
| 65 | end | |
| 66 | ||
| 67 | local function tryRefuel() | |
| 68 | for n=1,16 do | |
| 69 | if turtle.getItemCount(n) > 0 then | |
| 70 | turtle.select(n) | |
| 71 | if turtle.refuel(1) then | |
| 72 | turtle.select(1) | |
| 73 | return true | |
| 74 | end | |
| 75 | end | |
| 76 | end | |
| 77 | turtle.select(1) | |
| 78 | return false | |
| 79 | end | |
| 80 | ||
| 81 | if not tryRefuel() then | |
| 82 | print( "Add more fuel to continue." ) | |
| 83 | while not tryRefuel() do | |
| 84 | sleep(1) | |
| 85 | end | |
| 86 | print( "Resuming Tunnel." ) | |
| 87 | end | |
| 88 | end | |
| 89 | ||
| 90 | local function tryUp() | |
| 91 | refuel() | |
| 92 | while not turtle.up() do | |
| 93 | if turtle.detectUp() then | |
| 94 | if not tryDigUp() then | |
| 95 | return false | |
| 96 | end | |
| 97 | elseif turtle.attackUp() then | |
| 98 | collect() | |
| 99 | else | |
| 100 | sleep( 0.5 ) | |
| 101 | end | |
| 102 | end | |
| 103 | return true | |
| 104 | end | |
| 105 | ||
| 106 | local function tryDown() | |
| 107 | refuel() | |
| 108 | while not turtle.down() do | |
| 109 | if turtle.detectDown() then | |
| 110 | if not tryDigDown() then | |
| 111 | return false | |
| 112 | end | |
| 113 | elseif turtle.attackDown() then | |
| 114 | collect() | |
| 115 | else | |
| 116 | sleep( 0.5 ) | |
| 117 | end | |
| 118 | end | |
| 119 | return true | |
| 120 | end | |
| 121 | ||
| 122 | local function tryForward() | |
| 123 | refuel() | |
| 124 | while not turtle.forward() do | |
| 125 | if turtle.detect() then | |
| 126 | if not tryDig() then | |
| 127 | return false | |
| 128 | end | |
| 129 | elseif turtle.attack() then | |
| 130 | collect() | |
| 131 | else | |
| 132 | sleep( 0.5 ) | |
| 133 | end | |
| 134 | end | |
| 135 | return true | |
| 136 | end | |
| 137 | ||
| 138 | print( "Tunnelling..." ) | |
| 139 | ||
| 140 | for n=1,length do | |
| 141 | turtle.placeDown() | |
| 142 | tryDigUp() | |
| 143 | turtle.turnLeft() | |
| 144 | tryDig() | |
| 145 | tryUp() | |
| 146 | tryDig() | |
| 147 | tryUp() | |
| 148 | tryDig() | |
| 149 | tryUp() | |
| 150 | tryDig() | |
| 151 | tryUp() | |
| 152 | tryDig() | |
| 153 | turtle.turnRight() | |
| 154 | turtle.turnRight() | |
| 155 | tryDig() | |
| 156 | tryForward() | |
| 157 | tryDig() | |
| 158 | tryDigDown() | |
| 159 | tryDown() | |
| 160 | tryDig() | |
| 161 | tryDigDown() | |
| 162 | tryDown() | |
| 163 | tryDig() | |
| 164 | tryDigDown() | |
| 165 | tryDown() | |
| 166 | tryDig() | |
| 167 | tryDigDown() | |
| 168 | tryDown() | |
| 169 | tryDig() | |
| 170 | turtle.turnRight() | |
| 171 | turtle.turnRight() | |
| 172 | tryForward() | |
| 173 | turtle.turnRight() | |
| 174 | ||
| 175 | if n<length then | |
| 176 | tryDig() | |
| 177 | if not tryForward() then | |
| 178 | print( "Aborting Tunnel." ) | |
| 179 | break | |
| 180 | end | |
| 181 | else | |
| 182 | print( "Tunnel complete." ) | |
| 183 | end | |
| 184 | ||
| 185 | end | |
| 186 | ||
| 187 | ||
| 188 | print( "Returning to start..." ) | |
| 189 | ||
| 190 | -- Return to where we started | |
| 191 | turtle.turnLeft() | |
| 192 | turtle.turnLeft() | |
| 193 | tryUp() | |
| 194 | torch = 0 | |
| 195 | while depth > 1 do | |
| 196 | if turtle.forward() then | |
| 197 | depth = depth - 1 | |
| 198 | torch = torch +1 | |
| 199 | if torch == 5 then | |
| 200 | turtle.select(15) | |
| 201 | turtle.placeDown() | |
| 202 | torch = 0 | |
| 203 | end | |
| 204 | else | |
| 205 | turtle.dig() | |
| 206 | end | |
| 207 | end | |
| 208 | turtle.turnRight() | |
| 209 | j = 0 | |
| 210 | while j < 4 do | |
| 211 | tryDig() | |
| 212 | tryForward() | |
| 213 | tryDigUp() | |
| 214 | j = j +1 | |
| 215 | end | |
| 216 | turtle.turnRight() | |
| 217 | tryDown() | |
| 218 | print("Tunnel complete.")
| |
| 219 | rednet.send(92,"M01 - Tunnel complete.") | |
| 220 | rednet.send(92,"M01 - Mined "..collected.." items total." ) | |
| 221 | shell.run("test") |