SHOW:
|
|
- or go back to the newest paste.
| 1 | local tArgs = {...}
| |
| 2 | local length = tArgs[1] | |
| 3 | local numTunnels = tArgs[2] | |
| 4 | local inv = true | |
| 5 | local checkTorch = 0 | |
| 6 | local height = 0 | |
| 7 | local fullInvNum = 0 | |
| 8 | ||
| 9 | function isOre(name) | |
| 10 | return name == 'minecraft:coal_ore' | |
| 11 | or name == 'minecraft:iron_ore' | |
| 12 | or name == 'minecraft:gold_ore' | |
| 13 | or name == 'minecraft:diamond_ore' | |
| 14 | or name == 'minecraft:lapis_ore' | |
| 15 | or name == 'minecraft:redstone_ore' | |
| 16 | or name == 'minecraft:lit_redstone_ore' | |
| 17 | - | turtle.dig() |
| 17 | + | |
| 18 | - | -- This loop prevents gravel from screwing it all up |
| 18 | + | |
| 19 | - | while turtle.forward() == false do |
| 19 | + | function isOre(func) |
| 20 | - | turtle.dig() |
| 20 | + | local success, data = func() |
| 21 | - | end |
| 21 | + | return isOre(data['name']) |
| 22 | - | turtle.digUp() |
| 22 | + | |
| 23 | ||
| 24 | function isOre() | |
| 25 | return isOre(turtle.inspect) | |
| 26 | end | |
| 27 | ||
| 28 | function isOreUp() | |
| 29 | return isOre(turtle.inspectUp) | |
| 30 | end | |
| 31 | ||
| 32 | function isOreDown() | |
| 33 | return isOre(turtle.inspectDown) | |
| 34 | - | turtle.dig() |
| 34 | + | |
| 35 | - | while turtle.forward() == false do |
| 35 | + | |
| 36 | - | turtle.dig() |
| 36 | + | function repeatSuccess(func) |
| 37 | while func() do end | |
| 38 | - | turtle.digUp() |
| 38 | + | |
| 39 | ||
| 40 | function dig() | |
| 41 | repeatSuccess(turtle.dig) | |
| 42 | end | |
| 43 | ||
| 44 | function digUp() | |
| 45 | repeatSuccess(turtle.digUp) | |
| 46 | end | |
| 47 | - | turtle.dig() |
| 47 | + | |
| 48 | function digDown() | |
| 49 | repeatSuccess(turtle.digDown) | |
| 50 | - | turtle.dig() |
| 50 | + | |
| 51 | ||
| 52 | function searchAround() | |
| 53 | turtle.select(16) | |
| 54 | if isOre() then | |
| 55 | dig() | |
| 56 | turtle.forward() | |
| 57 | searchAround() | |
| 58 | turtle.back() | |
| 59 | elseif isOreDown() then | |
| 60 | digDown() | |
| 61 | turtle.down() | |
| 62 | searchAround() | |
| 63 | turtle.up() | |
| 64 | elseif isOreUp() then | |
| 65 | digUp() | |
| 66 | turtle.up() | |
| 67 | searchAround() | |
| 68 | turtle.down() | |
| 69 | end | |
| 70 | ||
| 71 | turtle.turnLeft() | |
| 72 | if isOre() then | |
| 73 | dig() | |
| 74 | turtle.forward() | |
| 75 | searchAround() | |
| 76 | turtle.back() | |
| 77 | end | |
| 78 | ||
| 79 | turtle.turnRight() | |
| 80 | turtle.turnRight() | |
| 81 | if isOre() then | |
| 82 | dig() | |
| 83 | turtle.forward() | |
| 84 | searchAround() | |
| 85 | turtle.back() | |
| 86 | end | |
| 87 | turtle.turnLeft() | |
| 88 | end | |
| 89 | ||
| 90 | -- The basic function to move forward and dig | |
| 91 | function tunnel() | |
| 92 | -- These used throughout to erase screen | |
| 93 | term.clear() | |
| 94 | term.setCursorPos(1,1) | |
| 95 | print("Mining...")
| |
| 96 | for i=1,length do | |
| 97 | fuel() | |
| 98 | dig() | |
| 99 | turtle.forward() | |
| 100 | digUp() | |
| 101 | searchAround() | |
| 102 | torch() | |
| 103 | end | |
| 104 | end | |
| 105 | ||
| 106 | -- The function to turn around and go the other direction down the tunnel, also clears side tunnels | |
| 107 | function turnAround() | |
| 108 | term.clear() | |
| 109 | term.setCursorPos(1,1) | |
| 110 | print("Turning around...")
| |
| 111 | for k = 1,6 do | |
| 112 | fuel() | |
| 113 | dig() | |
| 114 | turtle.forward() | |
| 115 | digUp() | |
| 116 | searchAround() | |
| 117 | - | turtle.digUp() |
| 117 | + | |
| 118 | end | |
| 119 | ||
| 120 | checkInv() | |
| 121 | ||
| 122 | while turtle.back() == false do | |
| 123 | turtle.turnRight() | |
| 124 | turtle.turnRight() | |
| 125 | dig() | |
| 126 | for i = 1,3 do | |
| 127 | turtle.forward() | |
| 128 | dig() | |
| 129 | end | |
| 130 | turtle.turnRight() | |
| 131 | turtle.turnRight() | |
| 132 | for i = 1,3 do | |
| 133 | turtle.back() | |
| 134 | end | |
| 135 | end | |
| 136 | turtle.back() | |
| 137 | turtle.back() | |
| 138 | end | |
| 139 | ||
| 140 | -- Clears the specified item from the inventory, most likely cobble, also stops on full inv | |
| 141 | function checkInv() | |
| 142 | term.clear() | |
| 143 | term.setCursorPos(1,1) | |
| 144 | print("Trashing...")
| |
| 145 | for y = 2,16 do | |
| 146 | turtle.select(y) | |
| 147 | if turtle.compareTo(1) then | |
| 148 | turtle.drop() | |
| 149 | end | |
| 150 | end | |
| 151 | end | |
| 152 | ||
| 153 | function fullInv() | |
| 154 | -- To not spill items everywhere, some credit to link0153 :) | |
| 155 | for i = 1,16 do | |
| 156 | if turtle.getItemCount(i) > 0 then | |
| 157 | fullInvNum = fullInvNum + 1 | |
| 158 | end | |
| 159 | end | |
| 160 | while fullInvNum == 16 do | |
| 161 | term.clear() | |
| 162 | term.setCursorPos(1,1) | |
| 163 | print("Inventory full, please clear.")
| |
| 164 | sleep(5) | |
| 165 | for i = 1,16 do | |
| 166 | if turtle.getItemCount(i) == 0 then | |
| 167 | fullInvNum = 0 | |
| 168 | end | |
| 169 | end | |
| 170 | end | |
| 171 | fullInvNum = 0 | |
| 172 | term.clear() | |
| 173 | term.setCursorPos(1,1) | |
| 174 | print("Mining...")
| |
| 175 | end | |
| 176 | ||
| 177 | -- Checks how long since the last torch, then decides to place one above or not | |
| 178 | function torch() | |
| 179 | -- Checks if low on torches | |
| 180 | if turtle.getItemCount(16) < 5 then | |
| 181 | term.clear() | |
| 182 | term.setCursorPos(1,1) | |
| 183 | print("Waiting for torches...place in bottom right.")
| |
| 184 | while turtle.getItemCount(16) < 5 do | |
| 185 | sleep(2) | |
| 186 | end | |
| 187 | end | |
| 188 | term.clear() | |
| 189 | term.setCursorPos(1,1) | |
| 190 | print("Mining...")
| |
| 191 | if checkTorch == 8 then | |
| 192 | fuel() | |
| 193 | turtle.select(16) | |
| 194 | turtle.up() | |
| 195 | digUp() | |
| 196 | -- This if and loop will bring the turtle back down from the placed torch | |
| 197 | if turtle.placeUp() or turtle.getItemCount(16) == 0 then | |
| 198 | for i = 0,height do | |
| 199 | fuel() | |
| 200 | turtle.down() | |
| 201 | end | |
| 202 | turtle.select(1) | |
| 203 | checkTorch = 0 | |
| 204 | height = 0 | |
| 205 | else | |
| 206 | height = height + 1 | |
| 207 | torch() | |
| 208 | end | |
| 209 | -- If it's too soon, dont place a torch | |
| 210 | else | |
| 211 | checkTorch = checkTorch + 1 | |
| 212 | end | |
| 213 | end | |
| 214 | ||
| 215 | -- Checks the fuel level, asks for more if necessary | |
| 216 | function fuel() | |
| 217 | if turtle.getFuelLevel() < 50 then | |
| 218 | print ("Wating for fuel...place in bottom left.")
| |
| 219 | while turtle.getFuelLevel() < 50 do | |
| 220 | turtle.select(13) | |
| 221 | turtle.refuel() | |
| 222 | sleep(2) | |
| 223 | end | |
| 224 | end | |
| 225 | term.clear() | |
| 226 | term.setCursorPos(1,1) | |
| 227 | print("Mining...")
| |
| 228 | turtle.select(1) | |
| 229 | end | |
| 230 | ||
| 231 | -- This function is a one time startup function, makes sure the turtle has the necessary materials | |
| 232 | function begin() | |
| 233 | turtle.select(1) | |
| 234 | -- Checks for trash item | |
| 235 | if turtle.getItemCount(1) == 0 then | |
| 236 | print("Please place an item to trash in the top left.")
| |
| 237 | while turtle.getItemCount(1) == 0 do | |
| 238 | sleep(1) | |
| 239 | end | |
| 240 | term.clear() | |
| 241 | term.setCursorPos(1,1) | |
| 242 | begin() | |
| 243 | -- Confirms trashed item | |
| 244 | else | |
| 245 | print("The item in the top left will be trashed...confirm?")
| |
| 246 | os.pullEvent("key")
| |
| 247 | end | |
| 248 | term.clear() | |
| 249 | term.setCursorPos(1,1) | |
| 250 | end | |
| 251 | ||
| 252 | -- From here is the main code | |
| 253 | ||
| 254 | -- Checks for correct args | |
| 255 | if not (tArgs[1] == nil or tArgs[2] == nil) then | |
| 256 | begin() | |
| 257 | -- Loops for the specified # of tunnels, one tunnel being up and back | |
| 258 | for j = 1,numTunnels do | |
| 259 | tunnel() | |
| 260 | fullInv() | |
| 261 | turtle.turnLeft() | |
| 262 | turnAround() | |
| 263 | fullInv() | |
| 264 | turtle.turnLeft() | |
| 265 | tunnel() | |
| 266 | fullInv() | |
| 267 | turtle.turnRight() | |
| 268 | turnAround() | |
| 269 | fullInv() | |
| 270 | turtle.turnRight() | |
| 271 | end | |
| 272 | -- Resets the screen and displays a confirmation of finishing | |
| 273 | term.clear() | |
| 274 | term.setCursorPos(1,1) | |
| 275 | print("Done!")
| |
| 276 | else | |
| 277 | term.clear() | |
| 278 | term.setCursorPos(1,1) | |
| 279 | print("Not enough arguments, should be used 'branch [length] [number of tunnels]'")
| |
| 280 | end |