SHOW:
|
|
- or go back to the newest paste.
1 | --seconds=20 if 4 redstone engines pumping out chest | |
2 | --seconds=10 if 8 redstone engines pumping 2 ender chests | |
3 | --seconds=7 if 12 redstone engines pumping 3 ender chests | |
4 | seconds=20 | |
5 | local tArgs = { ... } | |
6 | if #tArgs ~= 1 then | |
7 | print( "Usage: excavate <diameter>" ) | |
8 | return | |
9 | end | |
10 | ||
11 | -- Mine in a quarry pattern until we hit something we can't dig | |
12 | local size = tonumber( tArgs[1] ) | |
13 | if size < 1 then | |
14 | print( "Excavate diameter must be positive" ) | |
15 | return | |
16 | end | |
17 | ||
18 | local depth = 0 | |
19 | local unloaded = 0 | |
20 | local collected = 0 | |
21 | ||
22 | local xPos,zPos = 0,0 | |
23 | local xDir,zDir = 0,1 | |
24 | ||
25 | local goTo -- Filled in further down | |
26 | local refuel -- Filled in further down | |
27 | ||
28 | local function unload( _bKeepOneFuelStack ) | |
29 | print( "Unloading items..." ) | |
30 | for n=1,16 do | |
31 | local nCount = turtle.getItemCount(n) | |
32 | if nCount > 0 then | |
33 | turtle.select(n) | |
34 | local bDrop = true | |
35 | if _bKeepOneFuelStack and turtle.refuel(0) then | |
36 | bDrop = false | |
37 | _bKeepOneFuelStack = false | |
38 | end | |
39 | if bDrop then | |
40 | turtle.drop() | |
41 | unloaded = unloaded + nCount | |
42 | sleep(seconds) | |
43 | end | |
44 | end | |
45 | end | |
46 | collected = 0 | |
47 | turtle.select(1) | |
48 | end | |
49 | ||
50 | local function returnSupplies() | |
51 | local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir | |
52 | print( "Returning to surface..." ) | |
53 | goTo( 0,0,0,0,-1 ) | |
54 | ||
55 | local fuelNeeded = 2*(x+y+z) + 1 | |
56 | if not refuel( fuelNeeded ) then | |
57 | unload( true ) | |
58 | print( "Waiting for fuel" ) | |
59 | while not refuel( fuelNeeded ) do | |
60 | sleep(1) | |
61 | end | |
62 | else | |
63 | unload( true ) | |
64 | end | |
65 | ||
66 | print( "Resuming mining..." ) | |
67 | goTo( x,y,z,xd,zd ) | |
68 | end | |
69 | ||
70 | local function collect() | |
71 | local bFull = true | |
72 | local nTotalItems = 0 | |
73 | for n=1,16 do | |
74 | local nCount = turtle.getItemCount(n) | |
75 | if nCount == 0 then | |
76 | bFull = false | |
77 | end | |
78 | nTotalItems = nTotalItems + nCount | |
79 | end | |
80 | ||
81 | if nTotalItems > collected then | |
82 | collected = nTotalItems | |
83 | if math.fmod(collected + unloaded, 50) == 0 then | |
84 | print( "Mined "..(collected + unloaded).." items." ) | |
85 | end | |
86 | end | |
87 | ||
88 | if bFull then | |
89 | print( "No empty slots left." ) | |
90 | return false | |
91 | end | |
92 | return true | |
93 | end | |
94 | ||
95 | function refuel( ammount ) | |
96 | local fuelLevel = turtle.getFuelLevel() | |
97 | if fuelLevel == "unlimited" then | |
98 | return true | |
99 | end | |
100 | ||
101 | local needed = ammount or (xPos + zPos + depth + 1) | |
102 | if turtle.getFuelLevel() < needed then | |
103 | local fueled = false | |
104 | for n=1,16 do | |
105 | if turtle.getItemCount(n) > 0 then | |
106 | turtle.select(n) | |
107 | if turtle.refuel(1) then | |
108 | while turtle.getItemCount(n) > 0 and turtle.getFuelLevel() < needed do | |
109 | turtle.refuel(1) | |
110 | end | |
111 | if turtle.getFuelLevel() >= needed then | |
112 | turtle.select(1) | |
113 | return true | |
114 | end | |
115 | end | |
116 | end | |
117 | end | |
118 | turtle.select(1) | |
119 | return false | |
120 | end | |
121 | ||
122 | return true | |
123 | end | |
124 | ||
125 | local function tryForwards() | |
126 | if not refuel() then | |
127 | print( "Not enough Fuel" ) | |
128 | returnSupplies() | |
129 | end | |
130 | ||
131 | while not turtle.forward() do | |
132 | if turtle.detect() then | |
133 | if turtle.dig() then | |
134 | if not collect() then | |
135 | returnSupplies() | |
136 | end | |
137 | else | |
138 | return false | |
139 | end | |
140 | elseif turtle.attack() then | |
141 | if not collect() then | |
142 | returnSupplies() | |
143 | end | |
144 | else | |
145 | sleep( 0.5 ) | |
146 | end | |
147 | end | |
148 | ||
149 | xPos = xPos + xDir | |
150 | zPos = zPos + zDir | |
151 | return true | |
152 | end | |
153 | ||
154 | local function tryDown() | |
155 | if not refuel() then | |
156 | print( "Not enough Fuel" ) | |
157 | returnSupplies() | |
158 | end | |
159 | ||
160 | while not turtle.down() do | |
161 | if turtle.detectDown() then | |
162 | if turtle.digDown() then | |
163 | if not collect() then | |
164 | returnSupplies() | |
165 | end | |
166 | else | |
167 | return false | |
168 | end | |
169 | elseif turtle.attackDown() then | |
170 | if not collect() then | |
171 | returnSupplies() | |
172 | end | |
173 | else | |
174 | sleep( 0.5 ) | |
175 | end | |
176 | end | |
177 | ||
178 | depth = depth + 1 | |
179 | if math.fmod( depth, 10 ) == 0 then | |
180 | print( "Descended "..depth.." metres." ) | |
181 | end | |
182 | ||
183 | return true | |
184 | end | |
185 | ||
186 | local function turnLeft() | |
187 | turtle.turnLeft() | |
188 | xDir, zDir = -zDir, xDir | |
189 | end | |
190 | ||
191 | local function turnRight() | |
192 | turtle.turnRight() | |
193 | xDir, zDir = zDir, -xDir | |
194 | end | |
195 | ||
196 | function goTo( x, y, z, xd, zd ) | |
197 | while depth > y do | |
198 | if turtle.up() then | |
199 | depth = depth - 1 | |
200 | elseif turtle.digUp() or turtle.attackUp() then | |
201 | collect() | |
202 | else | |
203 | sleep( 0.5 ) | |
204 | end | |
205 | end | |
206 | ||
207 | if xPos > x then | |
208 | while xDir ~= -1 do | |
209 | turnLeft() | |
210 | end | |
211 | while xPos > x do | |
212 | if turtle.forward() then | |
213 | xPos = xPos - 1 | |
214 | elseif turtle.dig() or turtle.attack() then | |
215 | collect() | |
216 | else | |
217 | sleep( 0.5 ) | |
218 | end | |
219 | end | |
220 | elseif xPos < x then | |
221 | while xDir ~= 1 do | |
222 | turnLeft() | |
223 | end | |
224 | while xPos < x do | |
225 | if turtle.forward() then | |
226 | xPos = xPos + 1 | |
227 | elseif turtle.dig() or turtle.attack() then | |
228 | collect() | |
229 | else | |
230 | sleep( 0.5 ) | |
231 | end | |
232 | end | |
233 | end | |
234 | ||
235 | if zPos > z then | |
236 | while zDir ~= -1 do | |
237 | turnLeft() | |
238 | end | |
239 | while zPos > z do | |
240 | if turtle.forward() then | |
241 | zPos = zPos - 1 | |
242 | elseif turtle.dig() or turtle.attack() then | |
243 | collect() | |
244 | else | |
245 | sleep( 0.5 ) | |
246 | end | |
247 | end | |
248 | elseif zPos < z then | |
249 | while zDir ~= 1 do | |
250 | turnLeft() | |
251 | end | |
252 | while zPos < z do | |
253 | if turtle.forward() then | |
254 | zPos = zPos + 1 | |
255 | elseif turtle.dig() or turtle.attack() then | |
256 | collect() | |
257 | else | |
258 | sleep( 0.5 ) | |
259 | end | |
260 | end | |
261 | end | |
262 | ||
263 | while depth < y do | |
264 | if turtle.down() then | |
265 | depth = depth + 1 | |
266 | elseif turtle.digDown() or turtle.attackDown() then | |
267 | collect() | |
268 | else | |
269 | sleep( 0.5 ) | |
270 | end | |
271 | end | |
272 | ||
273 | while zDir ~= zd or xDir ~= xd do | |
274 | turnLeft() | |
275 | end | |
276 | end | |
277 | ||
278 | if not refuel() then | |
279 | print( "Out of Fuel" ) | |
280 | return | |
281 | end | |
282 | ||
283 | print( "Excavating..." ) | |
284 | ||
285 | local reseal = false | |
286 | turtle.select(1) | |
287 | if turtle.digDown() then | |
288 | reseal = true | |
289 | end | |
290 | ||
291 | local alternate = 0 | |
292 | local done = false | |
293 | while not done do | |
294 | for n=1,size do | |
295 | for m=1,size-1 do | |
296 | if not tryForwards() then | |
297 | done = true | |
298 | break | |
299 | end | |
300 | end | |
301 | if done then | |
302 | break | |
303 | end | |
304 | if n<size then | |
305 | if math.fmod(n + alternate,2) == 0 then | |
306 | turnLeft() | |
307 | if not tryForwards() then | |
308 | done = true | |
309 | break | |
310 | end | |
311 | turnLeft() | |
312 | else | |
313 | turnRight() | |
314 | if not tryForwards() then | |
315 | done = true | |
316 | break | |
317 | end | |
318 | turnRight() | |
319 | end | |
320 | end | |
321 | end | |
322 | if done then | |
323 | break | |
324 | end | |
325 | ||
326 | if size > 1 then | |
327 | if math.fmod(size,2) == 0 then | |
328 | turnRight() | |
329 | else | |
330 | if alternate == 0 then | |
331 | turnLeft() | |
332 | else | |
333 | turnRight() | |
334 | end | |
335 | alternate = 1 - alternate | |
336 | end | |
337 | end | |
338 | ||
339 | if not tryDown() then | |
340 | done = true | |
341 | break | |
342 | end | |
343 | end | |
344 | ||
345 | print( "Returning to surface..." ) | |
346 | ||
347 | -- Return to where we started | |
348 | goTo( 0,0,0,0,-1 ) | |
349 | unload( false ) | |
350 | goTo( 0,0,0,0,1 ) | |
351 | ||
352 | -- Seal the hole | |
353 | if reseal then | |
354 | turtle.placeDown() | |
355 | end | |
356 | ||
357 | print( "Mined "..(collected + unloaded).." items total." ) |