package net.minecraft.data.models;

import com.google.gson.GsonBuilder;
import org.apache.logging.log4j.LogManager;
import net.minecraft.data.models.blockstates.BlockStateGenerator;
import net.minecraft.data.models.model.DelegatedModel;
import net.minecraft.data.models.model.ModelLocationUtils;
import net.minecraft.world.item.Item;
import java.util.Set;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.core.Registry;
import net.minecraft.world.level.block.Block;
import java.util.function.BiFunction;
import com.google.gson.JsonElement;
import java.util.function.Supplier;
import java.util.Map;
import java.nio.file.Path;
import net.minecraft.data.HashCache;
import net.minecraft.data.DataGenerator;
import com.google.gson.Gson;
import org.apache.logging.log4j.Logger;
import net.minecraft.data.DataProvider;

public class ModelProvider implements DataProvider {
    private static final Logger LOGGER;
    private static final Gson GSON;
    private final DataGenerator generator;
    
    public ModelProvider(final DataGenerator hk) {
        this.generator = hk;
    }
    
    @Override
    public void run(final HashCache hm) {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     1: getfield        net/minecraft/data/models/ModelProvider.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_3         /* map4 */
        //    13: invokedynamic   BootstrapMethod #0, accept:(Ljava/util/Map;)Ljava/util/function/Consumer;
        //    18: astore          consumer5
        //    20: invokestatic    com/google/common/collect/Maps.newHashMap:()Ljava/util/HashMap;
        //    23: astore          map6
        //    25: invokestatic    com/google/common/collect/Sets.newHashSet:()Ljava/util/HashSet;
        //    28: astore          set7
        //    30: aload           map6
        //    32: invokedynamic   BootstrapMethod #1, accept:(Ljava/util/Map;)Ljava/util/function/BiConsumer;
        //    37: astore          biConsumer8
        //    39: aload           set7
        //    41: invokedynamic   BootstrapMethod #2, accept:(Ljava/util/Set;)Ljava/util/function/Consumer;
        //    46: astore          consumer9
        //    48: new             Lnet/minecraft/data/models/BlockModelGenerators;
        //    51: dup            
        //    52: aload           consumer5
        //    54: aload           biConsumer8
        //    56: aload           consumer9
        //    58: invokespecial   net/minecraft/data/models/BlockModelGenerators.<init>:(Ljava/util/function/Consumer;Ljava/util/function/BiConsumer;Ljava/util/function/Consumer;)V
        //    61: invokevirtual   net/minecraft/data/models/BlockModelGenerators.run:()V
        //    64: new             Lnet/minecraft/data/models/ItemModelGenerators;
        //    67: dup            
        //    68: aload           biConsumer8
        //    70: invokespecial   net/minecraft/data/models/ItemModelGenerators.<init>:(Ljava/util/function/BiConsumer;)V
        //    73: invokevirtual   net/minecraft/data/models/ItemModelGenerators.run:()V
        //    76: getstatic       net/minecraft/core/Registry.BLOCK:Lnet/minecraft/core/DefaultedRegistry;
        //    79: invokevirtual   net/minecraft/core/DefaultedRegistry.stream:()Ljava/util/stream/Stream;
        //    82: aload_3         /* map4 */
        //    83: invokedynamic   BootstrapMethod #3, test:(Ljava/util/Map;)Ljava/util/function/Predicate;
        //    88: invokeinterface java/util/stream/Stream.filter:(Ljava/util/function/Predicate;)Ljava/util/stream/Stream;
        //    93: invokestatic    java/util/stream/Collectors.toList:()Ljava/util/stream/Collector;
        //    96: invokeinterface java/util/stream/Stream.collect:(Ljava/util/stream/Collector;)Ljava/lang/Object;
        //   101: checkcast       Ljava/util/List;
        //   104: astore          list10
        //   106: aload           list10
        //   108: invokeinterface java/util/List.isEmpty:()Z
        //   113: ifne            144
        //   116: new             Ljava/lang/IllegalStateException;
        //   119: dup            
        //   120: new             Ljava/lang/StringBuilder;
        //   123: dup            
        //   124: invokespecial   java/lang/StringBuilder.<init>:()V
        //   127: ldc             "Missing blockstate definitions for: "
        //   129: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
        //   132: aload           list10
        //   134: invokevirtual   java/lang/StringBuilder.append:(Ljava/lang/Object;)Ljava/lang/StringBuilder;
        //   137: invokevirtual   java/lang/StringBuilder.toString:()Ljava/lang/String;
        //   140: invokespecial   java/lang/IllegalStateException.<init>:(Ljava/lang/String;)V
        //   143: athrow         
        //   144: getstatic       net/minecraft/core/Registry.BLOCK:Lnet/minecraft/core/DefaultedRegistry;
        //   147: aload           set7
        //   149: aload           map6
        //   151: invokedynamic   BootstrapMethod #4, accept:(Ljava/util/Set;Ljava/util/Map;)Ljava/util/function/Consumer;
        //   156: invokevirtual   net/minecraft/core/DefaultedRegistry.forEach:(Ljava/util/function/Consumer;)V
        //   159: aload_0         /* this */
        //   160: aload_1         /* hm */
        //   161: aload_2         /* path3 */
        //   162: aload_3         /* map4 */
        //   163: invokedynamic   BootstrapMethod #5, apply:()Ljava/util/function/BiFunction;
        //   168: invokespecial   net/minecraft/data/models/ModelProvider.saveCollection:(Lnet/minecraft/data/HashCache;Ljava/nio/file/Path;Ljava/util/Map;Ljava/util/function/BiFunction;)V
        //   171: aload_0         /* this */
        //   172: aload_1         /* hm */
        //   173: aload_2         /* path3 */
        //   174: aload           map6
        //   176: invokedynamic   BootstrapMethod #6, apply:()Ljava/util/function/BiFunction;
        //   181: invokespecial   net/minecraft/data/models/ModelProvider.saveCollection:(Lnet/minecraft/data/HashCache;Ljava/nio/file/Path;Ljava/util/Map;Ljava/util/function/BiFunction;)V
        //   184: return         
        //    MethodParameters:
        //  Name  Flags  
        //  ----  -----
        //  hm    
        //    StackMapTable: 00 01 FF 00 90 00 07 07 00 02 07 00 AF 07 00 B1 07 00 B3 00 07 00 B3 07 00 B5 00 00
        // 
        // 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 <T> void saveCollection(final HashCache hm, final Path path, final Map<T, ? extends Supplier<JsonElement>> map, final BiFunction<Path, T, Path> biFunction) {
        final Path path2;
        map.forEach((object, supplier) -> {
            path2 = biFunction.apply(path, object);
            try {
                DataProvider.save(ModelProvider.GSON, hm, supplier.get(), path2);
            }
            catch (Exception exception7) {
                ModelProvider.LOGGER.error("Couldn't save {}", path2, exception7);
            }
        });
    }
    
    private static Path createBlockStatePath(final Path path, final Block bvr) {
        final ResourceLocation uh3 = Registry.BLOCK.getKey(bvr);
        return path.resolve("assets/" + uh3.getNamespace() + "/blockstates/" + uh3.getPath() + ".json");
    }
    
    private static Path createModelPath(final Path path, final ResourceLocation uh) {
        return path.resolve("assets/" + uh.getNamespace() + "/models/" + uh.getPath() + ".json");
    }
    
    @Override
    public String getName() {
        return "Block State Definitions";
    }
    
    static {
        LOGGER = LogManager.getLogger();
        GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
    }
}
