    001package net.minecraft.world.gen.layer;
    002
    003import net.minecraft.world.WorldType;
    004
    005import net.minecraftforge.common.*;
    006import net.minecraftforge.event.terraingen.*;
    007
    008public abstract class GenLayer
    009{
    010    /** seed from World#getWorldSeed that is used in the LCG prng */
    011    private long worldGenSeed;
    012
    013    /** parent GenLayer that was provided via the constructor */
    014    protected GenLayer parent;
    015
    016    /**
    017     * final part of the LCG prng that uses the chunk X, Z coords along with the other two seeds to generate
    018     * pseudorandom numbers
    019     */
    020    private long chunkSeed;
    021
    022    /** base seed to the LCG prng provided via the constructor */
    023    private long baseSeed;
    024
    025    /**
    026     * the first array item is a linked list of the bioms, the second is the zoom function, the third is the same as the
    027     * first.
    028     */
    029    public static GenLayer[] initializeAllBiomeGenerators(long par0, WorldType par2WorldType)
    030    {
    031        GenLayerIsland var3 = new GenLayerIsland(1L);
    032        GenLayerFuzzyZoom var9 = new GenLayerFuzzyZoom(2000L, var3);
    033        GenLayerAddIsland var10 = new GenLayerAddIsland(1L, var9);
    034        GenLayerZoom var11 = new GenLayerZoom(2001L, var10);
    035        var10 = new GenLayerAddIsland(2L, var11);
    036        GenLayerAddSnow var12 = new GenLayerAddSnow(2L, var10);
    037        var11 = new GenLayerZoom(2002L, var12);
    038        var10 = new GenLayerAddIsland(3L, var11);
    039        var11 = new GenLayerZoom(2003L, var10);
    040        var10 = new GenLayerAddIsland(4L, var11);
    041        GenLayerAddMushroomIsland var16 = new GenLayerAddMushroomIsland(5L, var10);
    042        byte var4 = 4;
    043
    044        if (par2WorldType == WorldType.LARGE_BIOMES)
    045        {
    046            var4 = 6;
    047        }
    048        var4 = getModdedBiomeSize(par2WorldType, var4);
    049
    050        GenLayer var5 = GenLayerZoom.func_75915_a(1000L, var16, 0);
    051        GenLayerRiverInit var13 = new GenLayerRiverInit(100L, var5);
    052        var5 = GenLayerZoom.func_75915_a(1000L, var13, var4 + 2);
    053        GenLayerRiver var14 = new GenLayerRiver(1L, var5);
    054        GenLayerSmooth var15 = new GenLayerSmooth(1000L, var14);
    055        GenLayer var6 = GenLayerZoom.func_75915_a(1000L, var16, 0);
    056        GenLayerBiome var17 = new GenLayerBiome(200L, var6, par2WorldType);
    057        var6 = GenLayerZoom.func_75915_a(1000L, var17, 2);
    058        Object var18 = new GenLayerHills(1000L, var6);
    059
    060        for (int var7 = 0; var7 < var4; ++var7)
    061        {
    062            var18 = new GenLayerZoom((long)(1000 + var7), (GenLayer)var18);
    063
    064            if (var7 == 0)
    065            {
    066                var18 = new GenLayerAddIsland(3L, (GenLayer)var18);
    067            }
    068
    069            if (var7 == 1)
    070            {
    071                var18 = new GenLayerShore(1000L, (GenLayer)var18);
    072            }
    073
    074            if (var7 == 1)
    075            {
    076                var18 = new GenLayerSwampRivers(1000L, (GenLayer)var18);
    077            }
    078        }
    079
    080        GenLayerSmooth var19 = new GenLayerSmooth(1000L, (GenLayer)var18);
    081        GenLayerRiverMix var20 = new GenLayerRiverMix(100L, var19, var15);
    082        GenLayerVoronoiZoom var8 = new GenLayerVoronoiZoom(10L, var20);
    083        var20.initWorldGenSeed(par0);
    084        var8.initWorldGenSeed(par0);
    085        return new GenLayer[] {var20, var8, var20};
    086    }
    087
    088    public GenLayer(long par1)
    089    {
    090        this.baseSeed = par1;
    091        this.baseSeed *= this.baseSeed * 6364136223846793005L + 1442695040888963407L;
    092        this.baseSeed += par1;
    093        this.baseSeed *= this.baseSeed * 6364136223846793005L + 1442695040888963407L;
    094        this.baseSeed += par1;
    095        this.baseSeed *= this.baseSeed * 6364136223846793005L + 1442695040888963407L;
    096        this.baseSeed += par1;
    097    }
    098
    099    /**
    100     * Initialize layer's local worldGenSeed based on its own baseSeed and the world's global seed (passed in as an
    101     * argument).
    102     */
    103    public void initWorldGenSeed(long par1)
    104    {
    105        this.worldGenSeed = par1;
    106
    107        if (this.parent != null)
    108        {
    109            this.parent.initWorldGenSeed(par1);
    110        }
    111
    112        this.worldGenSeed *= this.worldGenSeed * 6364136223846793005L + 1442695040888963407L;
    113        this.worldGenSeed += this.baseSeed;
    114        this.worldGenSeed *= this.worldGenSeed * 6364136223846793005L + 1442695040888963407L;
    115        this.worldGenSeed += this.baseSeed;
    116        this.worldGenSeed *= this.worldGenSeed * 6364136223846793005L + 1442695040888963407L;
    117        this.worldGenSeed += this.baseSeed;
    118    }
    119
    120    /**
    121     * Initialize layer's current chunkSeed based on the local worldGenSeed and the (x,z) chunk coordinates.
    122     */
    123    public void initChunkSeed(long par1, long par3)
    124    {
    125        this.chunkSeed = this.worldGenSeed;
    126        this.chunkSeed *= this.chunkSeed * 6364136223846793005L + 1442695040888963407L;
    127        this.chunkSeed += par1;
    128        this.chunkSeed *= this.chunkSeed * 6364136223846793005L + 1442695040888963407L;
    129        this.chunkSeed += par3;
    130        this.chunkSeed *= this.chunkSeed * 6364136223846793005L + 1442695040888963407L;
    131        this.chunkSeed += par1;
    132        this.chunkSeed *= this.chunkSeed * 6364136223846793005L + 1442695040888963407L;
    133        this.chunkSeed += par3;
    134    }
    135
    136    /**
    137     * returns a LCG pseudo random number from [0, x). Args: int x
    138     */
    139    protected int nextInt(int par1)
    140    {
    141        int var2 = (int)((this.chunkSeed >> 24) % (long)par1);
    142
    143        if (var2 < 0)
    144        {
    145            var2 += par1;
    146        }
    147
    148        this.chunkSeed *= this.chunkSeed * 6364136223846793005L + 1442695040888963407L;
    149        this.chunkSeed += this.worldGenSeed;
    150        return var2;
    151    }
    152
    153    /**
    154     * Returns a list of integer values generated by this layer. These may be interpreted as temperatures, rainfall
    155     * amounts, or biomeList[] indices based on the particular GenLayer subclass.
    156     */
    157    public abstract int[] getInts(int var1, int var2, int var3, int var4);
    158
    159    public static byte getModdedBiomeSize(WorldType worldType, byte original)
    160    {
    161        WorldTypeEvent.BiomeSize event = new WorldTypeEvent.BiomeSize(worldType, original);
    162        MinecraftForge.TERRAIN_GEN_BUS.post(event);
    163        return event.newSize;
    164    }
    165}