package net.minecraft.advancements.critereon;

import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class PlayerHurtEntityTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return PlayerHurtEntityTrigger.ID;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        final DamagePredicate at5 = DamagePredicate.fromJson(jsonObject.get("damage"));
        final EntityPredicate.Composite b2 = EntityPredicate.Composite.fromJson(jsonObject, "entity", av);
        return new TriggerInstance(b, at5, b2);
    }
    
    public void trigger(final ServerPlayer ze, final Entity aom, final DamageSource anw, final float float4, final float float5, final boolean boolean6) {
        final LootContext dat8 = EntityPredicate.createContext(ze, aom);
        this.trigger(ze, a -> a.matches(ze, dat8, anw, float4, float5, boolean6));
    }
    
    static {
        ID = new ResourceLocation("player_hurt_entity");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final DamagePredicate damage;
        private final EntityPredicate.Composite entity;
        
        public TriggerInstance(final EntityPredicate.Composite b1, final DamagePredicate at, final EntityPredicate.Composite b3) {
            super(PlayerHurtEntityTrigger.ID, b1);
            this.damage = at;
            this.entity = b3;
        }
        
        public static TriggerInstance playerHurtEntity(final DamagePredicate.Builder a) {
            return new TriggerInstance(EntityPredicate.Composite.ANY, a.build(), EntityPredicate.Composite.ANY);
        }
        
        public boolean matches(final ServerPlayer ze, final LootContext dat, final DamageSource anw, final float float4, final float float5, final boolean boolean6) {
            return this.damage.matches(ze, anw, float4, float5, boolean6) && this.entity.matches(dat);
        }
        
        @Override
        public JsonObject serializeToJson(final SerializationContext cg) {
            final JsonObject jsonObject3 = super.serializeToJson(cg);
            jsonObject3.add("damage", this.damage.serializeToJson());
            jsonObject3.add("entity", this.entity.toJson(cg));
            return jsonObject3;
        }
    }
}
