package net.minecraft.advancements.critereon;

import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.GsonHelper;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class RecipeUnlockedTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return RecipeUnlockedTrigger.ID;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        final ResourceLocation uh5 = new ResourceLocation(GsonHelper.getAsString(jsonObject, "recipe"));
        return new TriggerInstance(b, uh5);
    }
    
    public void trigger(final ServerPlayer ze, final Recipe<?> bmu) {
        this.trigger(ze, a -> a.matches(bmu));
    }
    
    public static TriggerInstance unlocked(final ResourceLocation uh) {
        return new TriggerInstance(EntityPredicate.Composite.ANY, uh);
    }
    
    static {
        ID = new ResourceLocation("recipe_unlocked");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final ResourceLocation recipe;
        
        public TriggerInstance(final EntityPredicate.Composite b, final ResourceLocation uh) {
            super(RecipeUnlockedTrigger.ID, b);
            this.recipe = uh;
        }
        
        @Override
        public JsonObject serializeToJson(final SerializationContext cg) {
            final JsonObject jsonObject3 = super.serializeToJson(cg);
            jsonObject3.addProperty("recipe", this.recipe.toString());
            return jsonObject3;
        }
        
        public boolean matches(final Recipe<?> bmu) {
            return this.recipe.equals(bmu.getId());
        }
    }
}
