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 | -- Mine in a quarry pattern until we hit something we can't dig | |
| 8 | local length = tonumber( tArgs[1] ) | |
| 9 | if length < 1 then | |
| 10 | print( "Tunnel length must be positive" ) | |
| 11 | return | |
| 12 | end | |
| 13 | ||
| 14 | local depth = length | |
| 15 | local collected = 0 | |
| 16 | ||
| 17 | local function collect() | |
| 18 | collected = collected + 1 | |
| 19 | if math.fmod(collected, 25) == 0 then | |
| 20 | print( "Mined "..collected.." items." ) | |
| 21 | end | |
| 22 | end | |
| 23 | ||
| 24 | local function tryDig() | |
| 25 | while turtle.detect() do | |
| 26 | if turtle.dig() then | |
| 27 | collect() | |
| 28 | sleep(0.5) | |
| 29 | else | |
| 30 | return false | |
| 31 | end | |
| 32 | end | |
| 33 | return true | |
| 34 | end | |
| 35 | ||
| 36 | local function tryDigDown() | |
| 37 | while turtle.detectDown() do | |
| 38 | if turtle.digDown() then | |
| 39 | collect() | |
| 40 | sleep(0.5) | |
| 41 | else | |
| 42 | return false | |
| 43 | end | |
| 44 | end | |
| 45 | return true | |
| 46 | end | |
| 47 | ||
| 48 | local function tryDigUp() | |
| 49 | while turtle.detectUp() do | |
| 50 | if turtle.digUp() then | |
| 51 | collect() | |
| 52 | sleep(0.5) | |
| 53 | else | |
| 54 | return false | |
| 55 | end | |
| 56 | end | |
| 57 | return true | |
| 58 | end | |
| 59 | ||
| 60 | local function refuel() | |
| 61 | local fuelLevel = turtle.getFuelLevel() | |
| 62 | if fuelLevel == "unlimited" or fuelLevel > 0 then | |
| 63 | return | |
| 64 | end | |
| 65 | ||
| 66 | local function tryRefuel() | |
| 67 | for n=1,16 do | |
| 68 | if turtle.getItemCount(n) > 0 then | |
| 69 | turtle.select(n) | |
| 70 | if turtle.refuel(1) then | |
| 71 | turtle.select(1) | |
| 72 | return true | |
| 73 | end | |
| 74 | end | |
| 75 | end | |
| 76 | turtle.select(1) | |
| 77 | return false | |
| 78 | end | |
| 79 | ||
| 80 | if not tryRefuel() then | |
| 81 | print( "Add more fuel to continue." ) | |
| 82 | while not tryRefuel() do | |
| 83 | sleep(1) | |
| 84 | end | |
| 85 | print( "Resuming Tunnel." ) | |
| 86 | end | |
| 87 | end | |
| 88 | ||
| 89 | local function tryUp() | |
| 90 | refuel() | |
| 91 | while not turtle.up() do | |
| 92 | if turtle.detectUp() then | |
| 93 | if not tryDigUp() then | |
| 94 | return false | |
| 95 | end | |
| 96 | elseif turtle.attackUp() then | |
| 97 | collect() | |
| 98 | else | |
| 99 | sleep( 0.5 ) | |
| 100 | end | |
| 101 | end | |
| 102 | return true | |
| 103 | end | |
| 104 | ||
| 105 | local function tryDown() | |
| 106 | refuel() | |
| 107 | while not turtle.down() do | |
| 108 | if turtle.detectDown() then | |
| 109 | if not tryDigDown() then | |
| 110 | return false | |
| 111 | end | |
| 112 | elseif turtle.attackDown() then | |
| 113 | collect() | |
| 114 | else | |
| 115 | sleep( 0.5 ) | |
| 116 | end | |
| 117 | end | |
| 118 | return true | |
| 119 | end | |
| 120 | ||
| 121 | local function tryFackel() | |
| 122 | turtle.select(16) | |
| 123 | turtle.turnRight() | |
| 124 | print("Fackel 1")
| |
| 125 | turtle.place() | |
| 126 | turtle.turnLeft() | |
| 127 | turtle.select(1) | |
| 128 | end | |
| 129 | ||
| 130 | function tryFackel2() | |
| 131 | turtle.select(16) | |
| 132 | turtle.placeDown() | |
| 133 | turtle.select(1) | |
| 134 | end | |
| 135 | ||
| 136 | ||
| 137 | local function tryForward() | |
| 138 | refuel() | |
| 139 | while not turtle.forward() do | |
| 140 | if turtle.detect() then | |
| 141 | if not tryDig() then | |
| 142 | return false | |
| 143 | end | |
| 144 | elseif turtle.attack() then | |
| 145 | collect() | |
| 146 | else | |
| 147 | sleep( 0.5 ) | |
| 148 | end | |
| 149 | end | |
| 150 | return true | |
| 151 | end | |
| 152 | ||
| 153 | local function tryGaenge() | |
| 154 | refuel() | |
| 155 | turtle.turnLeft() | |
| 156 | tryUp() | |
| 157 | tryForward() | |
| 158 | FAL = 0 | |
| 159 | for n=1,20 do | |
| 160 | FAL = FAL +1 | |
| 161 | tryForward() | |
| 162 | tryDigUp() | |
| 163 | tryDigDown() | |
| 164 | if FAL == 5 then | |
| 165 | tryFackel2() | |
| 166 | FAL = 0 | |
| 167 | end | |
| 168 | - | j = j+1 |
| 168 | + | |
| 169 | - | if j == 5 then |
| 169 | + | |
| 170 | - | turtle.select(15) |
| 170 | + | |
| 171 | - | turtle.placeDown() |
| 171 | + | for n=1,21 do |
| 172 | - | end |
| 172 | + | tryForward() |
| 173 | end | |
| 174 | tryForward() | |
| 175 | FAR = 0 | |
| 176 | for n=1,20 do | |
| 177 | FAR = FAR +1 | |
| 178 | tryForward() | |
| 179 | tryDigUp() | |
| 180 | tryDigDown() | |
| 181 | if FAR == 5 then | |
| 182 | tryFackel2() | |
| 183 | FAR = 0 | |
| 184 | end | |
| 185 | end | |
| 186 | turtle.turnLeft() | |
| 187 | turtle.turnLeft() | |
| 188 | for n=1,21 do | |
| 189 | tryForward() | |
| 190 | end | |
| 191 | turtle.turnRight() | |
| 192 | tryDown() | |
| 193 | end | |
| 194 | ||
| 195 | fa = 2 | |
| 196 | ga = 0 | |
| 197 | shell.run("clear")
| |
| 198 | print("")
| |
| 199 | print("Copyright @ Birog ")
| |
| 200 | print("")
| |
| 201 | print(" Fackel bitte ins Fach 16 legen ")
| |
| 202 | print(" Enderkiste ins Fach 15 legen ")
| |
| 203 | print("")
| |
| 204 | print( "Tunnelling..." ) | |
| 205 | print() | |
| 206 | for n=1,length do | |
| 207 | turtle.placeDown() | |
| 208 | tryDigUp() | |
| 209 | turtle.turnLeft() | |
| 210 | tryDig() | |
| 211 | tryUp() | |
| 212 | tryDig() | |
| 213 | tryUp() | |
| 214 | tryDig() | |
| 215 | turtle.turnRight() | |
| 216 | turtle.turnRight() | |
| 217 | tryDig() | |
| 218 | tryDown() | |
| 219 | tryDig() | |
| 220 | tryDown() | |
| 221 | tryDig() | |
| 222 | turtle.turnLeft() | |
| 223 | ga = ga +1 | |
| 224 | fa = fa +1 | |
| 225 | if ga == 3 then | |
| 226 | tryGaenge() | |
| 227 | ga = 0 | |
| 228 | end | |
| 229 | if fa == 3 then | |
| 230 | tryFackel() | |
| 231 | fa = 0 | |
| 232 | end | |
| 233 | term.setCursorPos(9,1) | |
| 234 | pro = 100/length*n | |
| 235 | print(" Es sind bereits "..pro.." Prozent abgeschlossen")
| |
| 236 | if n<length then | |
| 237 | tryDig() | |
| 238 | if not tryForward() then | |
| 239 | print( "Aborting Tunnel." ) | |
| 240 | break | |
| 241 | end | |
| 242 | else | |
| 243 | print( "Tunnel complete." ) | |
| 244 | end | |
| 245 | ||
| 246 | end | |
| 247 | ||
| 248 | ||
| 249 | print( "Returning to start..." ) | |
| 250 | ||
| 251 | -- Return to where we started | |
| 252 | turtle.turnLeft() | |
| 253 | turtle.turnLeft() | |
| 254 | tryUp() | |
| 255 | j = 0 | |
| 256 | while depth > 1 do | |
| 257 | if tryForward() then | |
| 258 | depth = depth - 1 | |
| 259 | else | |
| 260 | turtle.dig() | |
| 261 | end | |
| 262 | end | |
| 263 | tryDown() | |
| 264 | turtle.turnRight() | |
| 265 | turtle.turnRight() | |
| 266 | ||
| 267 | ||
| 268 | print( "Tunnel complete." ) | |
| 269 | print( "Mined "..collected.." items total." ) |