Guest User

bridge

a guest
Jan 11th, 2015
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. local function doFuel()
  2.   while turtle.getFuelLevel() < 10 do
  3.     for i = 1,16 do
  4.       if turtle.getItemCount(i) > 0 then
  5.         turtle.select(i)
  6.         if turtle.refuel(4) then
  7.           break
  8.         end
  9.       end
  10.     end
  11.     if turtle.getFuelLevel() >= 10 then
  12.       break
  13.     end
  14.     print("Please insert more fuel")
  15.     os.pullEvent("turtle_inventory")
  16.   end
  17. end
  18.  
  19. local function putDown()
  20.   if not turtle.detectDown() and not turtle.placeDown() then
  21.     while not turtle.detectDown() do
  22.       for i = 1,16 do
  23.         if turtle.getItemCount(i) > 0 then
  24.           turtle.select(i)
  25.           if turtle.placeDown() then
  26.             break
  27.           end
  28.         end
  29.       end
  30.       if turtle.detectDown() then
  31.         break
  32.       end
  33.       print("Please insert building material.")
  34.       os.pullEvent("turtle_inventory")
  35.     end
  36.   end
  37. end
  38.  
  39. local args = {...}
  40. if #args ~= 1 or not tonumber(args[1]) then
  41.   print("Usage: bridge <length>")
  42.   return
  43. end
  44.  
  45. local length = tonumber(args[1])
  46. maxHeight = 0
  47. minHeight = 0
  48. height = 0
  49.  
  50. for i = 1,length-1 do
  51.   doFuel()
  52.   while turtle.detect() do
  53.     height = height + 1
  54.     while not turtle.up() do
  55.       turtle.back()
  56.       i = i-1
  57.     end
  58.   end
  59.   turtle.forward()
  60. end
  61. maxHeight = height+1
  62.  
  63. while not turtle.detectDown() do
  64.   doFuel()
  65.   height = height - 1
  66.   turtle.down()
  67. end
  68. minHeight = height
  69.  
  70. turtle.turnLeft()
  71. turtle.turnLeft()
  72.  
  73. for i = 1, length do
  74.   if i < length then
  75.     doFuel()
  76.     if length-i <= maxHeight-1 then
  77.       if height > 1 then
  78.         turtle.down()
  79.         height = height - 1
  80.       end
  81.     else
  82.       if height < maxHeight then
  83.         turtle.up()
  84.         height = height + 1
  85.       end
  86.     end
  87.     putDown()
  88.     turtle.forward()
  89.   end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment