package net.minecraft.advancements.critereon;

import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.entity.monster.Zombie;
import net.minecraft.server.level.ServerPlayer;
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;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        final EntityPredicate.Composite b2 = EntityPredicate.Composite.fromJson(jsonObject, "zombie", av);
        final EntityPredicate.Composite b3 = EntityPredicate.Composite.fromJson(jsonObject, "villager", av);
        return new TriggerInstance(b, b2, b3);
    }
    
    public void trigger(final ServerPlayer ze, final Zombie bcu, final Villager bdp) {
        final LootContext dat5 = EntityPredicate.createContext(ze, bcu);
        final LootContext dat6 = EntityPredicate.createContext(ze, bdp);
        this.trigger(ze, a -> a.matches(dat5, dat6));
    }
    
    static {
        ID = new ResourceLocation("cured_zombie_villager");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final EntityPredicate.Composite zombie;
        private final EntityPredicate.Composite villager;
        
        public TriggerInstance(final EntityPredicate.Composite b1, final EntityPredicate.Composite b2, final EntityPredicate.Composite b3) {
            super(CuredZombieVillagerTrigger.ID, b1);
            this.zombie = b2;
            this.villager = b3;
        }
        
        public static TriggerInstance curedZombieVillager() {
            return new TriggerInstance(EntityPredicate.Composite.ANY, EntityPredicate.Composite.ANY, EntityPredicate.Composite.ANY);
        }
        
        public boolean matches(final LootContext dat1, final LootContext dat2) {
            return this.zombie.matches(dat1) && this.villager.matches(dat2);
        }
        
        @Override
        public JsonObject serializeToJson(final SerializationContext cg) {
            final JsonObject jsonObject3 = super.serializeToJson(cg);
            jsonObject3.add("zombie", this.zombie.toJson(cg));
            jsonObject3.add("villager", this.villager.toJson(cg));
            return jsonObject3;
        }
    }
}
