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