Aarondmorgan

Turtle Tunnel

Dec 30th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. --[[Fuel must be placed in slot 15, torches must be placed in slot 16.]]
  2. -- Create the function for refueling
  3. function checkFuel()
  4. if turtle.getFuelLevel() <= 20 then
  5. if turtle.getItemCount(15) == 0 then
  6. print("Out of fuel.")
  7. exit()
  8. else
  9. turtle.select(15)
  10. turtle.refuel(1)
  11. turtle.select(1)
  12. end --if
  13. end --if
  14. end --checkFuel()
  15.  
  16. -- Create the turnAround function
  17. function turnAround()
  18. turtle.turnRight()
  19. turtle.turnRight()
  20. end --turnAround()
  21.  
  22. -- Digs the tunnel for the given length
  23. function tunnel(givenLength)
  24. local torchDistance = 0
  25. for index = 1,givenLength do
  26. if turtle.detect() then
  27. repeat
  28. turtle.dig()
  29. sleep(0.50)
  30. until turtle.detect() == false
  31. end --if
  32. turtle.forward()
  33. if turtle.detectUp() then
  34. repeat
  35. turtle.digUp()
  36. sleep(0.50)
  37. until turtle.detectUp() == false
  38. end --if
  39. turtle.turnLeft()
  40. if turtle.detect() then
  41. repeat
  42. turtle.dig()
  43. sleep(0.50)
  44. until turtle.detect() == false
  45. end --if
  46. turtle.up()
  47. if turtle.detect() then
  48. repeat
  49. turtle.dig()
  50. sleep(0.50)
  51. until turtle.detect() == false
  52. end--if
  53. turtle.turnRight()
  54. turtle.turnRight()
  55. if turtle.detect() then
  56. repeat
  57. turtle.dig()
  58. sleep(0.50)
  59. until turtle.detect() == false
  60. end
  61. turtle.down()
  62. if turtle.detect() then
  63. repeat
  64. turtle.dig()
  65. sleep(0.50)
  66. until turtle.detect() == false
  67. end
  68. turtle.turnLeft()
  69. torchDistance = torchDistance + 1
  70. -- attempts to place a block below
  71. turtle.select(1)
  72. turtle.placeDown()
  73. -- Places a torch every 9 blocks
  74. if torchDistance == 9 then
  75. print("Placing torch...")
  76. turtle.select(16)
  77. turnAround()
  78. turtle.place()
  79. turnAround()
  80. torchDistance = 0
  81. checkFuel()
  82. end --if
  83. end --for
  84. -- Sends the turtle back to the start
  85. turtle.up()
  86. turnAround()
  87. for index = 1,givenLength do
  88. checkFuel()
  89. if not turtle.detect() then
  90. turtle.forward()
  91. else
  92. repeat
  93. turtle.dig()
  94. turtle.sleep(0.25)
  95. until turtle.detect() == false
  96. turtle.forward()
  97. end --if
  98. end --for
  99. turtle.down()
  100. turnAround()
  101. end --tunnel()
  102.  
  103. -- Main script
  104. print("Input tunnel length:")
  105. local length = read()
  106. print("Starting excavation...")
  107. checkFuel()
  108. tunnel(length)
  109. term.clear()
  110. print("The tunnel has been excavated!")
Advertisement
Add Comment
Please, Sign In to add comment