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

world.beforeEvents.itemUse.subscribe((data) => {
    let player = data.source;
    if (data.itemStack.typeId == "ftb_bees:jar_empty") {
        const bees = data.source.getEntitiesFromViewDirection({
            type: "minecraft:bee",
            maxDistance: 20,
        });
        //console.warn(bees.length)
        if (!bees[0]) {
            return;
        }
        const bee = bees[0].entity;
        system.run(() => {
            bee.runCommand(`loot spawn ~ ~ ~ loot "ftb/bees/entities/eggs/vanilla"`);
            bee.remove();
            player.playSound("block.beehive.enter");
            player.runCommand("clear @p ftb_bees:jar_empty 0 1");
        });
    }
});
