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