charonme

tunnelbuilder

Jul 9th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.54 KB | None | 0 0
  1. -- tunnelbuilder <distance>
  2. -- needs building material in the first slot (eg. cobblestone)
  3. -- more building material can be supplied in other slots too if needed
  4. -- turtle will build the top row (with ceiling) first, then turn around, drop below and build the floor
  5. -- tunnel height will be 2 +1 ceiling +1 floor
  6.  
  7. local WALL_SLOT = 1
  8. local args = { ... }
  9. local distance = 0
  10. if #args ~= 1 then
  11.     print("Usage: tunnelbuilder <distance>")
  12.     error()
  13. end
  14. distance = args[1]
  15. if turtle.getFuelLevel() < 2*distance then
  16.     print("Not enough fuel to build the specified distance")
  17.     error()
  18. end
  19. -- ---------------------------------------------------------------------
  20. function reorderWalls()
  21.     for i = 1,16 do
  22.         if i~=WALL_SLOT then
  23.             turtle.select(i)
  24.             os.sleep(0.1)
  25.             if turtle.compareTo(WALL_SLOT) and (turtle.getItemCount(i)>0) then
  26.                 while (turtle.getItemCount(i)>0) and (turtle.getItemCount(WALL_SLOT)<64) and (turtle.transferTo(WALL_SLOT,1)) do
  27.                     -- os.sleep(0.01)
  28.                 end
  29.             end
  30.         end
  31.     end
  32.     turtle.select(WALL_SLOT)
  33. end
  34.  
  35. function suckAll()
  36.     local i = 1
  37.     while i < 17 and (i==WALL_SLOT or turtle.getItemSpace(i)==0) do
  38.         i = i + 1
  39.     end
  40.     turtle.select(i)
  41.     turtle.suck()
  42.     turtle.suckUp()
  43.     turtle.suckDown()
  44.     reorderWalls()
  45.     turtle.select(WALL_SLOT)
  46. end
  47.  
  48. function wall()
  49.     turtle.select(WALL_SLOT)
  50.     while turtle.detect() and not turtle.compare() do
  51.         turtle.dig()
  52.         suckAll()
  53.     end
  54.     turtle.select(WALL_SLOT)
  55.     if not turtle.compare() then
  56.         turtle.place()
  57.     end
  58. end
  59. function wallUp()
  60.     turtle.select(WALL_SLOT)
  61.     while turtle.detectUp() and not turtle.compareUp() do
  62.         turtle.digUp()
  63.         suckAll()
  64.     end
  65.     turtle.select(WALL_SLOT)
  66.     if not turtle.compareUp() then
  67.         turtle.placeUp()
  68.     end
  69. end
  70. function wallDown()
  71.     turtle.select(WALL_SLOT)
  72.     while turtle.detectDown() and not turtle.compareDown() do
  73.         turtle.digDown()
  74.         suckAll()
  75.     end
  76.     turtle.select(WALL_SLOT)
  77.     if not turtle.compareDown() then
  78.         turtle.placeDown()
  79.     end
  80. end
  81.  
  82. -- ---------------------------------------------------------------------
  83. reorderWalls()
  84.  
  85. for i=1,distance do
  86.     while not turtle.forward() do
  87.         turtle.dig()
  88.     end
  89.     turtle.turnLeft()
  90.     wall()
  91.     turtle.turnRight()
  92.     turtle.turnRight()
  93.     wall()
  94.     turtle.turnLeft()
  95.     wallUp()
  96. end
  97.  
  98. -- turn around and drop
  99. turtle.turnRight()
  100. turtle.turnRight()
  101. while not turtle.down() do
  102.     turtle.digDown()
  103.     suckAll()
  104. end
  105.  
  106. for i=1,distance-1 do
  107.     while not turtle.forward() do
  108.         turtle.dig()
  109.     end
  110.     turtle.turnLeft()
  111.     wall()
  112.     turtle.turnRight()
  113.     turtle.turnRight()
  114.     wall()
  115.     turtle.turnLeft()
  116.     wallDown()
  117. end
Advertisement
Add Comment
Please, Sign In to add comment