package net.minecraft.world.level.newbiome.layer;

import net.minecraft.world.level.biome.Biomes;
import net.minecraft.core.Registry;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.newbiome.area.LazyArea;
import net.minecraft.world.level.newbiome.context.LazyAreaContext;
import net.minecraft.world.level.levelgen.OverworldGeneratorSettings;
import net.minecraft.world.level.LevelType;
import net.minecraft.world.level.newbiome.context.BigContext;
import net.minecraft.world.level.newbiome.area.Area;
import java.util.function.LongFunction;
import net.minecraft.world.level.newbiome.area.AreaFactory;
import net.minecraft.world.level.newbiome.layer.traits.AreaTransformer1;

public class Layers {
    protected static final int WARM_OCEAN;
    protected static final int LUKEWARM_OCEAN;
    protected static final int OCEAN;
    protected static final int COLD_OCEAN;
    protected static final int FROZEN_OCEAN;
    protected static final int DEEP_WARM_OCEAN;
    protected static final int DEEP_LUKEWARM_OCEAN;
    protected static final int DEEP_OCEAN;
    protected static final int DEEP_COLD_OCEAN;
    protected static final int DEEP_FROZEN_OCEAN;
    
    private static <T extends Area, C extends BigContext<T>> AreaFactory<T> zoom(final long long1, final AreaTransformer1 cpz, final AreaFactory<T> cou, final int integer, final LongFunction<C> longFunction) {
        AreaFactory<T> cou2 = cou;
        for (int integer2 = 0; integer2 < integer; ++integer2) {
            cou2 = cpz.<T>run(longFunction.apply(long1 + integer2), cou2);
        }
        return cou2;
    }
    
