package net.minecraft.advancements.critereon;

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

public class EntityHurtPlayerTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return EntityHurtPlayerTrigger.ID;
    }
    
    @Override
    public TriggerInstance createInstance(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
        final DamagePredicate ar4 = DamagePredicate.fromJson(jsonObject.get("damage"));
        return new TriggerInstance(ar4);
    }
    
    public void trigger(final ServerPlayer xe, final DamageSource ajz, final float float3, final float float4, final boolean boolean5) {
        this.trigger(xe.getAdvancements(), a -> a.matches(xe, ajz, float3, float4, boolean5));
    }
    
    static {
        ID = new ResourceLocation("entity_hurt_player");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final DamagePredicate damage;
        
        public TriggerInstance(final DamagePredicate ar) {
            super(EntityHurtPlayerTrigger.ID);
            this.damage = ar;
        }
        
        public static TriggerInstance entityHurtPlayer(final DamagePredicate.Builder a) {
            return new TriggerInstance(a.build());
        }
        
        public boolean matches(final ServerPlayer xe, final DamageSource ajz, final float float3, final float float4, final boolean boolean5) {
            return this.damage.matches(xe, ajz, float3, float4, boolean5);
        }
        
        @Override
        public JsonElement serializeToJson() {
            final JsonObject jsonObject2 = new JsonObject();
            jsonObject2.add("damage", this.damage.serializeToJson());
            return jsonObject2;
        }
    }
}
