Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to check for a tree on the given side (left/right)
- function checkForTree(side)
- if side == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- if turtle.detect() then
- turtle.select(2) -- Select log for comparison
- if turtle.compare() then
- print("Tree detected on the " .. side .. ". Chopping and replanting.")
- -- Chopping the tree logic
- -- Break the block in front and move forward, repeat until the block above is not the same as slot 2
- if turtle.detect() then
- turtle.dig() -- Dig the block in front
- turtle.forward() -- Move forward to the next block
- -- Now check and dig the block above
- while turtle.detectUp() do
- turtle.digUp() -- Dig the block above
- turtle.up() -- Move up to the next level
- end
- end
- -- Now the turtle is at the top, move down until it meets a block
- while not turtle.detectDown() do
- turtle.down() -- Move down until a block is encountered
- end
- -- Turn around to face the original position
- turtle.turnLeft()
- turtle.turnLeft()
- -- Move forward to the original position
- turtle.forward()
- -- Turn to the left to plant the sapling
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(1) -- Select sapling in slot 1
- turtle.place() -- Place the sapling
- end
- end
- -- Return to original orientation
- if side == "left" then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- -- Call the function to start checking for trees on the left
- checkForTree("left")
Advertisement
Add Comment
Please, Sign In to add comment