package net.minecraft.advancements.critereon;

import com.google.gson.JsonElement;
import net.minecraft.world.level.ItemLike;
import net.minecraft.advancements.CriterionTriggerInstance;
import net.minecraft.world.item.ItemStack;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class ShotCrossbowTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return ShotCrossbowTrigger.ID;
    }
    
    @Override
    public TriggerInstance createInstance(final JsonObject jsonObject, final JsonDeserializationContext jsonDeserializationContext) {
        final ItemPredicate bj4 = ItemPredicate.fromJson(jsonObject.get("item"));
        return new TriggerInstance(bj4);
    }
    
    public void trigger(final ServerPlayer xe, final ItemStack ben) {
        this.trigger(xe.getAdvancements(), a -> a.matches(ben));
    }
    
    static {
        ID = new ResourceLocation("shot_crossbow");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final ItemPredicate item;
        
        public TriggerInstance(final ItemPredicate bj) {
            super(ShotCrossbowTrigger.ID);
            this.item = bj;
        }
        
        public static TriggerInstance shotCrossbow(final ItemLike bjv) {
            return new TriggerInstance(ItemPredicate.Builder.item().of(bjv).build());
        }
        
        public boolean matches(final ItemStack ben) {
            return this.item.matches(ben);
        }
        
        @Override
        public JsonElement serializeToJson() {
            final JsonObject jsonObject2 = new JsonObject();
            jsonObject2.add("item", this.item.serializeToJson());
            return jsonObject2;
        }
    }
}
