Advertisement
Guest User

Nomo's TreeFarm

a guest
May 5th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | None | 0 0
  1. local tArgs = { ... }
  2. if #tArgs == 1 then
  3.     amount = tonumber( tArgs[1] )
  4. else
  5.     amount = 1
  6. end
  7.  
  8. if turtle.getItemCount(16) < amount then
  9.     print("Please supply sufficient saplings in bottom right slot.")
  10.     return
  11. end
  12.  
  13. -- -- -- -- functions -- -- -- --
  14. local function tryDig()
  15.     while turtle.detect() do
  16.         if turtle.dig() then
  17.             sleep(0.1)
  18.         else    return false
  19.     end end
  20.     return true
  21. end
  22.  
  23. local function tryForward()
  24.     while not turtle.forward() do
  25.         if turtle.detect() then
  26.             if not tryDig() then
  27.                 return false
  28.             end
  29.         elseif turtle.attack() then
  30.             collect()
  31.         else
  32.             sleep( 0.5 )
  33.     end end
  34.     return true
  35. end
  36. -- -- -- -- main loop -- -- -- --
  37.  
  38. turtle.select(16)
  39. for i = 1, amount do
  40.     repeat turtle.forward() until turtle.detect()
  41.     tryForward()
  42.     repeat
  43.         turtle.digUp()
  44.         turtle.up()
  45.     until not turtle.detectUp()
  46.     repeat turtle.down()
  47.     until turtle.detectDown()
  48.     turtle.digDown()
  49.     turtle.placeDown()
  50. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement