package net.minecraft.advancements.critereon;

import com.google.gson.JsonElement;
import net.minecraft.advancements.CriterionTriggerInstance;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class SummonedEntityTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return SummonedEntityTrigger.ID;
    }
    
    @Override
    public TriggerInstance createInstance(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
        final EntityPredicate bb4 = EntityPredicate.fromJson(jsonObject.get("entity"));
        return new TriggerInstance(bb4);
    }
    
    public void trigger(final ServerPlayer xe, final Entity akq) {
        this.trigger(xe.getAdvancements(), a -> a.matches(xe, akq));
    }
    
    static {
        ID = new ResourceLocation("summoned_entity");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final EntityPredicate entity;
        
        public TriggerInstance(final EntityPredicate bb) {
            super(SummonedEntityTrigger.ID);
            this.entity = bb;
        }
        
        public static TriggerInstance summonedEntity(final EntityPredicate.Builder a) {
            return new TriggerInstance(a.build());
        }
        
        public boolean matches(final ServerPlayer xe, final Entity akq) {
            return this.entity.matches(xe, akq);
        }
        
        @Override
        public JsonElement serializeToJson() {
            final JsonObject jsonObject2 = new JsonObject();
            jsonObject2.add("entity", this.entity.serializeToJson());
            return jsonObject2;
        }
    }
}
