

// replaces the current block with the most common nearby blocks
import { world } from "@minecraft/server";

const leaveCycle = [
    'ecbl_bc:oak_leaves_green', 'ecbl_bc:oak_leaves_orange', 'ecbl_bc:oak_leaves_brown', 'ecbl_bc:oak_leaves_red'
]

world.beforeEvents.worldInitialize.subscribe((Initiate) => {
    Initiate.blockComponentRegistry.registerCustomComponent("ecbl_bc:become_next_leave_variant", {
        onTick: (e) => {
            const { block } = e;
            const blockType = block.typeId;

            const currentIndex = leaveCycle.indexOf(blockType);
            if (currentIndex !== -1) {
                const nextIndex = (currentIndex + 1) % leaveCycle.length;
                block.setType(leaveCycle[nextIndex]);
            }

        }
    });
}); 