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.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 cyo, final AreaFactory<T> cxj, final int integer, final LongFunction<C> longFunction) {
        AreaFactory<T> cxj2 = cxj;
        for (int integer2 = 0; integer2 < integer; ++integer2) {
            cxj2 = cyo.<T>run(longFunction.apply(long1 + integer2), cxj2);
        }
        return cxj2;
    }
    
    private static <T extends Area, C extends BigContext<T>> AreaFactory<T> getDefaultLayer(final boolean boolean1, final int integer2, final int integer3, final LongFunction<C> longFunction) {
        AreaFactory<T> cxj5 = IslandLayer.INSTANCE.<T>run((BigContext<T>)longFunction.apply(1L));
        cxj5 = ZoomLayer.FUZZY.<T>run(longFunction.apply(2000L), cxj5);
        cxj5 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(1L), cxj5);
        cxj5 = ZoomLayer.NORMAL.<T>run(longFunction.apply(2001L), cxj5);
        cxj5 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(2L), cxj5);
        cxj5 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(50L), cxj5);
        cxj5 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(70L), cxj5);
        cxj5 = RemoveTooMuchOceanLayer.INSTANCE.<T>run(longFunction.apply(2L), cxj5);
        AreaFactory<T> cxj6 = OceanLayer.INSTANCE.<T>run((BigContext<T>)longFunction.apply(2L));
        cxj6 = Layers.<T, C>zoom(2001L, ZoomLayer.NORMAL, cxj6, 6, longFunction);
        cxj5 = AddSnowLayer.INSTANCE.<T>run(longFunction.apply(2L), cxj5);
        cxj5 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(3L), cxj5);
        cxj5 = AddEdgeLayer.CoolWarm.INSTANCE.<T>run(longFunction.apply(2L), cxj5);
        cxj5 = AddEdgeLayer.HeatIce.INSTANCE.<T>run(longFunction.apply(2L), cxj5);
        cxj5 = AddEdgeLayer.IntroduceSpecial.INSTANCE.<T>run(longFunction.apply(3L), cxj5);
        cxj5 = ZoomLayer.NORMAL.<T>run(longFunction.apply(2002L), cxj5);
        cxj5 = ZoomLayer.NORMAL.<T>run(longFunction.apply(2003L), cxj5);
        cxj5 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(4L), cxj5);
        cxj5 = AddMushroomIslandLayer.INSTANCE.<T>run(longFunction.apply(5L), cxj5);
        cxj5 = AddDeepOceanLayer.INSTANCE.<T>run(longFunction.apply(4L), cxj5);
        AreaFactory<T> cxj7;
        cxj5 = (cxj7 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cxj5, 0, longFunction));
        cxj7 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cxj7, 0, longFunction);
        cxj7 = RiverInitLayer.INSTANCE.<T>run(longFunction.apply(100L), cxj7);
        AreaFactory<T> cxj8 = cxj5;
        cxj8 = new BiomeInitLayer(boolean1).<T>run(longFunction.apply(200L), cxj8);
        cxj8 = RareBiomeLargeLayer.INSTANCE.<T>run(longFunction.apply(1001L), cxj8);
        cxj8 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cxj8, 2, longFunction);
        cxj8 = BiomeEdgeLayer.INSTANCE.<T>run(longFunction.apply(1000L), cxj8);
        AreaFactory<T> cxj9 = cxj7;
        cxj9 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cxj9, 2, longFunction);
        cxj8 = RegionHillsLayer.INSTANCE.<T>run(longFunction.apply(1000L), cxj8, cxj9);
        cxj7 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cxj7, 2, longFunction);
        cxj7 = Layers.<T, C>zoom(1000L, ZoomLayer.NORMAL, cxj7, integer3, longFunction);
        cxj7 = RiverLayer.INSTANCE.<T>run(longFunction.apply(1L), cxj7);
        cxj7 = SmoothLayer.INSTANCE.<T>run(longFunction.apply(1000L), cxj7);
        cxj8 = RareBiomeSpotLayer.INSTANCE.<T>run(longFunction.apply(1001L), cxj8);
        for (int integer4 = 0; integer4 < integer2; ++integer4) {
            cxj8 = ZoomLayer.NORMAL.<T>run(longFunction.apply(1000 + integer4), cxj8);
            if (integer4 == 0) {
                cxj8 = AddIslandLayer.INSTANCE.<T>run(longFunction.apply(3L), cxj8);
            }
            if (integer4 == 1 || integer2 == 1) {
                cxj8 = ShoreLayer.INSTANCE.<T>run(longFunction.apply(1000L), cxj8);
            }
        }
        cxj8 = SmoothLayer.INSTANCE.<T>run(longFunction.apply(1000L), cxj8);
        cxj8 = RiverMixerLayer.INSTANCE.<T>run(longFunction.apply(100L), cxj8, cxj7);
        cxj8 = OceanMixerLayer.INSTANCE.<T>run(longFunction.apply(100L), cxj8, cxj6);
        return cxj8;
    }
    
    public static Layer getDefaultLayer(final long long1, final boolean boolean2, final int integer3, final int integer4) {
        final int integer5 = 25;
        final AreaFactory<LazyArea> cxj7 = Layers.<LazyArea, LazyAreaContext>getDefaultLayer(boolean2, integer3, integer4, long2 -> new LazyAreaContext(25, long1, long2));
        return new Layer(cxj7);
    }
    
    public static boolean isSame(final int integer1, final int integer2) {
        if (integer1 == integer2) {
            return true;
        }
        final Biome bre3 = Registry.BIOME.byId(integer1);
        final Biome bre4 = Registry.BIOME.byId(integer2);
        if (bre3 == null || bre4 == null) {
            return false;
        }
        if (bre3 == Biomes.WOODED_BADLANDS_PLATEAU || bre3 == Biomes.BADLANDS_PLATEAU) {
            return bre4 == Biomes.WOODED_BADLANDS_PLATEAU || bre4 == Biomes.BADLANDS_PLATEAU;
        }
        return (bre3.getBiomeCategory() != Biome.BiomeCategory.NONE && bre4.getBiomeCategory() != Biome.BiomeCategory.NONE && bre3.getBiomeCategory() == bre4.getBiomeCategory()) || bre3 == bre4;
    }
    
    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);
    }
}
