Advertisement
Redhunter_94

Fast 3x3 turtle tunneling script

Dec 12th, 2013
1,821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 3x3 Tunnel digger script for ComputerCraft turtle by Scott 'Satscape' Hather - www.satscape.info
  2. -- Place the turtle at the center bottom of where you want the 3x3 tunnel(and facing it)
  3. -- Place a chest directly left next to it
  4. -- Place torches in the bottom right slot
  5. -- Place coal/lava etc in any other slots
  6. -- It will empty itself into the chest at regular intervals and place torches on the tunnel walls!
  7. -- run "tunnel" on it's own to dig a 3x3x512 tunnel or "tunnel 20" to dig 3x3x20 tunnel.
  8.  
  9. local ident="miner1"
  10. -- rednet.open("right")
  11.  
  12. -- grab fuel from all slots
  13. function grabFuel()
  14.  for i=1,15 do
  15.   turtle.select(i)
  16.   turtle.refuel()
  17.  end
  18. end
  19.  
  20. grabFuel();
  21.  
  22. if turtle.getItemCount(16) == 0 then
  23.     print("NO torches in the last slot");
  24.     print("Shall I continue without torches (Y/N)");
  25.     yn = read();
  26.     if yn == "Y" then
  27.         -- Do Nothing
  28.     else
  29.         return
  30.     end
  31. end
  32.  
  33. distanceFromChest=0;
  34. distanceWere=0;
  35.  
  36. function digAndMove()
  37.     while (turtle.detect()) do
  38.         turtle.dig(); os.sleep(0.5);
  39.     end
  40.     turtle.forward();
  41. end
  42.  
  43. function digSafeUp()
  44.     while (turtle.detectUp()) do
  45.         turtle.digUp(); os.sleep(0.5);
  46.     end
  47. end
  48.  
  49. function digAndMoveDown()
  50.     while (turtle.detectDown()) do
  51.         turtle.digDown(); os.sleep(0.5);
  52.     end
  53.     turtle.down()
  54. end
  55.  
  56. args={...}
  57. tunlen=args[1]
  58. if tunlen=="" then
  59.   tunlen=512
  60. end
  61.  
  62. -- go to middle right
  63. turtle.turnRight();
  64. digAndMove();
  65. digSafeUp();
  66. turtle.up()
  67. turtle.turnLeft();
  68.  
  69. while true do
  70.  if distanceFromChest >= tonumber(tunlen) then
  71.   turtle.turnLeft()
  72.   turtle.turnLeft()
  73.   for d=1,distanceFromChest do
  74.     turtle.forward()
  75.   end
  76.   turtle.turnRight()
  77.   turtle.forward()
  78.   -- rednet.broadcast(ident..": Tunnel complete.")
  79.   print("Tunnel complete.")
  80.   os.sleep(1)
  81.   return
  82.  end
  83.     if turtle.getFuelLevel() < 1500 then
  84.         grabFuel();
  85.     end
  86.     print("Diggy Diggy hole, got "..turtle.getFuelLevel().." fuel left.");
  87.     distanceFromChest=distanceFromChest + 1;
  88.     digAndMove(); -- middle Right
  89.     turtle.digDown(); -- bottom Right
  90.     digSafeUp(); -- top Right
  91.     turtle.turnLeft();
  92.     digAndMove(); -- middle centre
  93.     turtle.digDown(); -- bottom centre
  94.     digSafeUp(); -- top centre
  95.     digAndMove(); -- middle Left
  96.     turtle.digDown(); -- bottom Left
  97.     digSafeUp(); -- top Left
  98.    
  99.     if distanceFromChest % 7 == 1 then
  100.         turtle.back();
  101.         turtle.select(16);
  102.         turtle.place(); -- place the torch on the wall
  103.         turtle.back();
  104.         turtle.turnRight();
  105.     else
  106.         turtle.back();
  107.         turtle.back();
  108.         turtle.turnRight();
  109.     end
  110.    
  111.     if distanceFromChest % 32 == 0 then  -- time to empty our stuff
  112.         turtle.turnLeft();
  113.         turtle.turnLeft();
  114.         distance = distanceFromChest - 1
  115.         for i = 0, distance do
  116.             turtle.forward();
  117.         end
  118.         turtle.turnRight();
  119.         turtle.forward();
  120.         turtle.down();
  121.         os.sleep(1);
  122.         grabFuel(); -- refuel first before offloading coal etc!
  123.        
  124.         -- rednet.broadcast(ident..": Refuelled, dropped off load.")
  125.         print("Refuelled, dropped off load.")
  126.        
  127.         for slot=1, 15, 1 do
  128.             turtle.select(slot);
  129.             turtle.drop();
  130.         end
  131.         os.sleep(1);
  132.         turtle.back();
  133.         turtle.turnRight();
  134.         turtle.up();
  135.         for i = 0, distance do
  136.             turtle.forward();
  137.         end
  138.     end
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement