Advertisement
charonme

bridge

Jul 9th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- bridge <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.  
  5. local WALL_SLOT = 1
  6. local args = { ... }
  7. local distance = 0
  8. if #args ~= 1 then
  9.     print("Usage: bridge<distance>")
  10.     error()
  11. end
  12. distance = args[1]
  13. if turtle.getFuelLevel() < 1*distance then
  14.     print("Not enough fuel to build the specified distance")
  15.     error()
  16. end
  17. -- ---------------------------------------------------------------------
  18. function reorderWalls()
  19.     for i = 1,16 do
  20.         if i~=WALL_SLOT then
  21.             turtle.select(i)
  22.             -- os.sleep(0.1)
  23.             if turtle.compareTo(WALL_SLOT) and (turtle.getItemCount(i)>0) then
  24.                 while (turtle.getItemCount(i)>0) and (turtle.getItemCount(WALL_SLOT)<64) and (turtle.transferTo(WALL_SLOT,1)) do
  25.                     -- os.sleep(0.01)
  26.                 end
  27.             end
  28.         end
  29.     end
  30.     turtle.select(WALL_SLOT)
  31. end
  32.  
  33. function suckAll()
  34.     local i = 1
  35.     while i <= 16 and (i==WALL_SLOT or turtle.getItemSpace(i)==0) do
  36.         i = i + 1
  37.     end
  38.     if i <= 16 then
  39.         turtle.select(i)
  40.         turtle.suck()
  41.         turtle.suckUp()
  42.         turtle.suckDown()
  43.         reorderWalls()
  44.     end
  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.         while not turtle.place() do
  57.             turtle.dig()
  58.         end
  59.     end
  60. end
  61. function wallDown()
  62.     turtle.select(WALL_SLOT)
  63.     while turtle.detectDown() and not turtle.compareDown() do
  64.         turtle.digDown()
  65.         -- suckAll()
  66.     end
  67.     turtle.select(WALL_SLOT)
  68.     if not turtle.compareDown() then
  69.         while not turtle.placeDown() do
  70.             turtle.digDown()
  71.         end
  72.     end
  73. end
  74.  
  75. -- ---------------------------------------------------------------------
  76. local stepsSinceReorder = 21
  77.  
  78. for i=1,distance do
  79.     if stepsSinceReorder>20 then
  80.         reorderWalls()
  81.         stepsSinceReorder = 0
  82.         turtle.select(WALL_SLOT)
  83.         if turtle.getItemCount() < 3 then
  84.             print("not enough building blocks")
  85.             error()
  86.         end
  87.     end
  88.     while not turtle.forward() do
  89.         turtle.dig()
  90.         -- suckAll()
  91.     end
  92.     wallDown()
  93.     while turtle.detectUp() do
  94.         turtle.digUp()
  95.         -- suckAll()
  96.     end
  97.     turtle.turnLeft()
  98.     wall()
  99.     turtle.turnRight()
  100.     turtle.turnRight()
  101.     wall()
  102.     turtle.turnLeft()
  103.     stepsSinceReorder = stepsSinceReorder+1
  104. end
  105. print("bridge built")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement