Lorc520

treecut

Apr 24th, 2025 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. -- Function to check for a tree on the given side (left/right)
  2. function checkForTree(side)
  3. if side == "left" then
  4. turtle.turnLeft()
  5. else
  6. turtle.turnRight()
  7. end
  8.  
  9. if turtle.detect() then
  10. turtle.select(2) -- Select log for comparison
  11. if turtle.compare() then
  12. print("Tree detected on the " .. side .. ". Chopping and replanting.")
  13.  
  14. -- Chopping the tree logic
  15. -- Break the block in front and move forward, repeat until the block above is not the same as slot 2
  16. if turtle.detect() then
  17. turtle.dig() -- Dig the block in front
  18. turtle.forward() -- Move forward to the next block
  19.  
  20. -- Now check and dig the block above
  21. while turtle.detectUp() do
  22. turtle.digUp() -- Dig the block above
  23. turtle.up() -- Move up to the next level
  24. end
  25. end
  26.  
  27. -- Now the turtle is at the top, move down until it meets a block
  28. while not turtle.detectDown() do
  29. turtle.down() -- Move down until a block is encountered
  30. end
  31.  
  32. -- Turn around to face the original position
  33. turtle.turnLeft()
  34. turtle.turnLeft()
  35.  
  36. -- Move forward to the original position
  37. turtle.forward()
  38.  
  39. -- Turn to the left to plant the sapling
  40. turtle.turnLeft()
  41. turtle.turnLeft()
  42. turtle.select(1) -- Select sapling in slot 1
  43. turtle.place() -- Place the sapling
  44. end
  45. end
  46.  
  47. -- Return to original orientation
  48. if side == "left" then
  49. turtle.turnRight()
  50. else
  51. turtle.turnLeft()
  52. end
  53. end
  54.  
  55. -- Call the function to start checking for trees on the left
  56. checkForTree("left")
  57.  
Advertisement
Add Comment
Please, Sign In to add comment