// priority: 8
ItemEvents.rightClicked(event => {
    let player = event.player;
    let item = event.item;

    // 使用工具函数获取饰品效果数据
    let curiosEffects = get_all_curios_effects(player);
    if (!curiosEffects || curiosEffects.length === 0) return;

    // 遍历所有饰品效果，执行对应策略
    curiosEffects.forEach(effect => {
        let strategy = curios_tetra_you_jian_Strategies[effect.name] || curios_tetra_you_jian_Strategies.default;
        strategy(event, player, effect.level, effect.name, item, effect.efficiency);
    });
});

const curios_tetra_you_jian_Strategies = {
    //大气符文
    'air_rune': function (event, player, effectLevel, effectname, item, efficiency) {
        if (item != 'legendary_monsters:air_rune') return
        let uuid = player.getUuid()
        let maxhealth = player.getMaxHealth()
        let damageValue = player.getAttributeTotalValue('minecraft:generic.attack_damage')

        //创建实体
        let spawn_entity = player.level.createEntity('legendary_monsters:cloud_golem')
        //实体位置
        spawn_entity.setPosition(player.x, player.y + 1, player.z)
        //生成实体
        spawn_entity.spawn()

        spawn_entity.persistentData.putInt('yi_shang', 10 - maxhealth / 4)
        spawn_entity.persistentData.putString('owner', uuid)
        spawn_entity.persistentData.putInt(attack_addition, damageValue / 4)

        player.swing()
        item.shrink(1)

    },
    //沙暴水晶
    'crystal_of_sandstorm': function (event, player, effectLevel, effectname, item, efficiency) {
        if (item != 'legendary_monsters:crystal_of_sandstorm') return

        let uuid = player.getUuid()
        let maxhealth = player.getMaxHealth()
        let damageValue = player.getAttributeTotalValue('minecraft:generic.attack_damage')

        //创建实体
        let spawn_entity = player.level.createEntity('legendary_monsters:dune_sentinel')
        //实体位置
        spawn_entity.setPosition(player.x, player.y + 1, player.z)
        //生成实体
        spawn_entity.spawn()

        spawn_entity.persistentData.putInt('yi_shang', 10 - maxhealth / 4)
        spawn_entity.persistentData.putString('owner', uuid)
        spawn_entity.persistentData.putInt(attack_addition, damageValue / 4)

        player.swing()
        item.shrink(1)

    },
    //自然水晶
    'nature_crystal': function (event, player, effectLevel, effectname, item, efficiency) {
        if (item != 'legendary_monsters:nature_crystal') return

        let uuid = player.getUuid()
        let maxhealth = player.getMaxHealth()
        let damageValue = player.getAttributeTotalValue('minecraft:generic.attack_damage')

        //创建实体
        let spawn_entity = player.level.createEntity('legendary_monsters:overgrown_colossus')
        //实体位置
        spawn_entity.setPosition(player.x, player.y + 1, player.z)
        //生成实体
        spawn_entity.spawn()

        spawn_entity.persistentData.putInt('yi_shang', 10 - maxhealth / 4)
        spawn_entity.persistentData.putString('owner', uuid)
        spawn_entity.persistentData.putInt(attack_addition, damageValue / 4)

        player.swing()
        item.shrink(1)

    },
    //始冰碎片
    'primal_ice_shard': function (event, player, effectLevel, effectname, item, efficiency) {
        if (item != 'legendary_monsters:primal_ice_shard') return

        let uuid = player.getUuid()
        let maxhealth = player.getMaxHealth()
        let damageValue = player.getAttributeTotalValue('minecraft:generic.attack_damage')

        //创建实体
        let spawn_entity = player.level.createEntity('legendary_monsters:frostbitten_golem')
        //实体位置
        spawn_entity.setPosition(player.x, player.y + 1, player.z)
        //生成实体
        spawn_entity.spawn()

        spawn_entity.persistentData.putInt('yi_shang', 10 - maxhealth / 4)
        spawn_entity.persistentData.putString('owner', uuid)
        spawn_entity.persistentData.putInt(attack_addition, damageValue / 4)

        player.swing()
        item.shrink(1)

    },
    //堕落之魂
    'corrupted_soul': function (event, player, effectLevel, effectname, item, efficiency) {
        let time = player.persistentData.getInt(effectname) ?? 0
        let CD = Math.abs(player.age - time)
        if (CD < 20 * 60 * 10) return
        player.persistentData.putInt(effectname, player.age)

        let damageValue = player.getAttributeTotalValue('minecraft:generic.attack_damage')
        if (item != 'minecraft:iron_ingot') return
        //创建实体
        let spawn_entity = player.level.createEntity('legendary_monsters:guard')
        spawn_entity.setPosition(player.x, player.y + 1, player.z)
        spawn_entity.persistentData.putInt(attack_addition, damageValue)
        //生成实体
        spawn_entity.spawn()
        spawn_entity.tame(player)
        player.swing()
        item.shrink(1)



    },
    'default': function (event, player, effectLevel, effectname, item, efficiency) {
        return;
    }
};