import * as server from "@minecraft/server"

server.world.afterEvents.entityDie.subscribe(result => {
    if (result.deadEntity.typeId == "minecraft:glow_squid") {
        let item = result.damageSource.damagingEntity.getComponent(server.EntityComponentTypes.Equippable).getEquipment(server.EquipmentSlot.Mainhand)
        if (item) {
            item.getTags().forEach(tag => {
                if (tag == "fd_knife") {
                    const ham = new server.ItemStack("crabbersdelight:raw_glow_squid_tentacles", 1)

                    result.deadEntity.dimension.spawnItem(ham, result.deadEntity.location)
                }
            })
        }
    }
}),
server.world.afterEvents.entityDie.subscribe(result => {
    if (result.deadEntity.typeId == "minecraft:squid") {
        let item = result.damageSource.damagingEntity.getComponent(server.EntityComponentTypes.Equippable).getEquipment(server.EquipmentSlot.Mainhand)
        if (item) {
            item.getTags().forEach(tag => {
                if (tag == "fd_knife") {
                    const ham = new server.ItemStack("crabbersdelight:raw_squid_tentacles", 1)

                    result.deadEntity.dimension.spawnItem(ham, result.deadEntity.location)
                }
            })
        }
    }
}),
server.world.afterEvents.entityDie.subscribe(result => {
    if (result.deadEntity.typeId == "minecraft:frog") {
        let item = result.damageSource.damagingEntity.getComponent(server.EntityComponentTypes.Equippable).getEquipment(server.EquipmentSlot.Mainhand)
        if (item) {
            item.getTags().forEach(tag => {
                if (tag == "fd_knife") {
                    const ham = new server.ItemStack("crabbersdelight:raw_frog_leg", 1)

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