CoderJohn

Turtle Branch Miner

Nov 13th, 2012
1,161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.60 KB | None | 0 0
  1. local prgm_args = {...};
  2. if(prgm_args[1] == 'usage' or prgm_args[1] == '?' or prgm_args[1] == 'help')then
  3.   print("miner <branches> <blocks between branches> <branch length>");
  4.   return true;
  5. end
  6.  
  7. local branches = tonumber(prgm_args[1]) or 5;
  8. local branch_interval = (prgm_args[2]~=nil and tonumber(prgm_args[2])+1) or 4;
  9. local branch_length = tonumber(prgm_args[3]) or 10;
  10. local trunk_length = branches*branch_interval;
  11.  
  12. local cTrunk
  13. local cBranch = 0;
  14. function dig(length)
  15.   local cLength = 0;
  16.   local bDetect, bMoved;
  17.   while(cLength < length)do
  18.     repeat turtle.dig(); os.sleep(0.1); bDetect = turtle.detect(); until bDetect == false;
  19.     bMoved = turtle.forward();
  20.     if(bMoved)then
  21.       cLength = cLength + 1;
  22.       turtle.digUp();
  23.       turtle.digDown();
  24.     end
  25.   end
  26.   while(cLength~=0)do
  27.     bMoved = turtle.back();
  28.     if(bMoved)then
  29.       cLength = cLength - 1;
  30.     end
  31.   end
  32. end
  33.  
  34. function digTrunk()
  35.   local cLength = 0;
  36.   local bDetect, bMoved;
  37.   while(cLength < trunk_length)do
  38.     repeat turtle.dig(); os.sleep(0.1); bDetect = turtle.detect(); until bDetect == false;
  39.     bMoved = turtle.forward();
  40.     if(bMoved)then
  41.       cLength = cLength + 1;
  42.       turtle.digUp();
  43.       turtle.digDown();
  44.       if(cLength%branch_interval==0)then
  45.         turtle.turnRight();
  46.         dig(branch_length);
  47.         turtle.turnLeft();
  48.         turtle.turnLeft();
  49.         dig(branch_length);
  50.         turtle.turnRight();
  51.       end
  52.     end
  53.   end
  54.   while(cLength~=0)do
  55.     bMoved = turtle.back();
  56.     if(bMoved)then
  57.       cLength = cLength - 1;
  58.     end
  59.   end
  60. end
  61.  
  62. digTrunk();
Advertisement
Add Comment
Please, Sign In to add comment