TheSommer

Branch

Jan 25th, 2013
1,327
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. --[[
  2.     Author
  3.         Rasmus Sommer aka. TheSommer
  4.         youtube.com/thesommersmc
  5.         twitch.tv/thesommer
  6.    
  7.     How to use:
  8.         Slot 1 - Fuel
  9.         Slot 2 - Bridge material
  10.         Slot 3 - Torches
  11.    
  12.         branch <length>
  13. --]]
  14.  
  15. local tArgs = { ... }
  16. if #tArgs ~= 1 then
  17.     print( "Usage: branch <length>" )
  18.     return
  19. end
  20.  
  21. local length = tonumber( tArgs[1] )
  22. if length < 1 then
  23.     print( "Branch length must be positive" )
  24.     return
  25. end
  26.  
  27. local function tryRefuel()
  28.     if turtle.getFuelLevel() == 0 then
  29.         turtle.select(1)
  30.         turtle.refuel(1)
  31.     end
  32. end
  33.  
  34. local function tryDig()
  35.     while turtle.detect() == true do
  36.         turtle.dig()
  37.         sleep(0.5)
  38.     end
  39. end
  40.  
  41. local function tryDigUp()
  42.     while turtle.detectUp() == true do
  43.         turtle.digUp()
  44.         sleep(0.5)
  45.     end
  46. end
  47.  
  48. local function tryUp()
  49.     tryDigUp()
  50.     tryRefuel()
  51.     turtle.up()
  52. end
  53.  
  54. local function tryDown()
  55.     while turtle.detectDown() == true do
  56.         turtle.digDown()
  57.         sleep(0.5)
  58.     end
  59.     tryRefuel()
  60.     turtle.down()
  61. end
  62.  
  63. local function tryForward()
  64.     tryDig()
  65.     tryRefuel()
  66.     turtle.forward()
  67. end
  68.  
  69. local function makeBridge()
  70.     if turtle.detectDown() == false then
  71.         turtle.select(2)
  72.         turtle.placeDown()
  73.     end
  74. end
  75.  
  76. local count = 1
  77.  
  78. for i = 1, length do
  79.     tryForward()
  80.     makeBridge()
  81.     tryDigUp()
  82.     if count % 8 == 0 then
  83.         turtle.turnRight()
  84.         turtle.turnRight()
  85.         turtle.select(3)
  86.         turtle.place()
  87.         turtle.turnRight()
  88.         turtle.turnRight()
  89.     end
  90.     count = count + 1
  91. end
Advertisement
Add Comment
Please, Sign In to add comment