package com.acethewildfire.acesbs.effect;

import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.entity.effect.StatusEffectCategory;
import net.minecraft.entity.effect.StatusEffectInstance;

public class CigaretteEffect extends StatusEffect {
    public CigaretteEffect(StatusEffectCategory category, int color) {
        super(category, color);
    }

    @Override
    public boolean applyUpdateEffect(LivingEntity entity, int amplifier) {
        StatusEffectInstance effect = entity.getStatusEffect(ModEffects.CIGARETTE);

        if (effect == null) return true;

        // When 1 tick remains, it's about to end
        if (effect.getDuration() <= 1 && !entity.getWorld().isClient()) {

            // Apply new effect
            entity.addStatusEffect(new StatusEffectInstance(
                    ModEffects.JITTERY, // second effect
                    6000,                  // duration (10 sec)
                    0                     // amplifier
            ));
        } else {
            if (!entity.getWorld().isClient()) {
                entity.removeStatusEffect(ModEffects.JITTERY);
                entity.removeStatusEffect(ModEffects.WITHDRAWAL);
            }
        }
        return true;
    }

    @Override
    public boolean canApplyUpdateEffect(int duration, int amplifier) {
        return true;
    }


}

