// priority: 8
// 食物食用时间
ItemEvents.foodEaten(event => {
    let player = event.player
    if (!player) return;

    let effects = get_all_effect(player);
    effects.forEach(effect => {
        let strategy = all_effect_food_eat_strategies[effect.name] || all_effect_food_eat_strategies.default;
        strategy(event, player, effect.level, effect.name, effect.efficiency);
    });
});
const all_effect_food_eat_strategies = {
    //食腐
    'scavenging': function (event, player, effectLevel, effectname, efficiency) {
        let food = event.item
        if (food == 'minecraft:rotten_flesh'){
            let time = player.persistentData.getInt(effectname) ?? 0
            let CD = Math.abs(player.age - time)
            if (CD < 20 * 20) return
            player.persistentData.putInt(effectname, player.age)

            let random_effect = MAODLEFFECTS_BENEFICIAL[Math.floor(Math.random() * MAODLEFFECTS_BENEFICIAL.length)]
            event.entity.potionEffects.add(random_effect, 20 * 60, effectLevel -1)
        }
    },
    'default': function (event, player, effectLevel, effectname, efficiency) {
        return;
    }
};