Advertisement
Guest User

Untitled

a guest
Jul 9th, 2013
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.34 KB | None | 0 0
  1. xDir = 1
  2. yDir = 0
  3. w = 0
  4. x = 0
  5. y = 0
  6. z = 0
  7. n = 1
  8.  
  9. for i=1, 65 do
  10.     turtle.digDown()
  11.     turtle.down()
  12.     z=z-1
  13. end
  14.  
  15. function dig()
  16.     while turtle.detect() do
  17.         turtle.dig()
  18.         sleep(1)
  19.     end
  20. end
  21.  
  22.  
  23. function changeDirR()
  24.     if xDir == 1 then
  25.         xDir = 0
  26.         yDir = -1
  27.     end
  28.     if xDir == -1 then
  29.         xDir = 0
  30.         yDir = 1
  31.     end
  32.     if yDir == 1 then
  33.         xDir = 1
  34.         yDir = 0
  35.     end
  36.     if yDir == -1 then
  37.         xDir = -1
  38.         yDir = 0
  39.     end
  40. end
  41.  
  42. function changePos()
  43.     if xDir == 1 then
  44.         x = x+1
  45.     end
  46.     if xDir == -1 then
  47.         x = x-1
  48.     end
  49.     if yDir == 1 then
  50.         y = y+1
  51.     end
  52.     if yDir == -1 then
  53.         y = y-1
  54.     end
  55. end
  56.  
  57.  
  58. function turn()
  59.     turtle.turnRight()
  60.     turtle.turnRight()
  61. end
  62.  
  63. function goup()
  64.     for h1=1, -z do
  65.         turtle.digup()
  66.         turtle.up()
  67.     end
  68.     unload()
  69.     charge()
  70.     returnDiggin()
  71. end
  72.  
  73. function godown()
  74.     for h2=1, -z do
  75.         turtle.digdown()
  76.         turtle.down()
  77.     end
  78.  
  79.     function gox()
  80.         for g1=1, x do
  81.             dig()
  82.             turtle.forward()
  83.         end
  84.     end
  85.  
  86.     function goy()
  87.         for g2=1, y do
  88.             dig()
  89.             turtle.forward()
  90.         end
  91.     end
  92.  
  93.     function gonegx()
  94.         for g3=1, -x do
  95.             dig()
  96.             turtle.forward()
  97.         end
  98.     end
  99.  
  100.     function gonegy()
  101.         for g4=1, -y do
  102.             dig()
  103.             turtle.forward()
  104.         end
  105.     end
  106.  
  107.     function goToCorner()
  108.         for bn=1, w do
  109.             turtle.forward()
  110.         end
  111.         turn()
  112.         routine()
  113.     end
  114.  
  115.     function routine()
  116.         while turtle.getItemCount(16) < 1 do
  117.             w = 0
  118.             for p=1, 2 do
  119.                 for u=1, n do
  120.                     while turtle.detect() do
  121.                         turtle.dig()
  122.                         sleep(1)
  123.                     end
  124.                     turtle.forward()
  125.                     changePos()
  126.                     w = w+1
  127.                     if enoughFuel() == true then
  128.                         for s=1, 12 do
  129.                             turtle.digUp()
  130.                             turtle.up()
  131.                         end
  132.                         for t=1, 12, 1 do
  133.                             turtle.digDown()
  134.                             turtle.down()
  135.                         end
  136.                     else
  137.                         returnToSurface()
  138.                     end
  139.                 end
  140.                 turtle.turnRight()
  141.                 changeDirR()
  142.             end
  143.             n=n+1
  144.         end
  145.         returnToSurface()
  146.     end
  147.  
  148.  
  149.     function returntosurface()
  150.         if xdir==1 then
  151.             turtle.turnRight()
  152.             goy()
  153.             if x<=0 then
  154.                 turtle.turnLeft()
  155.                 gonegx()
  156.             else
  157.                 turtle.turnright()
  158.                 gox()
  159.                 turn()
  160.             end
  161.         end
  162.         if xdir==-1 then
  163.             turtle.turnRight()
  164.             gonegy()
  165.             if x<=0 then
  166.                 turtle.turnRight()
  167.                 gonegx()
  168.             else
  169.                 turtle.turnLeft()
  170.                 gox()
  171.                 turn()
  172.             end
  173.         end
  174.         if ydir==1 then
  175.             turtle.turnRight()
  176.             gonegx()
  177.             if y<=0 then
  178.                 turtle.turnLeft()
  179.                 gonegy()
  180.                 turtle.turnright()
  181.             else
  182.                 turtle.turnright()
  183.                 goy()
  184.                 turtle.turnleft()
  185.             end
  186.         end
  187.         if ydir==-1 then
  188.             turtle.turnRight()
  189.             gox()
  190.             if y<=0 then
  191.                 turtle.turnRight()
  192.                 gonegy()
  193.                 turtle.turnright()
  194.             else
  195.                 turtle.turnleft()
  196.                 goy()
  197.                 turtle.turnleft()
  198.             end
  199.         end
  200.         goup()
  201.     end
  202.  
  203.  
  204.     function enoughFuel()
  205.         if xDir == 1 or xDir == -1 then
  206.             if x >= 0 then
  207.                 if turtle.getFuelLevel() > x+y-z+30 then
  208.                     return 1
  209.                 end
  210.             end
  211.             if x < 0 then
  212.                 if turtle.getFuelLevel() > -x+y-z+30 then
  213.                     return 1
  214.                 end
  215.             end
  216.         end
  217.         if yDir == 1 or yDir == -1 then
  218.             if y >= 0 then
  219.                 if turtle.getFuelLevel() > x+y-z+30 then
  220.                     return 1
  221.                 end
  222.             end
  223.             if y < 0 then
  224.                 if turtle.getFuelLevel() > x-y-z+30 then
  225.                     return 1
  226.                 end
  227.             end
  228.         end
  229.         return nil
  230.     end
  231.  
  232.     function unload()
  233.         for q=1, 16 do
  234.             local itemCount = turtle.getItemCount(q)
  235.             if itemCount > 0 then
  236.                 turtle.select(q)
  237.                 turtle.drop()
  238.             end
  239.         end
  240.         turtle.select(1)    
  241.     end
  242.  
  243.     function returnDiggin()
  244.         godown()
  245.         if yDir ~= 0 then
  246.             if x >= 0 then
  247.                 gox()
  248.                 if y > 0 then
  249.                     turtle.turnLeft()
  250.                     goy()
  251.                 end
  252.                 if y <= 0 then
  253.                     turtle.turnRight()
  254.                     gonegy()
  255.                     turn()
  256.                 end
  257.             end
  258.             if x < 0 then
  259.                 turn()
  260.                 gonegx()
  261.                 if y >= 0 then
  262.                     turtle.turnRight()
  263.                     goy()
  264.                     turn()
  265.                 end
  266.                 if y < 0 then
  267.                     turtle.turnLeft()
  268.                     gonegy()
  269.                 end
  270.             end
  271.         end
  272.         if xDir ~= 0 then
  273.             if y >= 0 then
  274.                 turtle.turnLeft()
  275.                 goy()
  276.                 if x >= 0 then
  277.                     turtle.turnRight()
  278.                     gox()
  279.                     turn()
  280.                 end
  281.                 if x < 0 then
  282.                     turtle.turnLeft()
  283.                     gonegx()
  284.                 end
  285.             end
  286.             if y < 0 then
  287.                 turtle.turnRigt()
  288.                 gonegy()
  289.                 if x > 0 then
  290.                     turtle.turnLeft()
  291.                     gox()
  292.                 end
  293.                 if x < 0 then
  294.                     turtle.turnRight()
  295.                     gonegx()
  296.                 end
  297.                 turn()
  298.             end
  299.         end
  300.     end
  301.     goToCorner()
  302. end
  303.  
  304.  
  305. function charge()
  306.     print ("Out of Fuel!")
  307. end
  308.  
  309. routine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement