Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. -- get arguments
  2.  
  3. local tArgs = { ... }
  4. if #tArgs ~= 1 then
  5. print( "Usage: basicTunne; <Tunnel Length>" )
  6. return
  7. end
  8.  
  9. local tunnelLength = tonumber( tArgs[1] )
  10. if tunnelLength < 1 then
  11. print( "Tunnel Length must be positive!" )
  12. return
  13. end
  14.  
  15. -- function to tunnel 1x3 directly in front
  16.  
  17. local function digInFront ()
  18. if turtle.detectUp() then
  19. if turtle.digUp() then
  20. turtle.suckDown()
  21. end
  22. end
  23.  
  24. if turtle.detect() then
  25. if turtle.dig() then
  26. turtle.suckDown()
  27. end
  28. end
  29.  
  30. if turtle.detectDown() then
  31. if turtle.digDown() then
  32. turtle.suckDown()
  33. end
  34. end
  35. end
  36.  
  37. -- function to move x blocks in given direction (left / right) maintaining orientation
  38. local function move(numToMove, orientation)
  39. local cleanNumToMove = tonumber( numToMove )
  40.  
  41. if orientation == "left" then
  42. if turtle.turnLeft() then
  43. for i = 1, cleanNumToMove, 1 do
  44. turtle.forward()
  45. end
  46. turtle.turnRight()
  47. end
  48. end
  49.  
  50. if orientation == "right" then
  51. if turtle.turnRight() then
  52. for i = 1, cleanNumToMove, 1 do
  53. turtle.forward()
  54. end
  55. turtle.turnLeft()
  56. end
  57. end
  58.  
  59. end
  60.  
  61. -- program start
  62.  
  63. local done = false
  64.  
  65. while not done do
  66. for n = 1, tunnelLength/2 do
  67.  
  68. digInFront()
  69. move(1, "right")
  70. digInFront()
  71. move(1, "right")
  72. digInFront()
  73.  
  74. turtle.forward()
  75.  
  76. digInFront()
  77. move(1, "left")
  78. digInFront()
  79. move(1, "left")
  80. digInFront()
  81. end
  82. done = true
  83. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement