package net.minecraft.advancements.critereon;

import net.minecraft.world.item.ItemStack;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class FilledBucketTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return FilledBucketTrigger.ID;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        final ItemPredicate bo5 = ItemPredicate.fromJson(jsonObject.get("item"));
        return new TriggerInstance(b, bo5);
    }
    
    public void trigger(final ServerPlayer ze, final ItemStack bki) {
        this.trigger(ze, a -> a.matches(bki));
    }
    
    static {
        ID = new ResourceLocation("filled_bucket");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final ItemPredicate item;
        
        public TriggerInstance(final EntityPredicate.Composite b, final ItemPredicate bo) {
            super(FilledBucketTrigger.ID, b);
            this.item = bo;
        }
        
        public static TriggerInstance filledBucket(final ItemPredicate bo) {
            return new TriggerInstance(EntityPredicate.Composite.ANY, bo);
        }
        
        public boolean matches(final ItemStack bki) {
            return this.item.matches(bki);
        }
        
        @Override
        public JsonObject serializeToJson(final SerializationContext cg) {
            final JsonObject jsonObject3 = super.serializeToJson(cg);
            jsonObject3.add("item", this.item.serializeToJson());
            return jsonObject3;
        }
    }
}
