package net.minecraft.advancements.critereon;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class EffectsChangedTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return EffectsChangedTrigger.ID;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        final MobEffectsPredicate by5 = MobEffectsPredicate.fromJson(jsonObject.get("effects"));
        return new TriggerInstance(b, by5);
    }
    
    public void trigger(final ServerPlayer ze) {
        this.trigger(ze, a -> a.matches(ze));
    }
    
    static {
        ID = new ResourceLocation("effects_changed");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final MobEffectsPredicate effects;
        
        public TriggerInstance(final EntityPredicate.Composite b, final MobEffectsPredicate by) {
            super(EffectsChangedTrigger.ID, b);
            this.effects = by;
        }
        
        public static TriggerInstance hasEffects(final MobEffectsPredicate by) {
            return new TriggerInstance(EntityPredicate.Composite.ANY, by);
        }
        
        public boolean matches(final ServerPlayer ze) {
            return this.effects.matches(ze);
        }
        
        @Override
        public JsonObject serializeToJson(final SerializationContext cg) {
            final JsonObject jsonObject3 = super.serializeToJson(cg);
            jsonObject3.add("effects", this.effects.serializeToJson());
            return jsonObject3;
        }
    }
}
