Advertisement
mandydax

Turtle Tunnel

Sep 11th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.79 KB | None | 0 0
  1. local args = { ... }
  2. local distance = 0
  3. local dropItems = false
  4. local makeFloor = false
  5. local enclosed = false
  6. local height = 2
  7. turtle.select(1)
  8.  
  9. function select(slot)
  10.   turtle.select(slot)
  11. end
  12.  
  13. function forward()
  14.   while not turtle.forward() do
  15.     turtle.dig()
  16.   end
  17. end
  18.  
  19. function up()
  20.   while not turtle.up() do
  21.     turtle.digUp()
  22.   end
  23. end
  24.  
  25. function down()
  26.   while not turtle.down() do
  27.     turtle.digDown()
  28.   end
  29. end
  30.  
  31. function place(slot)
  32.   select(slot)
  33.   while not turtle.place() do
  34.     turtle.dig()
  35.   end
  36. end
  37.  
  38. function placeUp(slot)
  39.   select(slot)
  40.   while not turtle.placeUp() do
  41.     turtle.digUp()
  42.   end
  43. end
  44.  
  45. function placeDown(slot)
  46.   select(slot)
  47.   while not turtle.placeDown() do
  48.     turtle.digDown()
  49.   end
  50. end
  51.  
  52. function left()
  53.   turtle.turnLeft()
  54. end
  55.  
  56. function right()
  57.   turtle.turnRight()
  58. end
  59.  
  60. function uturn()
  61.   left()
  62.   left()
  63. end
  64.  
  65. function flooring(slot)
  66.   for i = 2, distance do
  67.     turtle.digUp()
  68.     placeDown(slot)
  69.     forward()
  70.   end
  71.   turtle.digUp()
  72.   placeDown(slot)
  73. end
  74.  
  75. function roofingCorner(slot)
  76.   for i = 2, distance do
  77.     placeDown(slot)
  78.     forward()
  79.   end
  80.   placeDown(slot)
  81. end
  82.  
  83. function roofing(slot)
  84.   for i = 2, distance do
  85.     placeUp(slot)
  86.     forward()
  87.   end
  88.   placeUp(slot)
  89. end
  90.    
  91.  
  92. -- parse command line
  93. if #args == 0 then
  94.   print("Usage: Tunnel [distance]")
  95.   print("Optional tags:")
  96.   print(" -hx: height of tunnel x (1-3)")
  97.   print("       (default: 2)")
  98.   print(" -d: drop items")
  99.   print(" -f: create floor")
  100.   print("      (put mats in slot 1)")
  101.   print(" -e: enclosed")
  102. else
  103.   distance = args[1]
  104.   if #args > 1 then
  105.     for i=2, #args do
  106.       if args[i] == "-d" then
  107.         dropItems = true
  108.       elseif args[i] == "-f" then
  109.         turtle.select(1)
  110.         makeFloor = true
  111.       elseif string.sub(args[i], 1, 2) == "-h" then
  112.         height = tonumber(string.sub(args[i], 3, 3))
  113.       elseif args[i] == "-e" then
  114.         enclosed = true
  115.       end
  116.     end  
  117.   end
  118. end
  119.  
  120. if enclosed then --do enclosed tunnel
  121.   flooring(14)
  122.   left()
  123.   forward()
  124.   left()
  125.   flooring(13)
  126.   left()
  127.   forward()
  128.   forward()
  129.   left()
  130.   flooring(15)
  131.   up()
  132.   uturn()
  133.   flooring(11)
  134.   right()
  135.   forward()
  136.   forward()
  137.   right()
  138.   flooring(9)
  139.   up()
  140.   uturn()
  141.   flooring(5)
  142.   left()
  143.   forward()
  144.   forward()
  145.   left()
  146.   flooring(7)
  147.   up()
  148.   uturn()
  149.   roofingCorner(3)
  150.   right()
  151.   forward()
  152.   forward()
  153.   right()
  154.   roofingCorner(1)
  155.   right()
  156.   forward()
  157.   right()
  158.   down()
  159.   down()
  160.   roofing(2)
  161.   down()
  162.   uturn()
  163. else --do regular tunnel
  164.   for i = 1, distance do
  165.     forward()
  166.     if height > 1 then turtle.digUp() end
  167.     if height > 2 then turtle.digDown() end
  168.     if makeFloor then
  169.       placeDown()
  170.     end
  171.     if dropItems then turtle.drop() end
  172.   end
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement