MmPMSFmM

branch

Aug 10th, 2013
790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. --According to Benjamin Buford "Bubba" Blue I should make notes.
  2.  
  3. -- aLenght is the Actual length of the branch mine. length is an argument. done indicates whether or not the branch mine is finished
  4. local arg = { ... }
  5. local length = tonumber(arg[1])
  6. local aLength = 0
  7. local nBranch = 0
  8.  
  9. --Checks if the arguments are valid.
  10. if length == nil then
  11.     print [[Please only use numbers.
  12. Usage: branch <length>]]
  13.     return false
  14. elseif length < 1 then
  15.     print [[Please only use positive numbers.
  16. Usage: branch <length>]]
  17.     return false
  18. end
  19.  
  20. --Source for function refuel(): tunnel, a standard CC mining turtle program. All credit goes to the original author.
  21. --It refuels :O
  22. local function refuel()
  23.     local fuelLevel = turtle.getFuelLevel()
  24.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  25.         return
  26.     end
  27.     local function tryRefuel()
  28.         for n=1,16 do
  29.             if turtle.getItemCount(n) > 0 then
  30.                 turtle.select(n)
  31.                 if turtle.refuel(1) then
  32.                     turtle.select(1)
  33.                     return true
  34.                 end
  35.             end
  36.         end
  37.         turtle.select(1)
  38.         return false
  39.     end
  40.    
  41.     if not tryRefuel() then
  42.         print( "Add more fuel to continue." )
  43.         while not tryRefuel() do
  44.             sleep(1)
  45.         end
  46.         print( "Resuming Tunnel." )
  47.     end
  48. end
  49.  
  50. --Digs forward.
  51. local function frontDig()
  52.     while turtle.detect() do
  53.         turtle.dig()
  54.         sleep(0.25)
  55.     end
  56. end
  57.  
  58. --Digs up.
  59. local function upDig()
  60.     while turtle.detectUp() do
  61.         turtle.digUp()
  62.         sleep(0.25)
  63.     end
  64. end
  65.  
  66. --Digs down.
  67. local function downDig()
  68.     while turtle.detectDown() do
  69.         turtle.digDown()
  70.         sleep(0.25)
  71.     end
  72. end
  73.  
  74. --Goes forward.
  75. local function frontGo()
  76.     refuel()
  77.     frontDig()
  78.     while turtle.attack() do
  79.         turtle.attack()
  80.         sleep(0.25)
  81.     end
  82.     turtle.forward()
  83. end
  84.  
  85. --Goes up.
  86. local function upGo()
  87.     refuel()
  88.     upDig()
  89.     while turtle.attackUp() do
  90.         turtle.attackUp()
  91.         sleep(0.25)
  92.     end
  93.     turtle.up()
  94. end
  95.  
  96. --Goes down.
  97. local function downGo()
  98.     refuel()
  99.     downDig()
  100.     while turtle.attackDown() do
  101.         turtle.attackDown()
  102.         sleep(0.25)
  103.     end
  104.     turtle.down()
  105. end
  106.  
  107. --Makes trunk.
  108. local function trunkMine()
  109.     upDig()
  110.     turtle.turnLeft()
  111.     frontDig()
  112.     upGo()
  113.     frontDig()
  114.     downGo()
  115.     turtle.turnRight()
  116.     aLength = aLength + 1
  117.     if aLength % 25 == 0 then
  118.         print( "The branch mine is now " , aLength , " blocks long." )
  119.     end
  120. end
  121.  
  122. --Makes branch.
  123. local function branchMine()
  124.  
  125.     local function branch()
  126.         for n=1,5 do
  127.             frontGo()
  128.             upDig()
  129.         end
  130.     end
  131.    
  132.     local function move()
  133.         turtle.turnLeft()
  134.         turtle.turnLeft()
  135.         for n=1,6 do
  136.             frontGo()
  137.             upDig()
  138.         end
  139.     end
  140.    
  141.     turtle.turnRight()
  142.     branch()
  143.     move()
  144.     branch()
  145.     move()
  146.     turtle.turnLeft()
  147. end
  148.  
  149. --Mines the eventual branch mine.
  150. local function treeMine()
  151.     for n=1,3 do
  152.         trunkMine()
  153.         if aLength == length then
  154.             print( [[Finished branch mine.
  155. The branch mine is ]], aLength, " blocks long." )
  156.             return true
  157.         elseif n ~= 3 then
  158.             frontGo()
  159.         end
  160.     end
  161.     branchMine()
  162.     frontGo()
  163. end
  164.  
  165. print( "Mining ", length, " blocks long branch mine." )
  166.  
  167. --Makes branch mine until desired length is achieved.
  168. while aLength < length do
  169.     treeMine()
  170. end
Advertisement
Add Comment
Please, Sign In to add comment