package net.minecraft.advancements.critereon;

import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.Item;
import net.minecraft.tags.Tag;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.server.level.ServerPlayer;
import com.google.gson.JsonObject;
import net.minecraft.resources.ResourceLocation;

public class ConsumeItemTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return ConsumeItemTrigger.ID;
    }
    
    public TriggerInstance createInstance(final JsonObject jsonObject, final EntityPredicate.Composite b, final DeserializationContext av) {
        return new TriggerInstance(b, ItemPredicate.fromJson(jsonObject.get("item")));
    }
    
    public void trigger(final ServerPlayer ze, final ItemStack bki) {
        this.trigger(ze, a -> a.matches(bki));
    }
    
    static {
        ID = new ResourceLocation("consume_item");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final ItemPredicate item;
        
        public TriggerInstance(final EntityPredicate.Composite b, final ItemPredicate bo) {
            super(ConsumeItemTrigger.ID, b);
            this.item = bo;
        }
        
        public static TriggerInstance usedItem() {
            return new TriggerInstance(EntityPredicate.Composite.ANY, ItemPredicate.ANY);
        }
        
        public static TriggerInstance usedItem(final ItemLike bqa) {
            return new TriggerInstance(EntityPredicate.Composite.ANY, new ItemPredicate(null, bqa.asItem(), MinMaxBounds.Ints.ANY, MinMaxBounds.Ints.ANY, EnchantmentPredicate.NONE, EnchantmentPredicate.NONE, null, NbtPredicate.ANY));
        }
        
        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;
        }
    }
}
