package net.minecraft.advancements.critereon;

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

public class CuredZombieVillagerTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return CuredZombieVillagerTrigger.ID;
    }
    
    @Override
    public TriggerInstance createInstance(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
        final EntityPredicate bb4 = EntityPredicate.fromJson(jsonObject.get("zombie"));
        final EntityPredicate bb5 = EntityPredicate.fromJson(jsonObject.get("villager"));
        return new TriggerInstance(bb4, bb5);
    }
    
    public void trigger(final ServerPlayer xe, final Zombie axp, final Villager axw) {
        this.trigger(xe.getAdvancements(), a -> a.matches(xe, axp, axw));
    }
    
    static {
        ID = new ResourceLocation("cured_zombie_villager");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final EntityPredicate zombie;
        private final EntityPredicate villager;
        
        public TriggerInstance(final EntityPredicate bb1, final EntityPredicate bb2) {
            super(CuredZombieVillagerTrigger.ID);
            this.zombie = bb1;
            this.villager = bb2;
        }
        
        public static TriggerInstance curedZombieVillager() {
            return new TriggerInstance(EntityPredicate.ANY, EntityPredicate.ANY);
        }
        
        public boolean matches(final ServerPlayer xe, final Zombie axp, final Villager axw) {
            return this.zombie.matches(xe, axp) && this.villager.matches(xe, axw);
        }
        
        @Override
        public JsonElement serializeToJson() {
            final JsonObject jsonObject2 = new JsonObject();
            jsonObject2.add("zombie", this.zombie.serializeToJson());
            jsonObject2.add("villager", this.villager.serializeToJson());
            return jsonObject2;
        }
    }
}
