import * as mc from "@minecraft/server";

const { world, EntityComponentTypes, EquipmentSlot, ItemStack } = mc;

world.afterEvents.worldLoad.subscribe(() => {
    world.afterEvents.entityDie.subscribe(result => {
        if (result.deadEntity.typeId == "minecraft:sheep") {
            const damagingEntity = result.damageSource.damagingEntity;
            if (!damagingEntity) return;

            const equippable = damagingEntity.getComponent(EntityComponentTypes.Equippable);
            if (!equippable) return;

            const item = equippable.getEquipment(EquipmentSlot.Mainhand)
            if (item) {
                item.getTags().forEach(tag => {
                    if (tag == "fd_knife") {
                        const ham = new ItemStack("largemeals:raw_mutton_rack", 1)

                        result.deadEntity.dimension.spawnItem(ham, result.deadEntity.location)
                    }
                })
            }
        }
    })
})