Advertisement
Savage_Me55iah

Untitled

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