package net.minecraft.data.loot;

import com.google.gson.GsonBuilder;
import org.apache.logging.log4j.LogManager;
import java.util.Map;
import net.minecraft.world.level.storage.loot.predicates.LootItemCondition;
import net.minecraft.world.level.storage.loot.ValidationContext;
import java.io.IOException;
import net.minecraft.world.level.storage.loot.LootTables;
import java.nio.file.Path;
import net.minecraft.data.HashCache;
import com.google.common.collect.ImmutableList;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSet;
import net.minecraft.world.level.storage.loot.LootTable;
import net.minecraft.resources.ResourceLocation;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Supplier;
import com.mojang.datafixers.util.Pair;
import java.util.List;
import net.minecraft.data.DataGenerator;
import com.google.gson.Gson;
import org.apache.logging.log4j.Logger;
import net.minecraft.data.DataProvider;

public class LootTableProvider implements DataProvider {
    private static final Logger LOGGER;
    private static final Gson GSON;
    private final DataGenerator generator;
    private final List<Pair<Supplier<Consumer<BiConsumer<ResourceLocation, LootTable.Builder>>>, LootContextParamSet>> subProviders;
    
    public LootTableProvider(final DataGenerator gy) {
        this.subProviders = ImmutableList.of(Pair.of(FishingLoot::new, LootContextParamSets.FISHING), Pair.of(ChestLoot::new, LootContextParamSets.CHEST), Pair.of(EntityLoot::new, LootContextParamSets.ENTITY), Pair.of(BlockLoot::new, LootContextParamSets.BLOCK), Pair.of(GiftLoot::new, LootContextParamSets.GIFT));
        this.generator = gy;
    }
    
