Lothendas

2x2 Tunnel

Feb 21st, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. local args = { ... }
  2. -- Distance Variable
  3. local distance = tonumber(args[1])
  4. -- Fuel needed Variable
  5. local fuelNeeded = (distance / 2) * 4
  6. -- Torches needed variable
  7. local torchNeeded = distance / 10
  8.  
  9. -- Check Amount of Fuel Function
  10. local function checkFuel()
  11. while (turtle.getFuelLevel() < fuelNeeded) do
  12. turtle.select(1)
  13. if (turtle.getItemCount(1) == 0) then
  14. print("Not enough fuel to complete operation...")
  15. return false
  16. end
  17. turtle.refuel(1)
  18. end
  19. return true
  20. end
  21.  
  22. -- Check Amount of Torches Function
  23. local function checkTorches()
  24. if (turtle.getItemCount(2) < torchNeeded) then
  25. print ("Not enough torches to complete operation...")
  26. return false
  27. end
  28. return true
  29. end
  30.  
  31. -- Detect & Dig Function
  32. local function dig()
  33. while (turtle.detect()) do
  34. turtle.dig()
  35. sleep(0.5)
  36. end
  37. end
  38.  
  39. -- Move Left & Dig Function
  40. local function left()
  41. turtle.forward()
  42. turtle.digDown()
  43. turtle.turnLeft()
  44. end
  45.  
  46. -- Move Right & Dig Function
  47. local function right()
  48. turtle.forward()
  49. turtle.digDown()
  50. turtle.turnRight()
  51. end
  52.  
  53. -- Main Function | Digs Tunnel
  54. local function digTunnel()
  55. print("StartUp Complete. Commencing digging operations..")
  56. local t = 0
  57. local i = 0
  58. while (i < distance) do
  59. dig()
  60. right()
  61. dig()
  62. left()
  63. dig()
  64. left()
  65. dig()
  66. right()
  67. t = t + 2
  68. if (t == 10) then
  69. turtle.select(2)
  70. turtle.placeDown()
  71. t = 0
  72. end
  73. i = i + 2
  74. end
  75. end
  76.  
  77. if checkFuel() and checkTorches() then
  78. digTunnel()
  79. end
Advertisement
Add Comment
Please, Sign In to add comment