View difference between Paste ID: znsEcnH3 and cdWXhj5x
SHOW: | | - or go back to the newest paste.
1-
x = 5
1+
x = 21
2-
y = 5
2+
y = 15
3-
z = -10
3+
z = -25
4
a = 1000
5
cy = -1
6
cz = 0
7
ca = 1000
8
xb = x - 1
9
yb = y - 1
10-
turtle_num = 2
10+
turtle_num = 1
11
total_turtles = 2
12
xc = xb - total_turtles
13-
store_x = -1
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()
411+
412
  return_oy()
413
  locate_store_z()
414
  locate_store_x()
415
  locate_store_y()
416-
  place_cobble_down()
416+
417
  t_180l()
418
end
419
 
420
function return_all()
421
  realign_0()
422
  return_oy()
423
  return_xsave()
424
  return_oz()
425
  return_ysave()
426
  calibrate_z()
427
  realign_0()
428
end
429-
  return_zsave()
429+
430-
  turtle.digDown()
430+
431
  locate_store()
432
  place_chest()
433
  turtlechest = 1
434
  repeat
435-
  place_cobble_up()
435+
436
    z_in()
437
    place_chest()
438
    turtlechest = turtlechest + 1
439
  until turtlechest == total_turtles
440
  realign_0()
441
  return_all()
442
end
443
 
444
function storing()
445
  print("storing")
446
  save()
447
  locate_store()
448
  for num=1,15 do
449
    turtle.select(num)
450
    turtle.drop(64)
451
    sleep(1)
452
  end
453
  turtle.select(1)
454
  print("storing complete")
455
  return_all()
456
end
457
 
458
function storing_end()
459
  print("ending")
460
  save()
461
  locate_store()
462
  for num=1,15 do
463
    turtle.select(num)
464
    turtle.drop(64)
465
    sleep(1)
466
  end
467
  turtle.select(1)
468
  realign_0()
469
  print("program complete")
470
end
471
 
472
 
473
-- MAIN FUNCTIONS
474
 
475
function realign_place_up()
476
  if (turtle.detectUp() == false) then
477
    place_cobble_up()
478
  end
479
end
480
 
481
function realign_place()
482
  if (turtle.detect() == false) then
483
    place_cobble()
484
  end
485
end
486
 
487
function realign_pad_rhs()
488
  realign_place_up()
489
  tr()
490
  realign_place()
491
  tl()
492
end
493
 
494
function realign_pad_lhs()
495
  tl()
496
  realign_place()
497
  tr()
498
end
499
 
500
function realign_pad_a()
501
  repeat
502
    realign_pad_rhs()
503
    turtle.forward()
504
    y_in()
505
  until cy == y
506
  realign_pad_rhs()
507
  realign_place() 
508
  tl()
509
end
510
 
511
function realign_pad_b()
512
  repeat
513
    realign_pad_rhs()
514
    turtle.forward()
515
    x_in()
516
  until cx == x
517
  realign_pad_rhs()
518
  realign_place()
519
  tl()
520
end
521
 
522
function realign_pad_c()
523
  repeat
524
    realign_pad_rhs()
525
    turtle.forward()
526
    y_de()
527
  until cy == 1
528
  realign_pad_rhs()
529
  realign_place()
530
  tl()
531
end
532
 
533
function realign_pad_d()
534
  repeat
535
    realign_pad_rhs()
536
    turtle.forward()
537
    x_de()
538
  until cx == 1
539
  realign_pad_rhs()
540
  realign_place()
541
  tl()
542
end
543
 
544
function middle_pad_pos()
545
  turtle.forward()
546
  y_in()
547
  tl()
548
  turtle.forward()
549
  x_in()
550
  tr()
551
end
552
 
553
function middle_pad_a()
554
  repeat
555
    realign_place_up()
556
    turtle.forward()
557
    y_in()
558
  until cy == yb
559
  realign_place_up()
560
  t_180l()
561
  repeat
562
    turtle.forward()
563
    y_de()
564
  until cy == 2
565
  t_180l()
566
end
567
 
568
function mid_pad()
569
  middle_pad_pos()
570
  repeat
571
    middle_pad_a()
572
    tl()
573
    turtle.forward()
574
    tr()
575
    x_in()
576
  until cx == x
577
end
578
 
579
function align_pad()
580
  turtle.forward()
581
  y_in()
582
  turtle.forward()
583
  y_in()
584
  turtle.up()
585
  z_in()
586
  realign_pad_a()
587
  realign_pad_b()
588
  realign_pad_c()
589
  realign_pad_d()
590
  mid_pad()
591
  calibrate()
592
  storing_setup()
593
  turtle.down()
594
  z_de()
595
  tl()
596
  turtle_block = 1
597
  repeat
598
    turtle.forward()
599
    x_in()
600
    realign_pad_lhs()
601
    turtle_block = turtle_block + 1
602
  until turtle_block == total_turtles
603
  t_180l()
604
  repeat
605
    turtle.forward()
606
    x_de()
607
  until cx == 1
608
  realign_0()
609
  t_180l()
610
  turtle.forward()
611
  y_de()
612
  turtle.forward()
613
  y_de()
614
  t_180l()
615
end
616
617
 
618
function start()
619
  if turtle_num == 1 then
620
    align_pad()
621
  sleep(2)
622
  else
623
    repeat
624
      sleep(0.5)
625
    until turtle.detect() == true
626
    repeat
627
      sleep(0.5)
628
    until turtle.detect() == false
629
  sleep(2)
630
  turtle.forward()
631
  y_in()
632
  turtle.forward()
633
  y_in()
634
  calibrate()
635
  end
636
  if (turtle_num == total_turtles) then
637
    return_oz()
638
    repeat
639
      tl()
640
      turtle.dig()
641
      tr()
642
      turtle.forward()
643
      x_in()
644
    until cx == total_turtles
645
    return_oy()
646
    realign_0()
647
    sleep(5)
648
  else
649
    return_oz()
650
    return_ox()
651
    return_oy()
652
    realign_0()
653
    sleep(2)
654
    turtle.forward()
655
    y_in()
656
    tl()
657
    turtle.dig()
658
    tl()
659
    turtle.forward()
660
    y_de()
661
    realign_0()
662
    realign_place()
663
    repeat
664
      sleep(0.5)
665
   until turtle.detect() == false
666
   sleep (5)
667
  end
668
end
669
 
670
function dig_pos()
671
  repeat
672
    turtle.forward()
673
    y_in()
674
  until cy == 1
675
  calibrate_z()
676
end
677
 
678
function digging()
679
  realign_0()
680
  repeat
681
    bull_down()
682
    z_de()
683
  until cz == z
684
  calibrate_z()
685
end
686
 
687
function strip()
688
  digging()
689
  storing()
690
  if (turtle.detect() == false) then
691
    repeat
692
      turtle.forward()
693
      y_in()
694
      digging()
695
      storing()
696
    until turtle.detect() == true
697
  else
698
    calibrate_y()
699
  end
700
end
701
 
702
function next_row()
703
  return_oz()
704
  return_oy()
705
  locate_store_z()
706
  tl()
707
  rep = 0
708
  repeat
709
    turtle.forward()
710
    rep = rep + 1
711
  until rep == total_turtles
712
  return_oz()
713
  realign_0()
714
end
715
 
716
function quarry()
717
  repeat
718
    dig_pos()
719
    strip()
720
    next_row()
721
  until cx > xc
722
  dig_pos()
723
  strip()
724
  storing_end()
725
end
726
 
727
--start()
728
quarry()