package net.minecraft.advancements.critereon;

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

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