Advertisement
jkCBWPnet

Bridge

Aug 6th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. --Builds a platform or fills a non flat surface.
  2. --place turtle on last block before the span
  3. --this is my first lua app ;)
  4. --this may be upgraded to predetermine length needed for unknown span or wider path etc.
  5.  
  6. local function block()
  7.     if not turtle.detectDown() then
  8.         turtle.placeDown()
  9.     end
  10. end
  11.  
  12. local function move()
  13.     if turtle.detect() then
  14.         turtle.dig()
  15.     end
  16.     turtle.forward()
  17. end
  18.  
  19. local tArgs = { ... }
  20. if #tArgs < 1 then
  21.     print( "Usage: bridge <length> <width>" )
  22.     return
  23. end
  24.  
  25. local length = tonumber( tArgs[1] )
  26. if length < 1 then
  27.     print( "Bridge length must be positive." )
  28.     return
  29. end
  30.  
  31. local width = 1
  32. if #tArgs == 2 then
  33.     width = tonumber( tArgs[2] )
  34.     if width < 1 then
  35.         print( "Bridge width must be positive." )
  36.         return
  37.     end
  38. end
  39.  
  40. local blocks = 0
  41. for n=1,16 do
  42.     blocks = blocks + turtle.getItemCount(n)
  43. end
  44. if blocks < length * width then
  45.     print( "There must be at least "..(length * width).." blocks in the slots." )
  46.     return
  47. else
  48.     local slot = 1
  49.     local right = true
  50.     move()
  51.     block()
  52.     for x=1,width do
  53.         for z=1,length - 1 do
  54.             while turtle.getItemCount(slot) < 1 do
  55.                 slot = slot + 1
  56.             end
  57.             turtle.select(slot)
  58.             move()
  59.             block()
  60.         end
  61.         if x ~= width then
  62.             if right then
  63.                 turtle.turnRight()
  64.                 move()
  65.                 turtle.turnRight()
  66.             else
  67.                 turtle.turnLeft()
  68.                 move()
  69.                 turtle.turnLeft()
  70.             end
  71.             sleep(0.1)
  72.             block()
  73.             right = not right
  74.         end
  75.     end
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement