TheThirdPerson

Branch Miner

Aug 5th, 2013
1,537
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.75 KB | None | 0 0
  1. print("Number of branches?")
  2. local tunnelNumber = read() -- Here we set up the variables that the whole program works on
  3. print("Length of branches? Longer than 10 inadvisable.")
  4. local tunnelLength = read()
  5. print("Distance between? 3 is ideal.")
  6. local tunnelWall = read()
  7. print("Place torches in slot 2. Press enter when ready.")
  8. read()
  9. local mainDistance = 0
  10. local sideDistance = 0
  11. local mainLength = tunnelNumber*(tunnelWall+1)
  12. local totalTravel = (4*tunnelLength)*(tunnelNumber+2)+(mainLength*2)
  13. print("The total fuel requirement will be: "..totalTravel)
  14. sleep(2)
  15.  
  16.     function sideWork(dist) -- For making the side tunnels, argument is tunnel length. Increments sideDistance
  17.         for i=1,dist do
  18.             while turtle.detect() do
  19.                 turtle.dig()
  20.             end
  21.             turtle.forward()
  22.             sideDistance = sideDistance +1
  23.             turtle.digDown()
  24.             turtle.digUp()
  25.         end
  26.     end
  27.    
  28.     function mainWork(dist) -- For making the main tunnel, argument is tunnel length. Increments mainDistance
  29.         for i=1,dist do
  30.             while turtle.detect() do
  31.                 turtle.dig()
  32.             end
  33.             turtle.forward()
  34.             mainDistance = mainDistance + 1
  35.             turtle.digDown()
  36.             turtle.digUp()
  37.         end
  38.     end
  39.  
  40.     function travel(dist) -- Truncating the turtle.forward command, being stopped by a player or mob will not harm.
  41.         for i=1, dist do
  42.             repeat
  43.             until turtle.forward() == true
  44.         end
  45.     end
  46.    
  47.     function spin() -- because he will do it a lot
  48.         turtle.turnRight()
  49.         turtle.turnRight()
  50.     end
  51.    
  52.     function noFuel() -- Calculates total fuel cost for the job, returns true if there is not enough fuel
  53.         if turtle.getFuelLevel() < totalTravel then
  54.             return true
  55.         end
  56.     end
  57.    
  58.     function placeTorch() -- Places a torch from slot 2
  59.         turtle.select(2)
  60.         turtle.placeUp()
  61.         turtle.select(1)
  62.     end
  63.    
  64.     function checkInventory() -- Returns true if there is an item in the next to last inventory slot
  65.         if turtle.getItemCount(15) > 0 then
  66.             return true
  67.         end
  68.     end
  69.    
  70.     function goHome() -- To return home from the main tunnel
  71.         spin()
  72.         travel(mainDistance)
  73.     end
  74.    
  75.     function goToMain() -- To return to the main tunnel from the side tunnel
  76.         spin()
  77.         travel(sideDistance)
  78.     end
  79.    
  80.     function main(number,length,wall) -- Lets dig this damn tunnel now
  81.        
  82.         if noFuel() == true then
  83.         print("Please place at least "..totalTravel - turtle.getFuelLevel().." fuel in slot 1.")
  84.         end
  85.        
  86.         while noFuel() do -- If there is no fuel, the turtle will keep checking and trying to refuel until it has enough for the job
  87.             turtle.select(1)
  88.             turtle.refuel()
  89.             sleep(0.5)
  90.         end
  91.        
  92.        
  93.         for i=1,number do -- For as many times as there are tunnels
  94.                
  95.             mainWork(wall+1) -- Dig to the next side tunnel
  96.             turtle.back()
  97.             placeTorch() -- Place a torch right before tunnel
  98.             turtle.forward() -- Get to the tunnel proper
  99.             turtle.turnRight() -- Turn to dig the right side
  100.             sideWork(length) -- Dig for the length defined for the branches
  101.             placeTorch() -- place a torch at the end of each branch
  102.             spin() -- Turn around at the end of the tunnel
  103.             travel(length) -- Back to the main tunnel
  104.             sideDistance = 0 -- Reset side distance for next tunnel
  105.             sideWork(length) -- Dig the tunnel on the left now
  106.             placeTorch()
  107.             spin()
  108.             travel(length)
  109.             turtle.turnLeft()
  110.                
  111.             if checkInventory() then -- If the next to last slot has an item in it, go home, drop everything, and come back
  112.                 goHome()
  113.                 turtle.select(1)
  114.                 turtle.drop()
  115.                 for slot=3,16 do
  116.                     turtle.select(slot)
  117.                     turtle.drop()
  118.                 end
  119.                 turtle.select(1)
  120.                 spin()
  121.                 travel(mainDistance)
  122.                
  123.             end
  124.            
  125.         end
  126.        
  127.         goHome()
  128.            
  129.             for slot=1,16 do
  130.                 turtle.select(slot)
  131.                 turtle.drop()
  132.             end
  133.        
  134.         print("Job complete! What's next?")
  135.        
  136.     end
  137.  
  138.    
  139. main(tunnelNumber,tunnelLength,tunnelWall)
Advertisement
Add Comment
Please, Sign In to add comment