package net.minecraft.advancements.critereon;

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 UsedTotemTrigger extends SimpleCriterionTrigger<TriggerInstance> {
    private static final ResourceLocation ID;
    
    @Override
    public ResourceLocation getId() {
        return UsedTotemTrigger.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("used_totem");
    }
    
    public static class TriggerInstance extends AbstractCriterionTriggerInstance {
        private final ItemPredicate item;
        
        public TriggerInstance(final EntityPredicate.Composite b, final ItemPredicate bo) {
            super(UsedTotemTrigger.ID, b);
            this.item = bo;
        }
        
        public static TriggerInstance usedTotem(final ItemLike bqa) {
            return new TriggerInstance(EntityPredicate.Composite.ANY, ItemPredicate.Builder.item().of(bqa).build());
        }
        
        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;
        }
    }
}
