import { world } from "@minecraft/server";

// rf: {
//     component: "ecbl_bc:replace_rf_with_air",
//     remover: "ecbl_bc:roofed_forest_remover",
//     leaveSet: ['minecraft:mushroom_stem', 'minecraft:brown_mushroom_block', 'minecraft:red_mushroom_block'],
//     result: 'minecraft:air'
// },


world.beforeEvents.worldInitialize.subscribe((Initiate) => {
    Initiate.blockComponentRegistry.registerCustomComponent('ecbl_bc:replace_rf_with_air', {
        onTick: (e) => {
            const { block, dimension } = e;
            const initalLocation = block.location

            const toRemove = ['minecraft:dark_oak_log', 'minecraft:dark_oak_leaves']

            for (let x = -3; x <= 3; x++) {
                for (let z = -3; z <= 3; z++) {
                    if (x == 0 && z == 0) continue;
                    const finalLocation = {
                        x: initalLocation.x + x,
                        y: initalLocation.y,
                        z: initalLocation.z + z
                    };

                    const block = dimension.getBlock(finalLocation);
                    if (!block || !block.isValid()) continue;
                    if (toRemove.includes(block.typeId)) {
                        block.setType('minecraft:air');
                    }
                }
            }

            block.setType('minecraft:air');
        }
    });

});