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