View difference between Paste ID: 4Pt89ZV3 and f6jiuatN
SHOW: | | - or go back to the newest paste.
1
x = 30
2
y = 30
3
z = -40
4
a = 1000
5
cx = 1
6
cy = -1
7
cz = 0
8
ca = 1000
9
xb = x - 1
10
yb = y - 1
11
turtle = 1
12
total_turtles = 2
13
xc = xb - total_turtles
14
store_x = -1
15
store_y = -2
16
store_z = turtle + 2
17
cobble = 1
18
filter = 14
19
chest = 15
20
cobble2 = 16
21
ox = cx
22
oy = cy
23
oz = cz
24
 
25
--functions
26
27
28
function co()
29
  print(" x " .. cx .. " y " .. cy .. " z " .. cz .. " Angled at " .. ca)
30
end
31
32
function bull_up()
33
  if (turtle.detectUp() == false) then
34
    turtle.up()
35
  else
36
    repeat
37
      turtle.digUp()
38
      sleep(0.5)
39
    until turtle.detectUp() == false
40
    turtle.up()
41
  end
42
end
43
44
function bull_down()
45
  if (turtle.detectDown() == false) then
46
    turtle.down()
47
  else
48
    repeat
49
      turtle.digDown()
50
      sleep(0.5)
51
    until turtle.detectDown() == false
52
    turtle.down()
53
  end
54
end
55
56
function a_in()
57
  ca = ca + 90
58
  co()
59
end
60
 
61
function a_de()
62
  ca = ca - 90
63
  co()
64
end
65
 
66
function tl()
67
  turtle.turnLeft()
68
  a_in()
69
end
70
 
71
function tr()
72
  turtle.turnRight()
73
  a_de()
74
end
75
 
76
function t_180l()
77
  tl()
78
  tl()
79
end
80
 
81
function t_180r()
82
  tr()
83
  tr()
84
end
85
 
86
function x_in()
87
  cx = cx + 1
88
  co()
89
end
90
 
91
function x_de()
92
  cx = cx - 1
93
  co()
94
end
95
 
96
function y_in()
97
  cy = cy + 1
98
  co()
99
end
100
 
101
function y_de()
102
  cy = cy - 1
103
  co()
104
end
105
 
106
function z_in()
107
  cz = cz + 1
108
  co()
109
end
110
 
111
function z_de()
112
  cz = cz - 1
113
  co()
114
end
115
116
--  SAVING POSITION
117
 
118
function save()
119
  xsave = cx
120
  ysave = cy
121
  zsave = cz
122
  asave = ca
123
  print("saving ")
124
  co()
125
end
126
127
--  REALIGNING AND LOCATING
128
129
function realign_p()
130
  print("realigning")
131
end
132
 
133
function realign_0()
134
  realign_p()
135
  if ca == a == false then
136
    while (ca > a) do
137
      tr()
138
    end
139
    while (ca < a) do
140
      tl()
141
    end
142
  end
143
end
144
145
function calibrate_x()
146
  realign_0()
147
  tr()
148
  if (turtle.detect() == false) then
149
  repeat
150
    turtle.forward()
151
  until turtle.detect() == true
152
  tl()
153
  cx = 1
154
end
155
156
function calibrate_y()
157
  realign_0()
158
  t_180l()
159
  if (turtle.detect() == false) then
160
  repeat
161
    turtle.forward()
162
  until turtle.detect() == true
163
  t_180l()
164
  cy = 1
165
end
166
167
function calibrate_z()
168
  realign_0()
169
  if (turtle.detectUp() == false) then
170
  repeat
171
    turtle.up()
172
  until turtle.detectUp() == true
173
  cz = 1
174
end
175
176
function calibrate()
177
  calibrate_z()
178
  calibrate_x()
179
  calibrate_y()
180
end
181
182
function locate_store_z()
183
  if cz == store_z == false then
184
    while (cz < store_z) do
185
      turtle.up()
186
      z_in()
187
    end
188
    while (cz > store_z) do
189
      turtle.down()
190
      z_de()
191
    end
192
  end
193
end
194
195
function locate_store_x()
196
  while cx == store_x == false do
197
    if cx > store_x then
198
      tr()
199
      repeat
200
        turtle.forward()
201
        x_de()
202
      until cx == store_x
203
      tl()
204
    else
205
      tl()
206
      repeat
207
        turtle.forward()
208
        x_in()
209
      until cx == store_x
210
      tr()
211
    end
212
  end
213
end
214
215
function locate_store_y()
216
  while cy == store_y == false do
217
    if cy > store_y then
218
      t_180l()
219
      repeat
220
        turtle.forward()
221
        y_de()
222
      until cy == store_y
223
      t_180r()
224
    else
225
      repeat
226
        turtle.forward()
227
        y_in()
228
      until cy == store_y
229
    end
230
  end
231
end
232
233
function return_xsave()
234
  while cx == xsave == false do
235
    if cx > xsave then
236
      tr()
237
      repeat
238
        turtle.forward()
