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 | -- The basic function to move forward and dig | |
| 10 | function tunnel() | |
| 11 | -- These used throughout to erase screen | |
| 12 | term.clear() | |
| 13 | term.setCursorPos(1,1) | |
| 14 | print("Mining...")
| |
| 15 | for i=1,length do | |
| 16 | fuel() | |
| 17 | turtle.dig() | |
| 18 | -- This loop prevents gravel from screwing it all up | |
| 19 | while turtle.forward() == false do | |
| 20 | turtle.dig() | |
| 21 | end | |
| 22 | turtle.digUp() | |
| 23 | torch() | |
| 24 | end | |
| 25 | end | |
| 26 | ||
| 27 | -- The function to turn around and go the other direction down the tunnel, also clears side tunnels | |
| 28 | function turnAround() | |
| 29 | term.clear() | |
| 30 | term.setCursorPos(1,1) | |
| 31 | print("Turning around...")
| |
| 32 | for k = 1,6 do | |
| 33 | fuel() | |
| 34 | turtle.dig() | |
| 35 | while turtle.forward() == false do | |
| 36 | turtle.dig() | |
| 37 | end | |
| 38 | turtle.digUp() | |
| 39 | torch() | |
| 40 | end | |
| 41 | ||
| 42 | checkInv() | |
| 43 | ||
| 44 | while turtle.back() == false do | |
| 45 | turtle.turnRight() | |
| 46 | turtle.turnRight() | |
| 47 | turtle.dig() | |
| 48 | for i = 1,3 do | |
| 49 | turtle.forward() | |
| 50 | turtle.dig() | |
| 51 | end | |
| 52 | turtle.turnRight() | |
| 53 | turtle.turnRight() | |
| 54 | for i = 1,3 do | |
| 55 | turtle.back() | |
| 56 | end | |
| 57 | end | |
| 58 | turtle.back() | |
| 59 | turtle.back() | |
| 60 | end | |
| 61 | ||
| 62 | -- Clears the specified item from the inventory, most likely cobble, also stops on full inv | |
| 63 | function checkInv() | |
| 64 | term.clear() | |
| 65 | term.setCursorPos(1,1) | |
| 66 | print("Trashing...")
| |
| 67 | for y = 2,16 do | |
| 68 | turtle.select(y) | |
| 69 | if turtle.compareTo(1) then | |
| 70 | turtle.drop() | |
| 71 | end | |
| 72 | end | |
| 73 | end | |
| 74 | ||
| 75 | function fullInv() | |
| 76 | -- To not spill items everywhere, some credit to link0153 :) | |
| 77 | for i = 1,16 do | |
| 78 | if turtle.getItemCount(i) > 0 then | |
| 79 | fullInvNum = fullInvNum + 1 | |
| 80 | end | |
| 81 | - | if fullInvNum == 16 then |
| 81 | + | |
| 82 | while fullInvNum == 16 do | |
| 83 | term.clear() | |
| 84 | term.setCursorPos(1,1) | |
| 85 | print("Inventory full, please clear.")
| |
| 86 | - | fullInv() |
| 86 | + | |
| 87 | for i = 1,16 do | |
| 88 | if turtle.getItemCount(i) == 0 then | |
| 89 | fullInvNum = 0 | |
| 90 | end | |
| 91 | end | |
| 92 | end | |
| 93 | fullInvNum = 0 | |
| 94 | term.clear() | |
| 95 | term.setCursorPos(1,1) | |
| 96 | print("Mining...")
| |
| 97 | end | |
| 98 | ||
| 99 | -- Checks how long since the last torch, then decides to place one above or not | |
| 100 | function torch() | |
| 101 | -- Checks if low on torches | |
| 102 | if turtle.getItemCount(16) < 5 then | |
| 103 | term.clear() | |
| 104 | term.setCursorPos(1,1) | |
| 105 | print("Waiting for torches...place in bottom right.")
| |
| 106 | while turtle.getItemCount(16) < 5 do | |
| 107 | sleep(2) | |
| 108 | end | |
| 109 | end | |
| 110 | term.clear() | |
| 111 | term.setCursorPos(1,1) | |
| 112 | print("Mining...")
| |
| 113 | if checkTorch == 8 then | |
| 114 | fuel() | |
| 115 | turtle.select(16) | |
| 116 | turtle.up() | |
| 117 | turtle.digUp() | |
| 118 | -- This if and loop will bring the turtle back down from the placed torch | |
| 119 | if turtle.placeUp() or turtle.getItemCount(16) == 0 then | |
| 120 | for i = 0,height do | |
| 121 | fuel() | |
| 122 | turtle.down() | |
| 123 | end | |
| 124 | turtle.select(1) | |
| 125 | checkTorch = 0 | |
| 126 | height = 0 | |
| 127 | else | |
| 128 | height = height + 1 | |
| 129 | torch() | |
| 130 | end | |
| 131 | -- If it's too soon, dont place a torch | |
| 132 | else | |
| 133 | checkTorch = checkTorch + 1 | |
| 134 | end | |
| 135 | end | |
| 136 | ||
| 137 | -- Checks the fuel level, asks for more if necessary | |
| 138 | function fuel() | |
| 139 | if turtle.getFuelLevel() < 50 then | |
| 140 | print ("Wating for fuel...place in bottom left.")
| |
| 141 | while turtle.getFuelLevel() < 50 do | |
| 142 | turtle.select(13) | |
| 143 | turtle.refuel() | |
| 144 | sleep(2) | |
| 145 | end | |
| 146 | end | |
| 147 | term.clear() | |
| 148 | term.setCursorPos(1,1) | |
| 149 | print("Mining...")
| |
| 150 | turtle.select(1) | |
| 151 | end | |
| 152 | ||
| 153 | -- This function is a one time startup function, makes sure the turtle has the necessary materials | |
| 154 | function begin() | |
| 155 | turtle.select(1) | |
| 156 | -- Checks for trash item | |
| 157 | if turtle.getItemCount(1) == 0 then | |
| 158 | print("Please place an item to trash in the top left.")
| |
| 159 | while turtle.getItemCount(1) == 0 do | |
| 160 | sleep(1) | |
| 161 | end | |
| 162 | term.clear() | |
| 163 | term.setCursorPos(1,1) | |
| 164 | begin() | |
| 165 | -- Confirms trashed item | |
| 166 | else | |
| 167 | print("The item in the top left will be trashed...confirm?")
| |
| 168 | os.pullEvent("key")
| |
| 169 | end | |
| 170 | term.clear() | |
| 171 | term.setCursorPos(1,1) | |
| 172 | end | |
| 173 | ||
| 174 | -- From here is the main code | |
| 175 | begin() | |
| 176 | -- Loops for the specified # of tunnels, one tunnel being up and back | |
| 177 | for j = 1,numTunnels do | |
| 178 | tunnel() | |
| 179 | fullInv() | |
| 180 | turtle.turnLeft() | |
| 181 | turnAround() | |
| 182 | fullInv() | |
| 183 | turtle.turnLeft() | |
| 184 | tunnel() | |
| 185 | fullInv() | |
| 186 | turtle.turnRight() | |
| 187 | turnAround() | |
| 188 | fullInv() | |
| 189 | turtle.turnRight() | |
| 190 | end | |
| 191 | -- Resets the screen and displays a confirmation of finishing | |
| 192 | term.clear() | |
| 193 | term.setCursorPos(1,1) | |
| 194 | print("Done!") |