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 tryDigUp() | |
37 | while turtle.detectUp() do | |
38 | if turtle.digUp() 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 refuel() | |
49 | local fuelLevel = turtle.getFuelLevel() | |
50 | if fuelLevel == "unlimited" or fuelLevel > 0 then | |
51 | return | |
52 | end | |
53 | ||
54 | local function tryRefuel() | |
55 | for n=1,16 do | |
56 | if turtle.getItemCount(n) > 0 then | |
57 | turtle.select(n) | |
58 | if turtle.refuel(1) then | |
59 | turtle.select(1) | |
60 | return true | |
61 | end | |
62 | end | |
63 | end | |
64 | turtle.select(1) | |
65 | return false | |
66 | end | |
67 | ||
68 | if not tryRefuel() then | |
69 | print( "Add more fuel to continue." ) | |
70 | while not tryRefuel() do | |
71 | sleep(1) | |
72 | end | |
73 | print( "Resuming Tunnel." ) | |
74 | end | |
75 | end | |
76 | ||
77 | local function tryUp() | |
78 | refuel() | |
79 | while not turtle.up() do | |
80 | if turtle.detectUp() then | |
81 | if not tryDigUp() then | |
82 | return false | |
83 | end | |
84 | elseif turtle.attackUp() then | |
85 | collect() | |
86 | else | |
87 | sleep( 0.5 ) | |
88 | end | |
89 | end | |
90 | return true | |
91 | end | |
92 | ||
93 | local function tryBack() | |
94 | refuel() | |
95 | while not turtle.back() do | |
96 | if turtle.detect() then | |
97 | - | if not tryDigDown() then |
97 | + | if not tryDig() then |
98 | return false | |
99 | end | |
100 | elseif turtle.attack() then | |
101 | collect() | |
102 | else | |
103 | sleep( 0.5 ) | |
104 | end | |
105 | end | |
106 | return true | |
107 | end | |
108 | ||
109 | local function tryDown() | |
110 | refuel() | |
111 | while not turtle.down() do | |
112 | if turtle.detectDown() then | |
113 | if not turtle.digDown() then | |
114 | return false | |
115 | end | |
116 | elseif turtle.attackDown() then | |
117 | collect() | |
118 | else | |
119 | sleep( 0.5 ) | |
120 | end | |
121 | end | |
122 | return true | |
123 | end | |
124 | ||
125 | local function tryForward() | |
126 | refuel() | |
127 | while not turtle.forward() do | |
128 | - | turtle.placeDown() |
128 | + | |
129 | - | tryDigUp() |
129 | + | |
130 | - | turtle.turnLeft() |
130 | + | |
131 | - | tryDig() |
131 | + | |
132 | - | tryUp() |
132 | + | |
133 | - | tryDig() |
133 | + | |
134 | - | tryUp() |
134 | + | |
135 | - | tryDig() |
135 | + | |
136 | - | turtle.turnRight() |
136 | + | |
137 | - | turtle.turnRight() |
137 | + | |
138 | - | tryDig() |
138 | + | |
139 | - | tryDown() |
139 | + | |
140 | - | tryDig() |
140 | + | |
141 | - | tryDown() |
141 | + | |
142 | - | tryDig() |
142 | + | |
143 | - | turtle.turnLeft() |
143 | + | |
144 | tryDigUp() | |
145 | turtle.turnLeft() | |
146 | for x1=1,7 do | |
147 | tryDig() | |
148 | tryUp() | |
149 | end | |
150 | turtle.turnRight() | |
151 | turtle.turnRight() | |
152 | tryForward() | |
153 | for x2=1,7 do | |
154 | tryDig() | |
155 | tryDown() | |
156 | end | |
157 | tryBack() | |
158 | turtle.turnLeft() | |
159 | ||
160 | if n<length then | |
161 | tryDig() | |
162 | if not tryForward() then | |
163 | print( "Aborting Tunnel." ) | |
164 | break | |
165 | end | |
166 | else | |
167 | print( "Tunnel complete." ) | |
168 | end | |
169 | ||
170 | end | |
171 | ||
172 | ||
173 | print( "Returning to start..." ) | |
174 | ||
175 | -- Return to where we started | |
176 | turtle.turnLeft() | |
177 | turtle.turnLeft() | |
178 | tryUp() | |
179 | j = 0 | |
180 | while depth > 1 do | |
181 | if tryForward() then | |
182 | depth = depth - 1 | |
183 | j = j+1 | |
184 | if j == 5 then | |
185 | turtle.select(15) | |
186 | turtle.placeDown() | |
187 | end | |
188 | else | |
189 | turtle.dig() | |
190 | end | |
191 | end | |
192 | tryDown() | |
193 | turtle.turnRight() | |
194 | turtle.turnRight() | |
195 | ||
196 | ||
197 | print( "Tunnel complete." ) | |
198 | print( "Mined "..collected.." items total." ) |