import { ItemStack, world } from '@minecraft/server';

world.afterEvents.playerBreakBlock.subscribe((data) => {
    const block = data.block;
    const permutation = data.brokenBlockPermutation;
    const location = block.location;

    const woodTypes = [
        "minecraft:oak_log",
        "minecraft:spruce_log",
        "minecraft:birch_log",
        "minecraft:jungle_log",
        "minecraft:acacia_log",
        "minecraft:dark_oak_log",
        "minecraft:mangrove_log",
        "minecraft:cherry_log"
    ];

    if (woodTypes.some(woodType => permutation.matches(woodType))) {
        if (Math.random() < 0.8) {
            const item = new ItemStack("ph_furn:tree_sap", 1);
            block.dimension.spawnItem(item, location);
        }
    }
});
