Quetzi

Branch Miner

Feb 9th, 2013
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. print("place a single torch in slot 15 and a stack of torches in slot 16")
  2.  
  3.  
  4. --Length of the 3x3 hall
  5. print("How long should the Hall be?")
  6. local hallLength = tonumber(io.read())
  7. --Length of each tunnel
  8. print("How long should each side tunnel be?")
  9. local tunnelLength = tonumber(io.read())
  10.  
  11. -- How far apart torches are placed
  12. local torchSpacing = 6
  13.  
  14. function strip()
  15.   if turtle.detect() then
  16.     repeat turtle.dig() until turtle.forward()
  17.   else
  18.     repeat until turtle.forward()
  19.   end
  20.   if turtle.detectDown() then turtle.digDown() end
  21.   while turtle.detectUp() do
  22.     turtle.digUp()
  23.     sleep(0.5)
  24.   end
  25. end
  26.  
  27. function layer()
  28.   strip()
  29.   turtle.turnLeft()
  30.   strip()
  31.   turtle.turnLeft()
  32.   turtle.turnLeft()
  33.   repeat until turtle.forward()
  34.   strip()
  35.   turtle.back()
  36.   turtle.turnLeft()
  37. end
  38.  
  39. function refuel(min)
  40.   if turtle.getFuelLevel()<min then
  41.     print("Refuelling...")
  42.     shell.run("refuel","all")
  43.   end
  44.   if turtle.getFuelLevel()<min then
  45.     print("Not enough fuel to continue")
  46.     return
  47.   end
  48. end
  49.  
  50. function placeTorch()
  51.   turtle.select(16)
  52.   if turtle.compareTo(15) then
  53.     turtle.placeDown()
  54.   end
  55. end
  56.  
  57. function checkTorch(progress)
  58.   if (progress % torchSpacing == 0) and (progress>1) then
  59.     placeTorch()
  60.   end
  61. end
  62.  
  63. function tunnel(length)
  64.   for i=1,length do
  65.     strip()
  66.     checkTorch(i-1)
  67.   end
  68. end
  69. function hall(length)
  70.   for i=1,length do
  71.     layer()
  72.     checkTorch(i)
  73.   end
  74. end
  75.  
  76. function minesection()
  77.   local sections = math.floor(hallLength/6)
  78.   for i=1,sections do
  79.     hall(6)
  80.     for i=1,5 do
  81.       repeat until turtle.back()
  82.     end
  83.     turtle.turnLeft()
  84.     repeat until turtle.forward()
  85.     tunnel(tunnelLength)
  86.     turtle.turnRight()
  87.     tunnel(5)
  88.     turtle.back()
  89.     turtle.back()
  90.     placeTorch()
  91.     turtle.turnRight()
  92.     tunnel(tunnelLength)
  93.     for i=1,2 do
  94.       repeat until turtle.forward()
  95.     end
  96.     tunnel(tunnelLength)
  97.     turtle.turnRight()
  98.     tunnel(5)
  99.     turtle.back()
  100.     turtle.back()
  101.     placeTorch()
  102.     turtle.turnRight()
  103.     tunnel(tunnelLength)
  104.     repeat until turtle.forward()
  105.     turtle.turnRight()
  106.     for i=1,5 do
  107.       repeat until turtle.forward()
  108.     end
  109.   end
  110. end
  111. minesection()
Advertisement
Add Comment
Please, Sign In to add comment