package net.minecraft.advancements.critereon;

import org.apache.logging.log4j.LogManager;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.world.level.storage.loot.ValidationContext;
import com.google.gson.JsonElement;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
import com.google.gson.JsonArray;
import net.minecraft.world.level.storage.loot.Deserializers;
import com.google.gson.Gson;
import net.minecraft.world.level.storage.loot.PredicateManager;
import net.minecraft.resources.ResourceLocation;
import org.apache.logging.log4j.Logger;

public class DeserializationContext {
    private static final Logger LOGGER;
    private final ResourceLocation id;
    private final PredicateManager predicateManager;
    private final Gson predicateGson;
    
    public DeserializationContext(final ResourceLocation uh, final PredicateManager day) {
        this.predicateGson = Deserializers.createConditionSerializer().create();
        this.id = uh;
        this.predicateManager = day;
    }
    
    public final LootItemCondition[] deserializeConditions(final JsonArray jsonArray, final String string, final LootContextParamSet dcy) {
        final LootItemCondition[] arr5 = this.predicateGson.<LootItemCondition[]>fromJson(jsonArray, LootItemCondition[].class);
        final ValidationContext dbe6 = new ValidationContext(dcy, this.predicateManager::get, uh -> null);
        for (final LootItemCondition ddm10 : arr5) {
            ddm10.validate(dbe6);
            dbe6.getProblems().forEach((string2, string3) -> DeserializationContext.LOGGER.warn("Found validation problem in advancement trigger {}/{}: {}", string, string2, string3));
        }
        return arr5;
    }
    
    public ResourceLocation getAdvancementId() {
        return this.id;
    }
    
    static {
        LOGGER = LogManager.getLogger();
    }
}
