Lothendas

SingleTunnel

Feb 15th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. --SingleTunnel by Lothendas
  2.  
  3. --****IMPORTANT READ THIS***
  4. -- 1. Fuel in slot 1 (Coal/Charcoal/LavaBuckets)
  5. -- 2. Torces in slot 2
  6.  
  7. local args = { ... }
  8. -- Distance Variable
  9. local distance = tonumber(args[1])
  10. -- Fuel needed Variable
  11. local fuelNeeded = distance * 2
  12. -- Torches needed variable
  13. local torchNeeded = distance / 10
  14.  
  15. -- Check Amount of Fuel Function
  16. local function checkFuel()
  17.     while (turtle.getFuelLevel() < fuelNeeded) do
  18.         turtle.select(1)
  19.         if (turtle.getItemCount(1) == 0) then
  20.             print("Not enough fuel to complete operation...")
  21.             return false
  22.         end
  23.         turtle.refuel(1)
  24.     end
  25.     return true
  26. end
  27.  
  28. -- Check Amount of Torches Function
  29. local function checkTorches()
  30.     if (turtle.getItemCount(2) < torchNeeded) then
  31.         print ("Not enough torches to complete operation...")
  32.         return false
  33.     end
  34.     return true
  35. end
  36.  
  37. local function placeTorch()
  38.     turtle.select(2)
  39.     turtle.placeDown()
  40. end
  41.  
  42. local function dig()
  43.     while (turtle.detect()) do
  44.         turtle.dig()
  45.         sleep(0.5)
  46.     end
  47. end
  48.  
  49. local function turnAround()
  50.     turtle.turnLeft()
  51.     turtle.turnLeft()
  52. end
  53.  
  54. local function toStart()
  55.     local i = 0
  56.     for i = 1, distance do
  57.         turtle.forward()
  58.     end
  59. end
  60.  
  61. local function digTunnel()
  62.     print("Initializing digging...")
  63.     local torch = 0
  64.     local i = 0
  65.     while (i < distance) do
  66.         dig()
  67.         turtle.forward()
  68.         turtle.digDown()
  69.         torch = torch + 1
  70.         if (torch == 10) then
  71.             placeTorch()
  72.             turtle.turnLeft()
  73.             dig()
  74.             turnAround()
  75.             dig()
  76.             turtle.turnLeft()
  77.             torch = 0
  78.         end
  79.         i = i + 1
  80.     end
  81.     turnAround()
  82.     toStart()
  83.     print("Tunnel digging complete...")
  84. end
  85.  
  86. if checkFuel() and checkTorches() then
  87.     digTunnel()
  88. end
Advertisement
Add Comment
Please, Sign In to add comment