Advertisement
LBPHacker

Branchmine - Indented FTR Upload

Aug 5th, 2013
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.73 KB | None | 0 0
  1. --According to Benjamin Buford "Bubba" Blue I should make notes.
  2. -- aLenght is the Actual length of the branch mine. length is the desired length of the branch mine in blocks. The height is the desired height of the branch mine in 2 meter high floors. progress indicates the stage of the mining process; 1 is branch; 2 is trunk; 3 is level change.
  3. local arg1,arg2 = ...
  4. local length = tonumber(arg1)
  5. local zLength = length
  6. local height = tonumber(arg2)
  7. local aLength = 0
  8. local aHeight = 1
  9. local progress = 0
  10. --Checks if the arguments are valid.
  11. if length == nil or height == nil then
  12.     print([[ Please only use numbers.
  13.     Usage: oBranch <length> <height>]])
  14.     return false
  15. elseif length < 3 or height < 2 then
  16.     print([[ Please only use positive numbers.
  17.     This message might also have occurred because the entered numbers were too low.
  18.     Usage: oBranch <height> <height>]])
  19.     return false
  20. end
  21. --Changes valid length to match the second floors' (2nd, 4th, 6th, etc.) branches.
  22. local function lengthChange()
  23.     if length % 4 == 3 then
  24.         zLength = length
  25.         print( "The branch mine will be the desired ", length, "." )
  26.     elseif length % 4 == 2 then
  27.         zLength = length - 3
  28.         print( "I'm sorry, we have had to change the length from ", length, " to ", zLength, ". I'm sorry for the inconvenience." )
  29.     elseif length % 4 == 1 then
  30.         zLength = length - 2
  31.         print( "I'm sorry, we have had to change the length from ", length, " to ", zLength, ". I'm sorry for the inconvenience." )
  32.     else
  33.         zLength = length - 1
  34.         print( "I'm sorry, we have had to change the length from ", length, " to ", zLength, ". I'm sorry for the inconvenience." )
  35.     end
  36. end
  37. lengthChange()
  38.  
  39. --[[Source for function refuel(): tunnel, a standard CC mining turtle program. All credit goes to the original author.
  40. It refuels :o/>]]
  41. local function refuel()
  42.     local fuelLevel = turtle.getFuelLevel()
  43.         if fuelLevel == "unlimited" or fuelLevel > 0 then
  44.         return
  45.     end
  46.     local function tryRefuel()
  47.         for n=1,16 do
  48.             if turtle.getItemCount(n) > 0 then
  49.             turtle.select(n)
  50.             if turtle.refuel(1) then
  51.                 turtle.select(1)
  52.                 return true
  53.             end
  54.         end
  55.         end
  56.         turtle.select(1)
  57.         return false
  58.     end
  59.  
  60.     if not tryRefuel() then
  61.         print( "Add more fuel to continue." )
  62.         while not tryRefuel() do
  63.             sleep(1)
  64.         end
  65.         print( "Resuming Tunnel." )
  66.     end
  67. end
  68. --Digs forward.
  69. local function frontDig()
  70.     while turtle.detect() do
  71.         turtle.dig()
  72.         sleep(0.25)
  73.     end
  74. end
  75. --Digs up.
  76. local function upDig()
  77.     while turtle.detectUp() do
  78.         turtle.digUp()
  79.         sleep(0.25)
  80.     end
  81. end
  82. --Digs down.
  83. local function downDig()
  84.     while turtle.detectDown() do
  85.         turtle.digDown()
  86.         sleep(0.25)
  87.     end
  88. end
  89. --Goes forward.
  90. local function frontGo()
  91.     refuel()
  92.     frontDig()
  93.     while turtle.attackUp() do
  94.         turtle.attackUp()
  95.         sleep(0.25)
  96.     end
  97.     turtle.forward()
  98. end
  99. --Goes up.
  100. local function upGo()
  101.     refuel()
  102.     upDig()
  103.     while turtle.attackUp() do
  104.         turtle.attackUp()
  105.         sleep(0.25)
  106.     end
  107.     turtle.up()
  108. end
  109. --Goes down.
  110. local function downGo()
  111.     refuel()
  112.     downDig()
  113.     while turtle.attackDown() do
  114.         turtle.attackDown()
  115.         sleep(0.25)
  116.     end
  117.     turtle.down()
  118. end
  119. --Turns 'round.
  120. local function roundTurn()
  121.     for 1,6 do
  122.         turtle.turnLeft()
  123.     end
  124. end
  125. --Makes branchMine()
  126. local function branchMine()
  127.     --Makes branches.
  128.     local function branch()
  129.         local function stick()
  130.             for i = 1,6 do
  131.                 frontGo()
  132.                 upDig()
  133.             end
  134.         end
  135.         turtle.turnLeft()
  136.         stick()
  137.         roundTurn()
  138.         stick()
  139.         stick()
  140.         roundTurn()
  141.         stick()
  142.         turtle.turnRight()
  143.     end
  144.     --Makes the main trunk
  145.     local function trunk()
  146.         frontGo()
  147.         turtle.turnLeft()
  148.         frontDig()
  149.         upGo()
  150.         frontDig()
  151.         roundTurn()
  152.         frontDig()
  153.         downGo()
  154.         frontDig()
  155.         turtle.turnRight()
  156.         if aLength ~= zLength then
  157.             frontGo()
  158.         end
  159.     end
  160.     --Elevates to the next floor
  161.     local function level()
  162.         upGo()
  163.         upGo()
  164.         roundTurn()
  165.     end
  166.     --Decides the order of mining.
  167.     if progress == 1 then
  168.         branch()
  169.         aLength = aLength + 1
  170.         progress = progress + 1
  171.     elseif progress == 2 or progress == 3 or progress == 4 then
  172.         trunk()
  173.         aLength = aLength + 1
  174.         progress = progress + 1
  175.     elseif progress == 0 then
  176.         level()
  177.         aHeight = height + 1
  178.         progress = 1
  179.     end
  180.     --Makes the circle round
  181.     if progress == 5 then
  182.         progress = 1
  183.     end
  184.  
  185.     if aLength % 25 then
  186.         print( "The branch mine is now ", aLength, " blocks long." )
  187.     end
  188.  
  189.     if aLength == zLength then
  190.         print( "Finished floor number ", aHeight, "." )
  191.         if aHeight == 1 then
  192.             print( "The branch mine is now the appointed/desired ", aLength, " blocks long." )
  193.         end
  194.         if aHeight ~= height  then
  195.             progress = 0
  196.             aLength = 0
  197.         end
  198.     end
  199. end
  200. print( "Mining ", zLength, " blocks long branch mine." )
  201. --Makes branch mine until desired length is achieved.
  202. while aLength < zLength do
  203.     branchMine()
  204. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement