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