Advertisement
BasketMC

ComputerCraft: Quarry

Nov 29th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. local iRight = 0
  2. local iForward = 0
  3. local iDepth = 0
  4.  
  5. local bFacingForward = true
  6.  
  7. local iTorches = 16
  8.  
  9. write("How far Forward should I go?")
  10.  
  11. local iForwardTarget = read("*")
  12. iForwardTarget = iForwardTarget + 0;
  13.  
  14. write("How far Right should I go?")
  15.  
  16. local iRightTarget = read("*")
  17. iRightTarget = iRightTarget + 0;
  18.  
  19. write("How far Down should I go?")
  20.  
  21. local iDepthTarget = read("*")
  22. iDepthTarget = iDepthTarget + 0;
  23.  
  24. function returnToProcessPoint(iForward, iRight, iDepth, bFacingForward)
  25.  
  26.     print("Returning to Position")
  27.  
  28.     if iForward > 0 then
  29.         for i = 1, iForward, 1 do
  30.             while not turtle.forward() do
  31.                 turtle.attack()
  32.             end
  33.         end
  34.     end
  35.  
  36.     if iRight > 0 then
  37.         turtle.turnRight()
  38.         for i = 1, iRight, 1 do
  39.             while turtle.detect() do
  40.                 turtle.dig()
  41.             end
  42.             while not turtle.forward() do
  43.                 turtle.attack()
  44.             end
  45.         end
  46.         turtle.turnLeft()
  47.     end
  48.  
  49.     if iDepth > 0 then
  50.         for i = 2, iDepth, 1 do
  51.             turtle.digDown()
  52.             while not turtle.down() do
  53.                 turtle.attackDown()
  54.             end
  55.         end
  56.     end
  57.    
  58. end
  59.  
  60. function returnHome(iForward, iRight, iDepth, bFacingForward)
  61.  
  62.     print("Returning Home")
  63.  
  64.     if bFacingForward then
  65.         turtle.turnRight()
  66.         turtle.turnRight()
  67.     end
  68.  
  69.     if iDepth > 1 then
  70.         for i = 2, iDepth, 1 do
  71.             while not turtle.up() do
  72.                 turtle.attackUp()
  73.             end
  74.         end
  75.     end
  76.  
  77.     if iRight > 0 then
  78.         turtle.turnRight()
  79.         for i = 1, iRight, 1 do
  80.             while not turtle.forward() do
  81.                 turtle.attack()
  82.             end
  83.         end
  84.         turtle.turnLeft()
  85.     end
  86.  
  87.     for i = 1, iForward, 1 do
  88.         while turtle.detect() do
  89.             turtle.dig()
  90.         end
  91.         while not turtle.forward() do
  92.             turtle.attack()
  93.         end
  94.     end
  95.  
  96. end
  97.  
  98. while true do
  99.  
  100.     -- Return to where you left off
  101.     returnToProcessPoint(iForward, iRight, iDepth, bFacingForward)
  102.    
  103.     while true do
  104.    
  105.         turtle.select(1)
  106.            
  107.         if iDepth > 0 then
  108.             turtle.digDown()
  109.         end
  110.    
  111.         -- Do the Digging
  112.         for i = 2, iForwardTarget, 1 do
  113.                
  114.             if iDepth > 0 then
  115.            
  116.                 -- Grab a torch in front
  117.                 while turtle.detect() do
  118.                     turtle.select(iTorches)
  119.                     turtle.dig()
  120.                 end
  121.                
  122.                 while not turtle.forward() do
  123.                     turtle.attack()
  124.                 end
  125.                
  126.                 if bFacingForward then
  127.                     iForward = iForward + 1
  128.                 else
  129.                     iForward = iForward - 1
  130.                 end
  131.                
  132.                 turtle.digDown()
  133.    
  134.                 -- Place torch
  135.                 if iDepth > 0 and math.fmod(iForward, 4) == 1 and math.fmod(iRight, 4) == 1 then
  136.                     turtle.select(iTorches)
  137.                     turtle.placeDown()
  138.                 end
  139.             else
  140.                 while turtle.detect() do
  141.                     turtle.dig()
  142.                 end
  143.            
  144.                 while not turtle.forward() do
  145.                     turtle.attack()
  146.                 end
  147.                 if bFacingForward then
  148.                     iForward = iForward + 1
  149.                 else
  150.                     iForward = iForward - 1
  151.                 end
  152.                
  153.             end
  154.            
  155.         end
  156.    
  157.         if turtle.getItemCount(15) == 0 then
  158.        
  159.             iRight = iRight + 1
  160.  
  161.             if iRight == iRightTarget then
  162.                 print("You're at the most right column")
  163.                 iRight = iRight - 1
  164.                 break
  165.             end
  166.        
  167.             if bFacingForward then
  168.                 turtle.turnRight()
  169.                 if iDepth == 0 then
  170.                     while turtle.detect() do
  171.                         turtle.dig()
  172.                     end
  173.                 end
  174.                
  175.                 turtle.forward()
  176.                 turtle.turnRight()
  177.                
  178.             else
  179.                 turtle.turnLeft()
  180.                 if iDepth == 0 then
  181.                     while turtle.detect() do
  182.                         turtle.dig()
  183.                     end
  184.                 end
  185.                
  186.                 turtle.forward()
  187.                 turtle.turnLeft()
  188.                
  189.            
  190.             end
  191.  
  192.             bFacingForward = not bFacingForward;
  193.        
  194.         else
  195.            
  196.             print("Your inventory is full")
  197.             break
  198.        
  199.         end
  200.        
  201.     end
  202.  
  203.     -- Return back 
  204.     returnHome(iForward, iRight, iDepth, bFacingForward)
  205.  
  206.     -- Empty Inventory
  207.     for sel = 1, 15 do
  208.         turtle.select(sel)
  209.         turtle.drop()
  210.     end
  211.  
  212.     -- Reset Direction
  213.     turtle.turnRight()
  214.     turtle.turnRight()
  215.    
  216.     iForward = 0
  217.  
  218.     iRight = iRight + 1
  219.    
  220.     bFacingForward = true
  221.  
  222.     if iRight == iRightTarget then
  223.         iDepth = iDepth + 1
  224.         iRight = 0
  225.     end
  226.  
  227.     if iDepth == iDepthTarget then
  228.         return
  229.     end
  230.  
  231. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement