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