Advertisement
Guest User

lumberjack turtle

a guest
Apr 2nd, 2012
4,125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. function up()
  2.     while not turtle.up() do
  3.         turtle.digUp()
  4.     end
  5. end
  6.  
  7. function cutTree()
  8.     while turtle.compare() do
  9.         turtle.dig()
  10.         up()
  11.     end
  12.     while not turtle.detectDown() do
  13.         turtle.down()
  14.     end
  15. end
  16.  
  17. function search(dist)
  18.     while dist > 0 do
  19.         if turtle.compare() then
  20.             cutTree()
  21.         elseif not turtle.forward() then
  22.             up()
  23.         else
  24.             dist = dist - 1
  25.             while not turtle.detectDown() do
  26.                 turtle.down()
  27.             end
  28.         end
  29.     end
  30. end
  31.  
  32. local args = {...}
  33. if #args ~= 1 then
  34.     print('Usage: lumberjack <size>')
  35.     return
  36. end
  37.  
  38. turtle.select(1)
  39. if turtle.getItemCount(1) == 0 then
  40.     print('ERROR: Requires unrefined wood block in slot #1.')
  41.     return
  42. end
  43.  
  44. for n = 1, args[1], 1 do
  45.     search(n)
  46.     turtle.turnRight()
  47.     search(n)
  48.     turtle.turnRight()
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement