SHOW:
|
|
- or go back to the newest paste.
1 | ||
2 | --SETTINGS DEFAULTS | |
3 | local stop=false | |
4 | local settings={} | |
5 | - | settings["miningTime"]=5 |
5 | + | settings["miningTime"]=4 |
6 | settings["digDelay"]=1 | |
7 | settings["reserveFuelLevel"]=10 | |
8 | settings["chargeTime"]=30 | |
9 | settings["debug"]=false | |
10 | - | settings["blocksToTravel"]=0 |
10 | + | |
11 | - | settings["blocksTraveled"]=0 |
11 | + | |
12 | - | settings["rowsToTravel"]=0 |
12 | + | |
13 | - | settings["rowsTraveled"]=0 |
13 | + | |
14 | - | settings["blocksMined"]=0 |
14 | + | |
15 | file.close() | |
16 | - | settings["turning"]="left" |
16 | + | |
17 | - | settings["midTurn"]=false |
17 | + | |
18 | ||
19 | - | --CONSTANTS |
19 | + | |
20 | - | local cNone=0 |
20 | + | |
21 | - | local cLeft=1 |
21 | + | |
22 | - | local cYes=2 |
22 | + | |
23 | - | local cNo=3 |
23 | + | |
24 | - | local cPowerDown=4 |
24 | + | |
25 | - | local cPowerUp=5 |
25 | + | function cleanUp() |
26 | - | local cForward=6 |
26 | + | if nextStep=="chargeplacecharge" or nextStep=="chargedigcharge" then |
27 | - | local cReadyCharge=7 |
27 | + | if settings["debug"]==true then |
28 | - | local cComplete=8 |
28 | + | print("charge deployed") |
29 | - | local cGoHome=9 |
29 | + | |
30 | - | local cRight=10 |
30 | + | if turtle.getItemCount(3)==0 then |
31 | - | local cReboot=11 |
31 | + | if settings["debug"]==true then |
32 | - | local cShutdown=12 |
32 | + | print("Fully deployed") |
33 | - | local cClearSettings=13 |
33 | + | end |
34 | - | local cNeedFuel=14 |
34 | + | digCharge() |
35 | - | local cPairing=15 |
35 | + | elseif turtle.getItemCount(7)==0 then |
36 | if settings["debug"]==true then | |
37 | print("bc producer deployed") | |
38 | end | |
39 | if turtle.detectDown()==false then | |
40 | if settings["debug"]==true then | |
41 | print("moving down one") | |
42 | end | |
43 | turtle.down() | |
44 | end | |
45 | turtle.select(7) | |
46 | turtle.digDown() | |
47 | turtle.down() | |
48 | turtle.select(6) | |
49 | turtle.digDown() | |
50 | turtle.down() | |
51 | turtle.select(5) | |
52 | turtle.digDown() | |
53 | turtle.forward() | |
54 | turtle.select(4) | |
55 | turtle.digDown() | |
56 | elseif turtle.getItemCount(6)==0 then | |
57 | if settings["debug"]==true then | |
58 | print("Energy bridge deployed") | |
59 | end | |
60 | if turtle.detectDown()==false then | |
61 | if settings["debug"]==true then | |
62 | print("moving down one") | |
63 | end | |
64 | turtle.down() | |
65 | end | |
66 | turtle.select(6) | |
67 | turtle.digDown() | |
68 | turtle.down() | |
69 | turtle.select(5) | |
70 | turtle.digDown() | |
71 | turtle.forward() | |
72 | turtle.select(4) | |
73 | turtle.digDown() | |
74 | elseif turtle.getItemCount(5)==0 then | |
75 | if settings["debug"]==true then | |
76 | print("IC2 consumer deployed") | |
77 | end | |
78 | if turtle.detectDown()==false then | |
79 | if settings["debug"]==true then | |
80 | print("moving down one") | |
81 | end | |
82 | turtle.down() | |
83 | end | |
84 | turtle.select(5) | |
85 | turtle.digDown() | |
86 | turtle.forward() | |
87 | turtle.select(4) | |
88 | turtle.digDown() | |
89 | elseif turtle.getItemCount(4)==0 then | |
90 | if settings["debug"]==true then | |
91 | print("solar panel deployed") | |
92 | end | |
93 | if turtle.detectDown()==false then | |
94 | if settings["debug"]==true then | |
95 | print("moving forward one") | |
96 | end | |
97 | turtle.forward() | |
98 | end | |
99 | turtle.select(4) | |
100 | turtle.digDown() | |
101 | end | |
102 | digChest() | |
103 | digMiningWell() | |
104 | elseif nextStep=="chargewaitforrefuel" then | |
105 | digCharge() | |
106 | digChest() | |
107 | digMiningWell() | |
108 | elseif nextStep=="placeminingwell" or nextStep=="digminingwell" then | |
109 | if turtle.getItemCount(2)==0 then | |
110 | digMiningWell() | |
111 | end | |
112 | elseif nextStep=="placechest" or nextStep=="digchest" then | |
113 | if turtle.getItemCount(1)==0 then | |
114 | digChest() | |
115 | end | |
116 | digMiningWell() | |
117 | elseif nextStep=="powerdown" or nextStep=="powerup" then | |
118 | if settings["debug"]==true then | |
119 | print("power deployed") | |
120 | end | |
121 | if turtle.getItemCount(4)==0 then | |
122 | if settings["debug"]==true then | |
123 | print("fully deployed") | |
124 | end | |
125 | digCharge() | |
126 | elseif turtle.getItemCount(5)==0 then | |
127 | if settings["debug"]==true then | |
128 | print("IC2 deployed") | |
129 | end | |
130 | if turtle.detectDown()==false then | |
131 | if settings["debug"]==true then | |
132 | print("moving down one") | |
133 | end | |
134 | turtle.down() | |
135 | end | |
136 | turtle.select(7) | |
137 | turtle.digDown() | |
138 | turtle.down() | |
139 | turtle.select(6) | |
140 | turtle.digDown() | |
141 | turtle.down() | |
142 | turtle.select(5) | |
143 | turtle.digDown() | |
144 | elseif turtle.getItemCount(6)==0 then | |
145 | if settings["debug"]==true then | |
146 | print("energy bridge deployed") | |
147 | end | |
148 | if turtle.detectDown()==false then | |
149 | if settings["debug"]==true then | |
150 | print("moving down one") | |
151 | end | |
152 | turtle.down() | |
153 | end | |
154 | turtle.select(6) | |
155 | turtle.digDown() | |
156 | turtle.down() | |
157 | turtle.select(5) | |
158 | turtle.digDown() | |
159 | elseif turtle.getItemCount(7)==0 then | |
160 | if settings["debug"]==true then | |
161 | print("bc deployed") | |
162 | end | |
163 | if turtle.detectDown()==false then | |
164 | if settings["debug"]==true then | |
165 | print("moving down one") | |
166 | end | |
167 | turtle.down() | |
168 | end | |
169 | turtle.select(5) | |
170 | turtle.digDown() | |
171 | end | |
172 | digChest() | |
173 | digMiningWell() | |
174 | end | |
175 | if settings["debug"]==true then | |
176 | print("finished cleanup") | |
177 | end | |
178 | setNextStep("topoff") | |
179 | end | |
180 | ||
181 | function checkStatus() | |
182 | if turtle.getItemCount(1)>0 then | |
183 | print("Ender Chest OK") | |
184 | else | |
185 | print("Please insert an Ender Chest into slot 1") | |
186 | while turtle.getItemCount(1)==0 do | |
187 | turtle.select(1) | |
188 | sleep(0.1) | |
189 | end | |
190 | end | |
191 | if turtle.getItemCount(2)>0 then | |
192 | print("Mining Well OK") | |
193 | else | |
194 | print("Please insert Mining Well into slot 2") | |
195 | while turtle.getItemCount(2)==0 do | |
196 | turtle.select(2) | |
197 | sleep(0.1) | |
198 | end | |
199 | end | |
200 | if turtle.getFuelLevel()~="unlimited" then | |
201 | if turtle.getItemCount(3)>0 then | |
202 | - | turtle.dig() |
202 | + | |
203 | else | |
204 | print("Please insert Advanced Charge Station (or higher) into slot 3") | |
205 | - | turtle.dig() |
205 | + | |
206 | turtle.select(3) | |
207 | sleep(0.1) | |
208 | - | turtle.dig() |
208 | + | |
209 | end | |
210 | end | |
211 | - | turtle.dig() |
211 | + | |
212 | print("Solar Panel OK") | |
213 | else | |
214 | print("Please insert Ultimate Hybrid Solar Panel into slot 4") | |
215 | while turtle.getItemCount(4)==0 do | |
216 | turtle.select(4) | |
217 | sleep(0.1) | |
218 | end | |
219 | end | |
220 | if turtle.getItemCount(5)>0 then | |
221 | print("IC2 Consumer OK") | |
222 | else | |
223 | print("Please insert IC2 HV Consumer into slot 5") | |
224 | while turtle.getItemCount(5)==0 do | |
225 | turtle.select(5) | |
226 | sleep(0.1) | |
227 | end | |
228 | end | |
229 | if turtle.getItemCount(6)>0 then | |
230 | print("Energy Bridge OK") | |
231 | else | |
232 | print("Please insert Energy Bridge into slot 6") | |
233 | while turtle.getItemCount(6)==0 do | |
234 | turtle.select(6) | |
235 | sleep(0.1) | |
236 | end | |
237 | end | |
238 | if turtle.getItemCount(7)>0 then | |
239 | print("BC Producer OK") | |
240 | else | |
241 | print("Please insert BC Producer into slot 7") | |
242 | while turtle.getItemCount(7)==0 do | |
243 | turtle.select(7) | |
244 | sleep(0.1) | |
245 | end | |
246 | end | |
247 | if needsFuel() then | |
248 | if turtle.getItemCount(16)>0 then | |
249 | print("Fuel Level OK") | |
250 | else | |
251 | - | if debug==true then |
251 | + | |
252 | while turtle.getItemCount(16)==0 do | |
253 | turtle.select(16) | |
254 | sleep(0.1) | |
255 | end | |
256 | end | |
257 | end | |
258 | ||
259 | end | |
260 | ||
261 | function needsFuel() | |
262 | local level=turtle.getFuelLevel() | |
263 | if level=="unlimited" or level>settings["reserveFuelLevel"] then | |
264 | return false | |
265 | else | |
266 | return true | |
267 | end | |
268 | end | |
269 | ||
270 | function moveForward() | |
271 | while turtle.detect() do | |
272 | turtle.dig() | |
273 | sleep(settings["digDelay"]) | |
274 | end | |
275 | while turtle.forward()==false do | |
276 | turtle.dig() | |
277 | - | while turtle.forward()==false do |
277 | + | |
278 | turtle.attack() | |
279 | end | |
280 | end | |
281 | ||
282 | - | while turtle.forward()==false do |
282 | + | |
283 | if needsFuel()==true then | |
284 | setNextStep("chargeplacecharge") | |
285 | else | |
286 | setNextStep("placeminingwell") | |
287 | - | while turtle.forward()==false do |
287 | + | |
288 | end | |
289 | ||
290 | function placeCharge() | |
291 | turtle.select(4) | |
292 | while turtle.placeDown()==false do | |
293 | turtle.digDown() | |
294 | sleep(settings["digDelay"]) | |
295 | turtle.attackDown() | |
296 | end | |
297 | turtle.back() | |
298 | turtle.select(5) | |
299 | while turtle.placeDown()==false do | |
300 | turtle.digDown() | |
301 | sleep(settings["digDelay"]) | |
302 | - | while turtle.back()==false do |
302 | + | |
303 | end | |
304 | turtle.up() | |
305 | turtle.select(6) | |
306 | while turtle.placeDown()==false do | |
307 | turtle.digDown() | |
308 | sleep(settings["digDelay"]) | |
309 | turtle.attackDown() | |
310 | end | |
311 | turtle.up() | |
312 | turtle.select(7) | |
313 | while turtle.placeDown()==false do | |
314 | turtle.digDown() | |
315 | - | while turtle.back()==false do |
315 | + | |
316 | turtle.attackDown() | |
317 | end | |
318 | turtle.up() | |
319 | turtle.select(3) | |
320 | while turtle.placeDown()==false do | |
321 | turtle.digDown() | |
322 | sleep(settings["digDelay"]) | |
323 | turtle.attackDown() | |
324 | end | |
325 | end | |
326 | ||
327 | function digCharge() | |
328 | - | while turtle.back()==false do |
328 | + | |
329 | turtle.digDown() | |
330 | turtle.down() | |
331 | turtle.select(7) | |
332 | turtle.digDown() | |
333 | turtle.down() | |
334 | turtle.select(6) | |
335 | turtle.digDown() | |
336 | turtle.down() | |
337 | turtle.select(5) | |
338 | turtle.digDown() | |
339 | turtle.forward() | |
340 | turtle.select(4) | |
341 | turtle.digDown() | |
342 | end | |
343 | ||
344 | function placeChest() | |
345 | turtle.select(1) | |
346 | turtle.back() | |
347 | while turtle.place()==false do | |
348 | turtle.attack() | |
349 | turtle.dig() | |
350 | sleep(settings["digDelay"]) | |
351 | end | |
352 | end | |
353 | ||
354 | function digChest() | |
355 | turtle.select(1) | |
356 | if turtle.getItemCount(1) > 0 then | |
357 | turtle.drop() | |
358 | end | |
359 | turtle.dig() | |
360 | turtle.forward() | |
361 | end | |
362 | ||
363 | function placeMiningWell() | |
364 | turtle.select(2) | |
365 | while turtle.placeDown()==false do | |
366 | turtle.digDown() | |
367 | sleep(settings["digDelay"]) | |
368 | turtle.attackDown() | |
369 | end | |
370 | end | |
371 | ||
372 | function digMiningWell() | |
373 | turtle.select(2) | |
374 | if turtle.getItemCount(2) > 0 then | |
375 | turtle.drop() | |
376 | end | |
377 | turtle.digDown() | |
378 | end | |
379 | ||
380 | function setNextStep(next) | |
381 | if settings["debug"]==true then | |
382 | print("Set next step "..next) | |
383 | end | |
384 | local file=nil | |
385 | while file==nil do | |
386 | file=fs.open("SnapBoxStepTracker","w") | |
387 | end | |
388 | file.write(next) | |
389 | file.close() | |
390 | nextStep=next | |
391 | end | |
392 | ||
393 | function getNextStep() | |
394 | local file=fs.open("SnapBoxStepTracker","r") | |
395 | if file==nil then | |
396 | setNextStep("topoff") | |
397 | else | |
398 | local returnValue=file.readAll() | |
399 | file.close() | |
400 | setNextStep(returnValue) | |
401 | end | |
402 | end | |
403 | - | --check to make sure it has all the items it needs |
403 | + | |
404 | - | checkStatus() |
404 | + | |
405 | turtle.select(4) | |
406 | - | --initial refuel |
406 | + | |
407 | - | turtle.select(16) |
407 | + | turtle.down() |
408 | - | turtle.refuel() |
408 | + | |
409 | turtle.digDown() | |
410 | turtle.down() | |
411 | - | nextStep="topoff" |
411 | + | |
412 | turtle.digDown() | |
413 | turtle.down() | |
414 | turtle.select(7) | |
415 | - | getNextStep() |
415 | + | |
416 | end | |
417 | ||
418 | function powerDown() | |
419 | turtle.select(7) | |
420 | while turtle.placeDown()==false and turtle.getItemCount(7)>0 do | |
421 | turtle.digDown() | |
422 | sleep(settings["digDelay"]) | |
423 | turtle.attackDown() | |
424 | sleep(0.1) | |
425 | end | |
426 | turtle.up() | |
427 | turtle.select(6) | |
428 | while turtle.placeDown()==false and turtle.getItemCount(6)>0 do | |
429 | turtle.digDown() | |
430 | sleep(settings["digDelay"]) | |
431 | turtle.attackDown() | |
432 | sleep(0.1) | |
433 | end | |
434 | turtle.up() | |
435 | turtle.select(5) | |
436 | while turtle.placeDown()==false and turtle.getItemCount(5)>0 do | |
437 | turtle.digDown() | |
438 | sleep(settings["digDelay"]) | |
439 | turtle.attackDown() | |
440 | sleep(0.1) | |
441 | end | |
442 | turtle.up() | |
443 | turtle.select(4) | |
444 | while turtle.placeDown()==false and turtle.getItemCount(4)>0 do | |
445 | turtle.digDown() | |
446 | sleep(settings["digDelay"]) | |
447 | turtle.attackDown() | |
448 | sleep(0.1) | |
449 | end | |
450 | end | |
451 | ||
452 | function checkResume() | |
453 | local file=fs.open("SnapBoxSettings","r") | |
454 | if file==nil then | |
455 | return false | |
456 | else | |
457 | file.close() | |
458 | return true | |
459 | end | |
460 | end | |
461 | ||
462 | function doNextStep() | |
463 | --is there a better way to do this? | |
464 | if nextStep=="topoff" then | |
465 | topOff() | |
466 | elseif nextStep=="chargeplacecharge" then | |
467 | placeCharge() | |
468 | setNextStep("chargewaitforrefuel") | |
469 | elseif nextStep=="chargewaitforrefuel" then | |
470 | sleep(settings["chargeTime"]) | |
471 | setNextStep("chargedigcharge") | |
472 | elseif nextStep=="chargedigcharge" then | |
473 | digCharge() | |
474 | setNextStep("placeminingwell") | |
475 | elseif nextStep=="placeminingwell" then | |
476 | placeMiningWell() | |
477 | setNextStep("placechest") | |
478 | elseif nextStep=="placechest" then | |
479 | placeChest() | |
480 | setNextStep("powerdown") | |
481 | elseif nextStep=="powerdown" then | |
482 | powerDown() | |
483 | setNextStep("powerup") | |
484 | sleep(settings["miningTime"]) | |
485 | elseif nextStep=="powerup" then | |
486 | powerUp() | |
487 | setNextStep("digchest") | |
488 | elseif nextStep=="digchest" then | |
489 | digChest() | |
490 | setNextStep("digminingwell") | |
491 | elseif nextStep=="digminingwell" then | |
492 | digMiningWell() | |
493 | setNextStep("moveforward") | |
494 | elseif nextStep=="moveforward" then | |
495 | moveForward() | |
496 | setNextStep("topoff") | |
497 | else | |
498 | print("Unknown Step - Something Went Wrong. Giving Up "..nextStep) | |
499 | return | |
500 | end | |
501 | end | |
502 | ||
503 | function getNextStep() | |
504 | local file=fs.open("SnapBoxStepTracker","r") | |
505 | if file==nil then | |
506 | setNextStep("topoff") | |
507 | else | |
508 | local returnValue=file.readAll() | |
509 | file.close() | |
510 | setNextStep(returnValue) | |
511 | end | |
512 | end | |
513 | ||
514 | function clearScreen() | |
515 | term.clear() | |
516 | term.setCursorPos(1,1) | |
517 | end | |
518 | ||
519 | --------MAIN PROGRAM | |
520 | clearScreen() | |
521 | ||
522 | --Check for a resume | |
523 | if checkResume()==false then | |
524 | --check to make sure it has all the items it needs | |
525 | checkStatus() | |
526 | ||
527 | --initial refuel | |
528 | turtle.select(16) | |
529 | turtle.refuel() | |
530 | turtle.select(1) | |
531 | nextStep="topoff" | |
532 | saveSettings() | |
533 | else | |
534 | print("Resuming") | |
535 | loadSettings() | |
536 | getNextStep() | |
537 | cleanUp() | |
538 | if settings["debug"]==true then | |
539 | fs.delete("SnapBoxSettings") | |
540 | fs.delete("SnapBoxStepTracker") | |
541 | return | |
542 | end | |
543 | end | |
544 | ||
545 | --main loop | |
546 | while stop==false do | |
547 | doNextStep() | |
548 | saveSettings() | |
549 | sleep(0.2) | |
550 | end |