    public static <T extends Area, C extends BigContext<T>> AreaFactory<T> getDefaultLayer(final LevelType bkd, final OverworldGeneratorSettings cbz, final LongFunction<C> longFunction) {
        AreaFactory<T> cou4 = IslandLayer.INSTANCE.<T>run((BigContext<T>)longFunction.apply(1L));
        cou4 = ZoomLayer.FUZZY.<T>run(longFunction.apply(2000L), cou4);
        cou4 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(1L), cou4);
        cou4 = ZoomLayer.NORMAL.<T>run(longFunction.apply(2001L), cou4);
        cou4 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(2L), cou4);
        cou4 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(50L), cou4);
        cou4 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(70L), cou4);
        cou4 = RemoveTooMuchOceanLayer.INSTANCE.<T>run(longFunction.apply(2L), cou4);
        AreaFactory<T> cou5 = OceanLayer.INSTANCE.<T>run((BigContext<T>)longFunction.apply(2L));
        cou5 = Layers.<T, C>zoom(2001L, ZoomLayer.NORMAL, cou5, 6, longFunction);
        cou4 = AddSnowLayer.INSTANCE.<T>run(longFunction.apply(2L), cou4);
        cou4 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(3L), cou4);
        cou4 = AddEdgeLayer.CoolWarm.INSTANCE.<T>run(longFunction.apply(2L), cou4);
        cou4 = AddEdgeLayer.HeatIce.INSTANCE.<T>run(longFunction.apply(2L), cou4);
        cou4 = AddEdgeLayer.IntroduceSpecial.INSTANCE.<T>run(longFunction.apply(3L), cou4);
        cou4 = ZoomLayer.NORMAL.<T>run(longFunction.apply(2002L), cou4);
        cou4 = ZoomLayer.NORMAL.<T>run(longFunction.apply(2003L), cou4);
        cou4 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(4L), cou4);
        cou4 = AddMushroomIslandLayer.INSTANCE.<T>run(longFunction.apply(5L), cou4);
        cou4 = AddDeepOceanLayer.INSTANCE.<T>run(longFunction.apply(4L), cou4);
        cou4 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cou4, 0, longFunction);
        final int integer6 = (bkd == LevelType.LARGE_BIOMES) ? 6 : cbz.getBiomeSize();
        final int integer7 = cbz.getRiverSize();
        AreaFactory<T> cou6 = cou4;
        cou6 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cou6, 0, longFunction);
        cou6 = RiverInitLayer.INSTANCE.<T>run(longFunction.apply(100L), cou6);
        AreaFactory<T> cou7 = cou4;
        cou7 = new BiomeInitLayer(bkd, cbz.getFixedBiome()).<T>run(longFunction.apply(200L), cou7);
        cou7 = RareBiomeLargeLayer.INSTANCE.<T>run(longFunction.apply(1001L), cou7);
        cou7 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cou7, 2, longFunction);
        cou7 = BiomeEdgeLayer.INSTANCE.<T>run(longFunction.apply(1000L), cou7);
        AreaFactory<T> cou8 = cou6;
        cou8 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cou8, 2, longFunction);
        cou7 = RegionHillsLayer.INSTANCE.<T>run(longFunction.apply(1000L), cou7, cou8);
        cou6 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cou6, 2, longFunction);
        cou6 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cou6, integer7, longFunction);
        cou6 = RiverLayer.INSTANCE.<T>run(longFunction.apply(1L), cou6);
        cou6 = SmoothLayer.INSTANCE.<T>run(longFunction.apply(1000L), cou6);
        cou7 = RareBiomeSpotLayer.INSTANCE.<T>run(longFunction.apply(1001L), cou7);
        for (int integer8 = 0; integer8 < integer6; ++integer8) {
            cou7 = ZoomLayer.NORMAL.<T>run(longFunction.apply(1000 + integer8), cou7);
            if (integer8 == 0) {
                cou7 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(3L), cou7);
            }
            if (integer8 == 1 || integer6 == 1) {
                cou7 = ShoreLayer.INSTANCE.<T>run(longFunction.apply(1000L), cou7);
            }
        }
        cou7 = SmoothLayer.INSTANCE.<T>run(longFunction.apply(1000L), cou7);
        cou7 = RiverMixerLayer.INSTANCE.<T>run(longFunction.apply(100L), cou7, cou6);
        cou7 = OceanMixerLayer.INSTANCE.<T>run(longFunction.apply(100L), cou7, cou5);
        return cou7;
    }
    
    public static Layer getDefaultLayer(final long long1, final LevelType bkd, final OverworldGeneratorSettings cbz) {
        final int integer5 = 25;
        final AreaFactory<LazyArea> cou6 = Layers.<LazyArea, LazyAreaContext>getDefaultLayer(bkd, cbz, long2 -> new LazyAreaContext(25, long1, long2));
        return new Layer(cou6);
    }
    
    public static boolean isSame(final int integer1, final int integer2) {
        if (integer1 == integer2) {
            return true;
        }
        final Biome bkt3 = Registry.BIOME.byId(integer1);
        final Biome bkt4 = Registry.BIOME.byId(integer2);
        if (bkt3 == null || bkt4 == null) {
            return false;
        }
        if (bkt3 == Biomes.WOODED_BADLANDS_PLATEAU || bkt3 == Biomes.BADLANDS_PLATEAU) {
            return bkt4 == Biomes.WOODED_BADLANDS_PLATEAU || bkt4 == Biomes.BADLANDS_PLATEAU;
        }
        return (bkt3.getBiomeCategory() != Biome.BiomeCategory.NONE && bkt4.getBiomeCategory() != Biome.BiomeCategory.NONE && bkt3.getBiomeCategory() == bkt4.getBiomeCategory()) || bkt3 == bkt4;
    }
    
    protected static boolean isOcean(final int integer) {
        return integer == Layers.WARM_OCEAN || integer == Layers.LUKEWARM_OCEAN || integer == Layers.OCEAN || integer == Layers.COLD_OCEAN || integer == Layers.FROZEN_OCEAN || integer == Layers.DEEP_WARM_OCEAN || integer == Layers.DEEP_LUKEWARM_OCEAN || integer == Layers.DEEP_OCEAN || integer == Layers.DEEP_COLD_OCEAN || integer == Layers.DEEP_FROZEN_OCEAN;
    }
    
    protected static boolean isShallowOcean(final int integer) {
        return integer == Layers.WARM_OCEAN || integer == Layers.LUKEWARM_OCEAN || integer == Layers.OCEAN || integer == Layers.COLD_OCEAN || integer == Layers.FROZEN_OCEAN;
    }
    
    static {
        WARM_OCEAN = Registry.BIOME.getId(Biomes.WARM_OCEAN);
        LUKEWARM_OCEAN = Registry.BIOME.getId(Biomes.LUKEWARM_OCEAN);
        OCEAN = Registry.BIOME.getId(Biomes.OCEAN);
        COLD_OCEAN = Registry.BIOME.getId(Biomes.COLD_OCEAN);
        FROZEN_OCEAN = Registry.BIOME.getId(Biomes.FROZEN_OCEAN);
        DEEP_WARM_OCEAN = Registry.BIOME.getId(Biomes.DEEP_WARM_OCEAN);
        DEEP_LUKEWARM_OCEAN = Registry.BIOME.getId(Biomes.DEEP_LUKEWARM_OCEAN);
        DEEP_OCEAN = Registry.BIOME.getId(Biomes.DEEP_OCEAN);
        DEEP_COLD_OCEAN = Registry.BIOME.getId(Biomes.DEEP_COLD_OCEAN);
        DEEP_FROZEN_OCEAN = Registry.BIOME.getId(Biomes.DEEP_FROZEN_OCEAN);
    }
}
