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