    @Override
    public void run(final HashCache ha) {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     1: getfield        net/minecraft/data/loot/LootTableProvider.generator:Lnet/minecraft/data/DataGenerator;
        //     4: invokevirtual   net/minecraft/data/DataGenerator.getOutputFolder:()Ljava/nio/file/Path;
        //     7: astore_2        /* path3 */
        //     8: invokestatic    com/google/common/collect/Maps.newHashMap:()Ljava/util/HashMap;
        //    11: astore_3        /* map4 */
        //    12: aload_0         /* this */
        //    13: getfield        net/minecraft/data/loot/LootTableProvider.subProviders:Ljava/util/List;
        //    16: aload_3         /* map4 */
        //    17: invokedynamic   BootstrapMethod #5, accept:(Ljava/util/Map;)Ljava/util/function/Consumer;
        //    22: invokeinterface java/util/List.forEach:(Ljava/util/function/Consumer;)V
        //    27: new             Lnet/minecraft/world/level/storage/loot/ValidationContext;
        //    30: dup            
        //    31: getstatic       net/minecraft/world/level/storage/loot/parameters/LootContextParamSets.ALL_PARAMS:Lnet/minecraft/world/level/storage/loot/parameters/LootContextParamSet;
        //    34: invokedynamic   BootstrapMethod #6, apply:()Ljava/util/function/Function;
        //    39: aload_3         /* map4 */
        //    40: invokedynamic   BootstrapMethod #7, apply:(Ljava/util/Map;)Ljava/util/function/Function;
        //    45: invokespecial   net/minecraft/world/level/storage/loot/ValidationContext.<init>:(Lnet/minecraft/world/level/storage/loot/parameters/LootContextParamSet;Ljava/util/function/Function;Ljava/util/function/Function;)V
        //    48: astore          csg5
        //    50: invokestatic    net/minecraft/world/level/storage/loot/BuiltInLootTables.all:()Ljava/util/Set;
        //    53: aload_3         /* map4 */
        //    54: invokeinterface java/util/Map.keySet:()Ljava/util/Set;
        //    59: invokestatic    com/google/common/collect/Sets.difference:(Ljava/util/Set;Ljava/util/Set;)Lcom/google/common/collect/Sets$SetView;
        //    62: astore          set6
        //    64: aload           set6
        //    66: invokeinterface java/util/Set.iterator:()Ljava/util/Iterator;
        //    71: astore          6
        //    73: aload           6
        //    75: invokeinterface java/util/Iterator.hasNext:()Z
        //    80: ifeq            123
        //    83: aload           6
        //    85: invokeinterface java/util/Iterator.next:()Ljava/lang/Object;
        //    90: checkcast       Lnet/minecraft/resources/ResourceLocation;
        //    93: astore          sm8
        //    95: aload           csg5
        //    97: new             Ljava/lang/StringBuilder;
        //   100: dup            
        //   101: invokespecial   java/lang/StringBuilder.<init>:()V
        //   104: ldc             "Missing built-in table: "
        //   106: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        //   109: aload           sm8
        //   111: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
        //   114: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
        //   117: invokevirtual   net/minecraft/world/level/storage/loot/ValidationContext.reportProblem:(Ljava/lang/String;)V
        //   120: goto            73
        //   123: aload_3         /* map4 */
        //   124: aload           csg5
        //   126: invokedynamic   BootstrapMethod #8, accept:(Lnet/minecraft/world/level/storage/loot/ValidationContext;)Ljava/util/function/BiConsumer;
        //   131: invokeinterface java/util/Map.forEach:(Ljava/util/function/BiConsumer;)V
        //   136: aload           csg5
        //   138: invokevirtual   net/minecraft/world/level/storage/loot/ValidationContext.getProblems:()Lcom/google/common/collect/Multimap;
        //   141: astore          multimap7
        //   143: aload           multimap7
        //   145: invokeinterface com/google/common/collect/Multimap.isEmpty:()Z
        //   150: ifne            176
        //   153: aload           multimap7
        //   155: invokedynamic   BootstrapMethod #9, accept:()Ljava/util/function/BiConsumer;
        //   160: invokeinterface com/google/common/collect/Multimap.forEach:(Ljava/util/function/BiConsumer;)V
        //   165: new             Ljava/lang/IllegalStateException;
        //   168: dup            
        //   169: ldc_w           "Failed to validate loot tables, see logs"
        //   172: invokespecial   java/lang/IllegalStateException.<init>:(Ljava/lang/String;)V
        //   175: athrow         
        //   176: aload_3         /* map4 */
        //   177: aload_2         /* path3 */
        //   178: aload_1         /* ha */
        //   179: invokedynamic   BootstrapMethod #10, accept:(Ljava/nio/file/Path;Lnet/minecraft/data/HashCache;)Ljava/util/function/BiConsumer;
        //   184: invokeinterface java/util/Map.forEach:(Ljava/util/function/BiConsumer;)V
        //   189: return         
        //    MethodParameters:
        //  Name  Flags  
        //  ----  -----
        //  ha    
        //    StackMapTable: 00 03 FF 00 49 00 07 00 07 00 C4 07 00 C6 07 00 C8 07 00 93 00 07 00 CA 00 00 F9 00 31 FA 00 34
        // 
        // The error that occurred was:
        // 
        // java.lang.IllegalStateException: Could not infer any expression.
        //     at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:374)
        //     at com.strobel.decompiler.ast.TypeAnalysis.run(TypeAnalysis.java:96)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:344)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:42)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:214)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:782)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:675)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:552)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:519)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:161)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:150)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:125)
        //     at cuchaz.enigma.SourceProvider.getSources(SourceProvider.java:85)
        //     at cuchaz.enigma.EnigmaProject$JarExport.decompileClass(EnigmaProject.java:241)
        //     at cuchaz.enigma.EnigmaProject$JarExport.lambda$decompile$1(EnigmaProject.java:230)
        //     at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        //     at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
        //     at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        //     at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        //     at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:952)
        //     at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:926)
        //     at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
        //     at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
        //     at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        //     at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        //     at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        //     at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        //     at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
        // 
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }
    
    private static Path createPath(final Path path, final ResourceLocation sm) {
        return path.resolve("data/" + sm.getNamespace() + "/loot_tables/" + sm.getPath() + ".json");
    }
    
    @Override
    public String getName() {
        return "LootTables";
    }
    
    static {
        LOGGER = LogManager.getLogger();
        GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
    }
}