239
        x_de()
240
      until cx == xsave
241
      tl()
242
    else
243
      tl()
244
      repeat
245
        turtle.forward()
246
        x_in()
247
      until cx == xsave
248
      tr()
249
    end
250
  end
251
end
252
253
function return_ysave()
254
  while cy == ysave == false do
255
    if cy > ysave then
256
      t_180l()
257
      repeat
258
        turtle.forward()
259
        y_de()
260
      until cy == ysave
261
      t_180r()
262
    else
263
      repeat
264
        turtle.forward()
265
        y_in()
266
      until cy == ysave
267
    end
268
  end
269
end
270
271
function return_zsave()
272
  if cz == zsave == false then
273
    while (cz < zsave) do
274
      turtle.up()
275
      z_in()
276
    end
277
    while (cz > zsave) do
278
      turtle.down()
279
      z_de()
280
    end
281
  end
282
end
283
284
function return_ox()
285
  while cx == ox == false do
286
    if cx > ox then
287
      tr()
288
      repeat
289
        turtle.forward()
290
        x_de()
291
      until cx == ox
292
      tl()
293
    else
294
      tl()
295
      repeat
296
        turtle.forward()
297
        x_in()
298
      until cx == ox
299
      tr()
300
    end
301
  end
302
end
303
304
function return_oy()
305
  while cy == oy == false do
306
    if cy > oy then
307
      t_180l()
308
      repeat
309
        turtle.forward()
310
        y_de()
311
      until cy == oy
312
      t_180r()
313
    else
314
      repeat
315
        turtle.forward()
316
        y_in()
317
      until cy == oy
318
    end
319
  end
320
end
321
322
function return_oz()
323
  if cz == oz == false then
324
    while (cz < oz) do
325
      turtle.up()
326
      z_in()
327
    end
328
    while (cz > oz) do
329
      turtle.down()
330
      z_de()
331
    end
332
  end
333
end
334
335
336
--  PLACING
337
338
function place_cobble_up()
339
  if (turtle.getItemCount(cobble) == 1) then
340
    cobble = cobble + 1
341
  end
342
  turtle.select(cobble)
343
  turtle.placeUp()
344
  turtle.select(1)
345
end
346
347
function place_cobble_down()
348
  if (turtle.getItemCount(cobble) == 1) then
349
    cobble = cobble + 1
350
  end
351
  turtle.select(cobble)
352
  turtle.placeDown()
353
  turtle.select(1)
354
end
355
356
function place_cobble()
357
  if (turtle.getItemCount(cobble) == 1) then
358
    cobble = cobble + 1
359
  end
360
  turtle.select(cobble)
361
  turtle.place()
362
  turtle.select(1)
363
end
364
365
function place_chest()
366
  turtle.select(chest)
367
  turtle.place()
368
  tr()
369
  turtle.forward()
370
  turtle.forward()
371
  tl()
372
  turtle.forward()
373
  tl()
374
  turtle.select(filter)
375
  turtle.place()
376
  tl()
377
  turtle.forward()
378
  tr()
379
  turtle.forward()
380
  turtle.forward()
381
  tr()
382
  turtle.select(1)
383
end
384
385
function locate_store()
386
  save()
387
  realign_0()
388
  turtle.digUp()
389
  turtle.up()
390
  z_in()
391
  turtle.up()
392
  z_in()
393
  place_cobble_down()
394
  zsave = cz
395
  locate_store_z()
396
  locate_store_x()
397
  locate_store_y()
398
  realign_0()
399
  t_180l()
400
end
401
402
function return_all()
403
  realign_0()
404
  return_ysave()
405
  return_xsave()
406
  return_zsave()
407
  turtle.digDown()
408
  turtle.down()
409
  z_de()
410
  turtle.down()
411
  z_de()
412
  place_cobble_up()
413
  realign_0()
414
end
415
416
function storing_setup()
417
  locate_store()
418
  place_chest()
419
  turtlechest = 1
420
  repeat
421
    turtle.up()
422
    z_in()
423
    place_chest()
424
    turtlechest = turtlechest + 1
425
  until turtlechest == total_turtles
426
  realign_0()
427
  return_all()
428
end
429
430
function storing()
431
  print("storing")
432
  save()
433
  locate_store()
434
  for num=1,16 do
435
    turtle.select(num)
436
    turtle.drop(64)
437
    sleep(1)
438
  end
439
  turtle.select(1)
440
  print("storing complete")
441
  return_all()
442
end
443
444
function storing_end()
445
  print("ending")
446
  save()
447
  locate_store()
448
  for num=1,16 do
449
    turtle.select(num)
450
    turtle.drop(64)
451
    sleep(1)
452
  end
453
  turtle.select(1)
454
  realign_0()
455
  print("program complete")
456
end
457
458
459
-- MAIN FUNCTIONS
460
461
function realign_place_up()
462
  if (turtle.detectUp() == false) then
463
    place_cobble_up()
464
  end
465
end
466
467
function realign_place()
468
  if (turtle.detect() == false) then
