    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 genlayerisland = new GenLayerIsland(1L);
    032        GenLayerFuzzyZoom genlayerfuzzyzoom = new GenLayerFuzzyZoom(2000L, genlayerisland);
    033        GenLayerAddIsland genlayeraddisland = new GenLayerAddIsland(1L, genlayerfuzzyzoom);
    034        GenLayerZoom genlayerzoom = new GenLayerZoom(2001L, genlayeraddisland);
    035        genlayeraddisland = new GenLayerAddIsland(2L, genlayerzoom);
    036        GenLayerAddSnow genlayeraddsnow = new GenLayerAddSnow(2L, genlayeraddisland);
    037        genlayerzoom = new GenLayerZoom(2002L, genlayeraddsnow);
    038        genlayeraddisland = new GenLayerAddIsland(3L, genlayerzoom);
    039        genlayerzoom = new GenLayerZoom(2003L, genlayeraddisland);
    040        genlayeraddisland = new GenLayerAddIsland(4L, genlayerzoom);
    041        GenLayerAddMushroomIsland genlayeraddmushroomisland = new GenLayerAddMushroomIsland(5L, genlayeraddisland);
    042        byte b0 = 4;
    043
    044        if (par2WorldType == WorldType.LARGE_BIOMES)
    045        {
    046            b0 = 6;
    047        }
    048        b0 = getModdedBiomeSize(par2WorldType, b0);
    049
    050        GenLayer genlayer = GenLayerZoom.func_75915_a(1000L, genlayeraddmushroomisland, 0);
    051        GenLayerRiverInit genlayerriverinit = new GenLayerRiverInit(100L, genlayer);
    052        genlayer = GenLayerZoom.func_75915_a(1000L, genlayerriverinit, b0 + 2);
    053        GenLayerRiver genlayerriver = new GenLayerRiver(1L, genlayer);
    054        GenLayerSmooth genlayersmooth = new GenLayerSmooth(1000L, genlayerriver);
    055        GenLayer genlayer1 = GenLayerZoom.func_75915_a(1000L, genlayeraddmushroomisland, 0);
    056        GenLayerBiome genlayerbiome = new GenLayerBiome(200L, genlayer1, par2WorldType);
    057        genlayer1 = GenLayerZoom.func_75915_a(1000L, genlayerbiome, 2);
    058        Object object = new GenLayerHills(1000L, genlayer1);
    059
    060        for (int j = 0; j < b0; ++j)
    061        {
    062            object = new GenLayerZoom((long)(1000 + j), (GenLayer)object);
    063
    064            if (j == 0)
    065            {
    066                object = new GenLayerAddIsland(3L, (GenLayer)object);
    067            }
    068
    069            if (j == 1)
    070            {
    071                object = new GenLayerShore(1000L, (GenLayer)object);
    072            }
    073
    074            if (j == 1)
    075            {
    076                object = new GenLayerSwampRivers(1000L, (GenLayer)object);
    077            }
    078        }
    079
    080        GenLayerSmooth genlayersmooth1 = new GenLayerSmooth(1000L, (GenLayer)object);
    081        GenLayerRiverMix genlayerrivermix = new GenLayerRiverMix(100L, genlayersmooth1, genlayersmooth);
    082        GenLayerVoronoiZoom genlayervoronoizoom = new GenLayerVoronoiZoom(10L, genlayerrivermix);
    083        genlayerrivermix.initWorldGenSeed(par0);
    084        genlayervoronoizoom.initWorldGenSeed(par0);
    085        return new GenLayer[] {genlayerrivermix, genlayervoronoizoom, genlayerrivermix};
    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 j = (int)((this.chunkSeed >> 24) % (long)par1);
    142
    143        if (j < 0)
    144        {
    145            j += par1;
    146        }
    147
    148        this.chunkSeed *= this.chunkSeed * 6364136223846793005L + 1442695040888963407L;
    149        this.chunkSeed += this.worldGenSeed;
    150        return j;
    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 i, int j, int k, int l);
    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}