package net.minecraft.util.datafix.fixes;

import com.mojang.datafixers.kinds.Applicative;
import com.mojang.datafixers.kinds.App;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.mojang.serialization.Codec;
import com.mojang.datafixers.Typed;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.commons.lang3.mutable.MutableBoolean;
import org.apache.commons.lang3.math.NumberUtils;
import com.mojang.serialization.OptionalDynamic;
import com.mojang.serialization.DynamicOps;
import java.util.Objects;
import java.util.stream.Stream;
import java.util.Optional;
import java.util.Locale;
import java.util.Map;
import com.mojang.serialization.Dynamic;
import com.mojang.serialization.DynamicLike;
import java.util.function.Function;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.DataFix;

public class WorldGenSettingsFix extends DataFix {
    private static final ImmutableMap<String, StructureFeatureConfiguration> DEFAULTS;
    
    public WorldGenSettingsFix(final Schema schema) {
        super(schema, true);
    }
    
    protected TypeRewriteRule makeRule() {
        return this.fixTypeEverywhereTyped("WorldGenSettings building", this.getInputSchema().getType(References.WORLD_GEN_SETTINGS), typed -> typed.update(DSL.remainderFinder(), (Function)WorldGenSettingsFix::fix));
    }
    
    private static <T> Dynamic<T> noise(final long long1, final DynamicLike<T> dynamicLike, final Dynamic<T> dynamic3, final Dynamic<T> dynamic4) {
        return (Dynamic<T>)dynamicLike.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamicLike.createString("type"), dynamicLike.createString("minecraft:noise"), dynamicLike.createString("biome_source"), (Dynamic)dynamic4, dynamicLike.createString("seed"), dynamicLike.createLong(long1), dynamicLike.createString("settings"), (Dynamic)dynamic3));
    }
    
    private static <T> Dynamic<T> vanillaBiomeSource(final Dynamic<T> dynamic, final long long2, final boolean boolean3, final boolean boolean4) {
        final ImmutableMap.Builder<Dynamic<T>, Dynamic<T>> builder6 = ImmutableMap.<Dynamic<T>, Dynamic<T>>builder().put((Dynamic<T>)dynamic.createString("type"), (Dynamic<T>)dynamic.createString("minecraft:vanilla_layered")).put((Dynamic<T>)dynamic.createString("seed"), (Dynamic<T>)dynamic.createLong(long2)).put((Dynamic<T>)dynamic.createString("large_biomes"), (Dynamic<T>)dynamic.createBoolean(boolean4));
        if (boolean3) {
            builder6.put((Dynamic<T>)dynamic.createString("legacy_biome_init_layer"), (Dynamic<T>)dynamic.createBoolean(boolean3));
        }
        return (Dynamic<T>)dynamic.createMap((Map)builder6.build());
    }
    
    private static <T> Dynamic<T> fix(final Dynamic<T> dynamic) {
        final DynamicOps<T> dynamicOps2 = (DynamicOps<T>)dynamic.getOps();
        final long long3 = dynamic.get("RandomSeed").asLong(0L);
        final Optional<String> optional6 = (Optional<String>)dynamic.get("generatorName").asString().map(string -> string.toLowerCase(Locale.ROOT)).result();
        final Optional<String> optional7 = dynamic.get("legacy_custom_options").asString().result().<Optional<String>>map(Optional::of).orElseGet(() -> {
            if (optional6.equals(Optional.<String>of("customized"))) {
                return dynamic.get("generatorOptions").asString().result();
            }
            else {
                return Optional.empty();
            }
        });
        boolean boolean8 = false;
        Dynamic<T> dynamic2;
        if (optional6.equals(Optional.<String>of("customized"))) {
            dynamic2 = WorldGenSettingsFix.<T>defaultOverworld(dynamic, long3);
        }
        else if (!optional6.isPresent()) {
            dynamic2 = WorldGenSettingsFix.<T>defaultOverworld(dynamic, long3);
        }
        else {
            final String s = optional6.get();
            switch (s) {
                case "flat": {
                    final OptionalDynamic<T> optionalDynamic11 = (OptionalDynamic<T>)dynamic.get("generatorOptions");
                    final Map<Dynamic<T>, Dynamic<T>> map12 = WorldGenSettingsFix.<T>fixFlatStructures(dynamicOps2, optionalDynamic11);
                    dynamic2 = (Dynamic<T>)dynamic.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic.createString("type"), dynamic.createString("minecraft:flat"), dynamic.createString("settings"), dynamic.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic.createString("structures"), dynamic.createMap((Map)map12), dynamic.createString("layers"), optionalDynamic11.get("layers").result().orElseGet(() -> dynamic.createList((Stream)Stream.<Dynamic>of(new Dynamic[] { dynamic.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic.createString("height"), dynamic.createInt(1), dynamic.createString("block"), dynamic.createString("minecraft:bedrock"))), dynamic.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic.createString("height"), dynamic.createInt(2), dynamic.createString("block"), dynamic.createString("minecraft:dirt"))), dynamic.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic.createString("height"), dynamic.createInt(1), dynamic.createString("block"), dynamic.createString("minecraft:grass_block"))) }))), dynamic.createString("biome"), dynamic.createString(optionalDynamic11.get("biome").asString("minecraft:plains"))))));
                    break;
                }
                case "debug_all_block_states": {
                    dynamic2 = (Dynamic<T>)dynamic.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic.createString("type"), dynamic.createString("minecraft:debug")));
                    break;
                }
                case "buffet": {
                    final OptionalDynamic<T> optionalDynamic12 = (OptionalDynamic<T>)dynamic.get("generatorOptions");
                    final OptionalDynamic<?> optionalDynamic13 = optionalDynamic12.get("chunk_generator");
                    final Optional<String> optional8 = (Optional<String>)optionalDynamic13.get("type").asString().result();
                    Dynamic<T> dynamic3;
                    if (Objects.equals(optional8, Optional.<String>of("minecraft:caves"))) {
                        dynamic3 = (Dynamic<T>)dynamic.createString("minecraft:caves");
                        boolean8 = true;
                    }
                    else if (Objects.equals(optional8, Optional.<String>of("minecraft:floating_islands"))) {
                        dynamic3 = (Dynamic<T>)dynamic.createString("minecraft:floating_islands");
                    }
                    else {
                        dynamic3 = (Dynamic<T>)dynamic.createString("minecraft:overworld");
                    }
                    final Dynamic<T> dynamic4 = (Dynamic<T>)optionalDynamic12.get("biome_source").result().orElseGet(() -> dynamic.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic.createString("type"), dynamic.createString("minecraft:fixed"))));
                    Dynamic<T> dynamic5;
                    if (dynamic4.get("type").asString().result().equals(Optional.<String>of("minecraft:fixed"))) {
                        final String string2 = dynamic4.get("options").get("biomes").asStream().findFirst().<String>flatMap(dynamic -> dynamic.asString().result()).orElse("minecraft:ocean");
                        dynamic5 = (Dynamic<T>)dynamic4.remove("options").set("biome", dynamic.createString(string2));
                    }
                    else {
                        dynamic5 = dynamic4;
                    }
                    dynamic2 = WorldGenSettingsFix.<T>noise(long3, (com.mojang.serialization.DynamicLike<T>)dynamic, dynamic3, dynamic5);
                    break;
                }
                default: {
                    final boolean boolean9 = optional6.get().equals("default");
                    final boolean boolean10 = optional6.get().equals("default_1_1") || (boolean9 && dynamic.get("generatorVersion").asInt(0) == 0);
                    final boolean boolean11 = optional6.get().equals("amplified");
                    final boolean boolean12 = optional6.get().equals("largebiomes");
                    dynamic2 = WorldGenSettingsFix.<T>noise(long3, (com.mojang.serialization.DynamicLike<T>)dynamic, (com.mojang.serialization.Dynamic<T>)dynamic.createString(boolean11 ? "minecraft:amplified" : "minecraft:overworld"), (com.mojang.serialization.Dynamic<T>)WorldGenSettingsFix.<T>vanillaBiomeSource((com.mojang.serialization.Dynamic<T>)dynamic, long3, boolean10, boolean12));
                    break;
                }
            }
        }
        final boolean boolean13 = dynamic.get("MapFeatures").asBoolean(true);
        final boolean boolean14 = dynamic.get("BonusChest").asBoolean(false);
        final ImmutableMap.Builder<T, T> builder11 = ImmutableMap.<T, T>builder();
        builder11.put((T)dynamicOps2.createString("seed"), (T)dynamicOps2.createLong(long3));
        builder11.put((T)dynamicOps2.createString("generate_features"), (T)dynamicOps2.createBoolean(boolean13));
        builder11.put((T)dynamicOps2.createString("bonus_chest"), (T)dynamicOps2.createBoolean(boolean14));
        builder11.put((T)dynamicOps2.createString("dimensions"), WorldGenSettingsFix.<T>vanillaLevels(dynamic, long3, dynamic2, boolean8));
        final ImmutableMap.Builder<Object, Object> builder12;
        final DynamicOps dynamicOps3;
        optional7.ifPresent(string -> builder12.put(dynamicOps3.createString("legacy_custom_options"), dynamicOps3.createString(string)));
        return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps2, dynamicOps2.createMap((Map)builder11.build()));
    }
    
    protected static <T> Dynamic<T> defaultOverworld(final Dynamic<T> dynamic, final long long2) {
        return WorldGenSettingsFix.<T>noise(long2, (com.mojang.serialization.DynamicLike<T>)dynamic, (com.mojang.serialization.Dynamic<T>)dynamic.createString("minecraft:overworld"), (com.mojang.serialization.Dynamic<T>)WorldGenSettingsFix.<T>vanillaBiomeSource((com.mojang.serialization.Dynamic<T>)dynamic, long2, false, false));
    }
    
    protected static <T> T vanillaLevels(final Dynamic<T> dynamic1, final long long2, final Dynamic<T> dynamic3, final boolean boolean4) {
        final DynamicOps<T> dynamicOps6 = (DynamicOps<T>)dynamic1.getOps();
        return (T)dynamicOps6.createMap((Map)ImmutableMap.of(dynamicOps6.createString("minecraft:overworld"), dynamicOps6.createMap((Map)ImmutableMap.of(dynamicOps6.createString("type"), dynamicOps6.createString("minecraft:overworld" + (boolean4 ? "_caves" : "")), dynamicOps6.createString("generator"), dynamic3.getValue())), dynamicOps6.createString("minecraft:the_nether"), dynamicOps6.createMap((Map)ImmutableMap.of(dynamicOps6.createString("type"), dynamicOps6.createString("minecraft:the_nether"), dynamicOps6.createString("generator"), WorldGenSettingsFix.noise(long2, (com.mojang.serialization.DynamicLike<Object>)dynamic1, (com.mojang.serialization.Dynamic<Object>)dynamic1.createString("minecraft:nether"), (com.mojang.serialization.Dynamic<Object>)dynamic1.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic1.createString("type"), dynamic1.createString("minecraft:multi_noise"), dynamic1.createString("seed"), dynamic1.createLong(long2), dynamic1.createString("preset"), dynamic1.createString("minecraft:nether")))).getValue())), dynamicOps6.createString("minecraft:the_end"), dynamicOps6.createMap((Map)ImmutableMap.of(dynamicOps6.createString("type"), dynamicOps6.createString("minecraft:the_end"), dynamicOps6.createString("generator"), WorldGenSettingsFix.noise(long2, (com.mojang.serialization.DynamicLike<Object>)dynamic1, (com.mojang.serialization.Dynamic<Object>)dynamic1.createString("minecraft:end"), (com.mojang.serialization.Dynamic<Object>)dynamic1.createMap((Map)ImmutableMap.<Dynamic, Dynamic>of(dynamic1.createString("type"), dynamic1.createString("minecraft:the_end"), dynamic1.createString("seed"), dynamic1.createLong(long2)))).getValue()))));
    }
    
    private static <T> Map<Dynamic<T>, Dynamic<T>> fixFlatStructures(final DynamicOps<T> dynamicOps, final OptionalDynamic<T> optionalDynamic) {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     3: dup            
        //     4: bipush          32
        //     6: invokespecial   org/apache/commons/lang3/mutable/MutableInt.<init>:(I)V
        //     9: astore_2        /* mutableInt3 */
        //    10: new             Lorg/apache/commons/lang3/mutable/MutableInt;
        //    13: dup            
        //    14: iconst_3       
        //    15: invokespecial   org/apache/commons/lang3/mutable/MutableInt.<init>:(I)V
        //    18: astore_3        /* mutableInt4 */
        //    19: new             Lorg/apache/commons/lang3/mutable/MutableInt;
        //    22: dup            
        //    23: sipush          128
        //    26: invokespecial   org/apache/commons/lang3/mutable/MutableInt.<init>:(I)V
        //    29: astore          mutableInt5
        //    31: new             Lorg/apache/commons/lang3/mutable/MutableBoolean;
        //    34: dup            
        //    35: iconst_0       
        //    36: invokespecial   org/apache/commons/lang3/mutable/MutableBoolean.<init>:(Z)V
        //    39: astore          mutableBoolean6
        //    41: invokestatic    com/google/common/collect/Maps.newHashMap:()Ljava/util/HashMap;
        //    44: astore          map7
        //    46: aload_1         /* optionalDynamic */
        //    47: invokevirtual   com/mojang/serialization/OptionalDynamic.result:()Ljava/util/Optional;
        //    50: invokevirtual   java/util/Optional.isPresent:()Z
        //    53: ifne            81
        //    56: aload           mutableBoolean6
        //    58: invokevirtual   org/apache/commons/lang3/mutable/MutableBoolean.setTrue:()V
        //    61: aload           map7
        //    63: ldc_w           "minecraft:village"
        //    66: getstatic       net/minecraft/util/datafix/fixes/WorldGenSettingsFix.DEFAULTS:Lcom/google/common/collect/ImmutableMap;
        //    69: ldc_w           "minecraft:village"
        //    72: invokevirtual   com/google/common/collect/ImmutableMap.get:(Ljava/lang/Object;)Ljava/lang/Object;
        //    75: invokeinterface java/util/Map.put:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
        //    80: pop            
        //    81: aload_1         /* optionalDynamic */
        //    82: ldc_w           "structures"
        //    85: invokevirtual   com/mojang/serialization/OptionalDynamic.get:(Ljava/lang/String;)Lcom/mojang/serialization/OptionalDynamic;
        //    88: invokedynamic   BootstrapMethod #8, apply:()Ljava/util/function/Function;
        //    93: invokevirtual   com/mojang/serialization/OptionalDynamic.flatMap:(Ljava/util/function/Function;)Lcom/mojang/serialization/DataResult;
        //    96: invokevirtual   com/mojang/serialization/DataResult.result:()Ljava/util/Optional;
        //    99: aload           mutableBoolean6
        //   101: aload_2         /* mutableInt3 */
        //   102: aload_3         /* mutableInt4 */
        //   103: aload           mutableInt5
        //   105: aload           map7
        //   107: invokedynamic   BootstrapMethod #9, accept:(Lorg/apache/commons/lang3/mutable/MutableBoolean;Lorg/apache/commons/lang3/mutable/MutableInt;Lorg/apache/commons/lang3/mutable/MutableInt;Lorg/apache/commons/lang3/mutable/MutableInt;Ljava/util/Map;)Ljava/util/function/Consumer;
        //   112: invokevirtual   java/util/Optional.ifPresent:(Ljava/util/function/Consumer;)V
        //   115: invokestatic    com/google/common/collect/ImmutableMap.builder:()Lcom/google/common/collect/ImmutableMap$Builder;
        //   118: astore          builder8
        //   120: aload           builder8
        //   122: aload_1         /* optionalDynamic */
        //   123: ldc_w           "structures"
        //   126: invokevirtual   com/mojang/serialization/OptionalDynamic.createString:(Ljava/lang/String;)Lcom/mojang/serialization/Dynamic;
        //   129: aload_1         /* optionalDynamic */
        //   130: aload           map7
        //   132: invokeinterface java/util/Map.entrySet:()Ljava/util/Set;
        //   137: invokeinterface java/util/Set.stream:()Ljava/util/stream/Stream;
        //   142: aload_1         /* optionalDynamic */
        //   143: invokedynamic   BootstrapMethod #10, apply:(Lcom/mojang/serialization/OptionalDynamic;)Ljava/util/function/Function;
        //   148: aload_0         /* dynamicOps */
        //   149: invokedynamic   BootstrapMethod #11, apply:(Lcom/mojang/serialization/DynamicOps;)Ljava/util/function/Function;
        //   154: invokestatic    java/util/stream/Collectors.toMap:(Ljava/util/function/Function;Ljava/util/function/Function;)Ljava/util/stream/Collector;
        //   157: invokeinterface java/util/stream/Stream.collect:(Ljava/util/stream/Collector;)Ljava/lang/Object;
        //   162: checkcast       Ljava/util/Map;
        //   165: invokevirtual   com/mojang/serialization/OptionalDynamic.createMap:(Ljava/util/Map;)Lcom/mojang/serialization/Dynamic;
        //   168: invokevirtual   com/google/common/collect/ImmutableMap$Builder.put:(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableMap$Builder;
        //   171: pop            
        //   172: aload           mutableBoolean6
        //   174: invokevirtual   org/apache/commons/lang3/mutable/MutableBoolean.isTrue:()Z
        //   177: ifeq            255
        //   180: aload           builder8
        //   182: aload_1         /* optionalDynamic */
        //   183: ldc_w           "stronghold"
        //   186: invokevirtual   com/mojang/serialization/OptionalDynamic.createString:(Ljava/lang/String;)Lcom/mojang/serialization/Dynamic;
        //   189: aload_1         /* optionalDynamic */
        //   190: aload_1         /* optionalDynamic */
        //   191: ldc_w           "distance"
        //   194: invokevirtual   com/mojang/serialization/OptionalDynamic.createString:(Ljava/lang/String;)Lcom/mojang/serialization/Dynamic;
        //   197: aload_1         /* optionalDynamic */
        //   198: aload_2         /* mutableInt3 */
        //   199: invokevirtual   org/apache/commons/lang3/mutable/MutableInt.getValue:()Ljava/lang/Integer;
        //   202: invokevirtual   java/lang/Integer.intValue:()I
        //   205: invokevirtual   com/mojang/serialization/OptionalDynamic.createInt:(I)Lcom/mojang/serialization/Dynamic;
        //   208: aload_1         /* optionalDynamic */
        //   209: ldc_w           "spread"
        //   212: invokevirtual   com/mojang/serialization/OptionalDynamic.createString:(Ljava/lang/String;)Lcom/mojang/serialization/Dynamic;
        //   215: aload_1         /* optionalDynamic */
        //   216: aload_3         /* mutableInt4 */
        //   217: invokevirtual   org/apache/commons/lang3/mutable/MutableInt.getValue:()Ljava/lang/Integer;
        //   220: invokevirtual   java/lang/Integer.intValue:()I
        //   223: invokevirtual   com/mojang/serialization/OptionalDynamic.createInt:(I)Lcom/mojang/serialization/Dynamic;
        //   226: aload_1         /* optionalDynamic */
        //   227: ldc_w           "count"
        //   230: invokevirtual   com/mojang/serialization/OptionalDynamic.createString:(Ljava/lang/String;)Lcom/mojang/serialization/Dynamic;
        //   233: aload_1         /* optionalDynamic */
        //   234: aload           mutableInt5
        //   236: invokevirtual   org/apache/commons/lang3/mutable/MutableInt.getValue:()Ljava/lang/Integer;
        //   239: invokevirtual   java/lang/Integer.intValue:()I
        //   242: invokevirtual   com/mojang/serialization/OptionalDynamic.createInt:(I)Lcom/mojang/serialization/Dynamic;
        //   245: invokestatic    com/google/common/collect/ImmutableMap.of:(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableMap;
        //   248: invokevirtual   com/mojang/serialization/OptionalDynamic.createMap:(Ljava/util/Map;)Lcom/mojang/serialization/Dynamic;
        //   251: invokevirtual   com/google/common/collect/ImmutableMap$Builder.put:(Ljava/lang/Object;Ljava/lang/Object;)Lcom/google/common/collect/ImmutableMap$Builder;
        //   254: pop            
        //   255: aload           builder8
        //   257: invokevirtual   com/google/common/collect/ImmutableMap$Builder.build:()Lcom/google/common/collect/ImmutableMap;
        //   260: areturn        
        //    Signature:
        //  <T:Ljava/lang/Object;>(Lcom/mojang/serialization/DynamicOps<TT;>;Lcom/mojang/serialization/OptionalDynamic<TT;>;)Ljava/util/Map<Lcom/mojang/serialization/Dynamic<TT;>;Lcom/mojang/serialization/Dynamic<TT;>;>;
        //    MethodParameters:
        //  Name             Flags  
        //  ---------------  -----
        //  dynamicOps       
        //  optionalDynamic  
        //    StackMapTable: 00 02 FF 00 51 00 07 07 00 F4 07 00 B0 07 01 FA 07 01 FA 07 01 FA 07 01 FF 07 02 16 00 00 FF 00 AD 00 08 00 00 00 00 00 00 00 07 00 0A 00 00
        // 
        // The error that occurred was:
        // 
        // java.lang.NullPointerException
        //     at com.strobel.decompiler.languages.java.ast.NameVariables.generateNameForVariable(NameVariables.java:264)
        //     at com.strobel.decompiler.languages.java.ast.NameVariables.assignNamesToVariables(NameVariables.java:198)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:276)
        //     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 int getInt(final String string, final int integer) {
        return NumberUtils.toInt(string, integer);
    }
    
    private static int getInt(final String string, final int integer2, final int integer3) {
        return Math.max(integer3, getInt(string, integer2));
    }
    
    private static void setSpacing(final Map<String, StructureFeatureConfiguration> map, final String string2, final String string3, final int integer) {
        final StructureFeatureConfiguration a5 = map.getOrDefault(string2, WorldGenSettingsFix.DEFAULTS.get(string2));
        final int integer2 = getInt(string3, a5.spacing, integer);
        map.put(string2, new StructureFeatureConfiguration(integer2, a5.separation, a5.salt));
    }
    
    static {
        DEFAULTS = ImmutableMap.<String, StructureFeatureConfiguration>builder().put("minecraft:village", new StructureFeatureConfiguration(32, 8, 10387312)).put("minecraft:desert_pyramid", new StructureFeatureConfiguration(32, 8, 14357617)).put("minecraft:igloo", new StructureFeatureConfiguration(32, 8, 14357618)).put("minecraft:jungle_pyramid", new StructureFeatureConfiguration(32, 8, 14357619)).put("minecraft:swamp_hut", new StructureFeatureConfiguration(32, 8, 14357620)).put("minecraft:pillager_outpost", new StructureFeatureConfiguration(32, 8, 165745296)).put("minecraft:monument", new StructureFeatureConfiguration(32, 5, 10387313)).put("minecraft:endcity", new StructureFeatureConfiguration(20, 11, 10387313)).put("minecraft:mansion", new StructureFeatureConfiguration(80, 20, 10387319)).build();
    }
    
    static final class StructureFeatureConfiguration {
        public static final Codec<StructureFeatureConfiguration> CODEC;
        private final int spacing;
        private final int separation;
        private final int salt;
        
        public StructureFeatureConfiguration(final int integer1, final int integer2, final int integer3) {
            this.spacing = integer1;
            this.separation = integer2;
            this.salt = integer3;
        }
        
        public <T> Dynamic<T> serialize(final DynamicOps<T> dynamicOps) {
            return (Dynamic<T>)new Dynamic((DynamicOps)dynamicOps, StructureFeatureConfiguration.CODEC.encodeStart((DynamicOps)dynamicOps, this).result().orElse(dynamicOps.emptyMap()));
        }
        
        static {
            CODEC = RecordCodecBuilder.create(instance -> ((RecordCodecBuilder.Instance)instance).group((App)Codec.INT.fieldOf("spacing").forGetter(a -> a.spacing), (App)Codec.INT.fieldOf("separation").forGetter(a -> a.separation), (App)Codec.INT.fieldOf("salt").forGetter(a -> a.salt)).apply(instance, StructureFeatureConfiguration::new));
        }
    }
}