469
    place_cobble()
470
  end
471
end
472
 
473
function realign_pad_rhs()
474
  realign_place_up()
475
  tr()
476
  realign_place()
477
  tl()
478
end
479
480
function realign_pad_lhs()
481
  tl()
482
  realign_place()
483
  tr()
484
end
485
486
function realign_pad_a()
487
  repeat
488
    realign_pad_rhs()
489
    turtle.forward()
490
    y_in()
491
  until cy == y
492
  tl()
493
end
494
495
function realign_pad_b()
496
  repeat
497
    realign_pad_rhs()
498
    turtle.forward()
499
    x_in()
500
  until cx == x
501
  tl()
502
end
503
504
function realign_pad_c()
505
  repeat
506
    realign_pad_rhs()
507
    turtle.forward()
508
    y_de()
509
  until cy == 1
510
  tl()
511
end
512
  
513
function realign_pad_d()
514
  repeat
515
    realign_pad_rhs()
516
    turtle.forward()
517
    x_de()
518
  until cx == 1
519
  tl()
520
end
521
522
function middle_pad_pos()
523
  turtle.forward()
524
  y_in()
525
  tl()
526
  turtle.forward()
527
  x_in()
528
  tr()
529
end
530
531
function middle_pad_a()
532
  repeat
533
    realign_place_up()
534
    turtle.forward()
535
    y_in()
536
  until cy == yb
537
  t_180l()
538
  repeat
539
    turtle.forward()
540
    y_de()
541
  until cy == 2
542
  t_180l()
543
end
544
545
function mid_pad()
546
  middle_pad_pos()
547
  repeat
548
    middle_pad_a()
549
    tl()
550
    turtle.forward()
551
    tr()
552
    x_in()
553
  until cx == x
554
end
555
556
function align_pad()
557
  turtle.forward()
558
  y_in()
559
  turtle.forward()
560
  y_in()
561
  turtle.up()
562
  z_in()
563
  realign_pad_a()
564
  realign_pad_b()
565
  realign_pad_c()
566
  realign_pad_d()
567
  mid_pad()
568
  calibrate()
569
  storing_setup()
570
  turtle.down()
571
  z_de()
572
  tl()
573
  turtle_block = 1
574
  repeat
575
    turtle.forward()
576
    x_in()
577
    realign_pad_lhs()
578
    turtle_block = turtle_block + 1
579
  until turtle_block == total_turtles
580
  t_180l()
581
  repeat
582
    turtle.forward()
583
    x_de()
584
  until cx == 1
585
  realign_0()
586
  t_180l()
587
  turtle.forward()
588
  y_de()
589
  turtle.forward()
590
  y_de()
591
  t_180()
592
  realign_place()
593
end
594
595
function start()
596
  if turtle == 1 then
597
    align_pad()
598
  else
599
    repeat
600
      sleep(0.5)
601
    until turtle.detect() == true
602
    repeat
603
      sleep(0.5)
604
    until turtle.detect() == false
605
  end
606-
  if turtle == total_turtles then
606+
  if (turtle == total_turtles) then
607-
    return_oz
607+
    return_oz()
608
    repeat
609
      tl()
610
      turtle.dig()
611
      tr()
612
      turtle.forward()
613
      x_in()
614
    until cx == total_turtles
615
    return_oy()
616
    realign_0()
617
    sleep(5)
618
  else
619-
    return_oz
619+
    return_oz()
620-
    return_ox
620+
    return_ox()
621-
    return_oy
621+
622
    realign_0()
623
    turtle.forward()
624
    y_in()
625
    tl()
626
    turtle.dig()
627
    tl()
628
    turtle.forward()
629
    y_de()
630
    realign_0()
631
    realign_place()
632
    repeat
633
      sleep(0.5)
634
    until turtle.detect() == false
635
  end
636
end
637
638
function dig_pos()
639
  repeat
640
    turtle.forward()
641
    y_in()
642
  until cy == 1
643
  calibrate_z()
644
end
645
646
function digging()
647
  realign_0()
648
  repeat
649
    bull_down()
650
    z_de()
651
  until cz == z
652
  calibrate_z()
653
end
654
655
function strip()
656
  if (turtle.detect() == false) then
657
    repeat
658
      turtle.forward()
659
      y_in()
660
      digging()
661
      storing()
662
    until turtle.detect() == true
663
  else
664
    calibrate_y()
665
  end
666
end
667
  
668
function next_row()
669
  return_oz()
670
  return_oy()
671
  locate_store_z()
672
  tl()
673
  rep = 0
674
  repeat
675
    turtle.forward()
676
    x_in()
677
  until rep == total_turtles
678
  turtle.down()
679
  z_de()
680
  turtle.down()
681
  z_de()
682
  realign_0()
683
end
684
685
function quarry()
686
  repeat
687
    dig_pos()
688
    strip()
689
    next_row()
690
  until cx > xc
691
  dig_pos()
692
  strip()
693
  storing_end()
694
end
695
696
start()
697
quarry()