import { getBlocksAround } from '../../utils/utils.js';
import { DeadLeavesRecipes } from '../../recipes/recipes.js';

class LeavesBlockComponent {
    onTick(event) {
        const block = event.block;
        const wantedLeaves = DeadLeavesRecipes.DEAD_LEAVES_TO_LEAVES.get(block.typeId);
        if (!wantedLeaves) {
            return;
        }
        const blocksAround = getBlocksAround(block);
        for (let i = blocksAround.length - 1; i >= 0; i--) {
            const blockAround = blocksAround[i];
            if (blockAround.typeId === wantedLeaves) {
                blockAround.setType(block.typeId);
                return;
            }
        }
    }
}

export { LeavesBlockComponent };
