    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.ArrayList;
    006    import java.util.List;
    007    import java.util.Random;
    008
    009    public class WorldChunkManager
    010    {
    011        private GenLayer genBiomes;
    012
    013        /** A GenLayer containing the indices into BiomeGenBase.biomeList[] */
    014        private GenLayer biomeIndexLayer;
    015
    016        /** The BiomeCache object for this world. */
    017        private BiomeCache biomeCache;
    018
    019        /** A list of biomes that the player can spawn in. */
    020        private List biomesToSpawnIn;
    021
    022        protected WorldChunkManager()
    023        {
    024            this.biomeCache = new BiomeCache(this);
    025            this.biomesToSpawnIn = new ArrayList();
    026            this.biomesToSpawnIn.add(BiomeGenBase.forest);
    027            this.biomesToSpawnIn.add(BiomeGenBase.plains);
    028            this.biomesToSpawnIn.add(BiomeGenBase.taiga);
    029            this.biomesToSpawnIn.add(BiomeGenBase.taigaHills);
    030            this.biomesToSpawnIn.add(BiomeGenBase.forestHills);
    031            this.biomesToSpawnIn.add(BiomeGenBase.jungle);
    032            this.biomesToSpawnIn.add(BiomeGenBase.jungleHills);
    033        }
    034
    035        public WorldChunkManager(long par1, WorldType par3WorldType)
    036        {
    037            this();
    038            GenLayer[] var4 = GenLayer.initializeAllBiomeGenerators(par1, par3WorldType);
    039            this.genBiomes = var4[0];
    040            this.biomeIndexLayer = var4[1];
    041        }
    042
    043        public WorldChunkManager(World par1World)
    044        {
    045            this(par1World.getSeed(), par1World.getWorldInfo().getTerrainType());
    046        }
    047
    048        /**
    049         * Gets the list of valid biomes for the player to spawn in.
    050         */
    051        public List getBiomesToSpawnIn()
    052        {
    053            return this.biomesToSpawnIn;
    054        }
    055
    056        /**
    057         * Returns the BiomeGenBase related to the x, z position on the world.
    058         */
    059        public BiomeGenBase getBiomeGenAt(int par1, int par2)
    060        {
    061            return this.biomeCache.getBiomeGenAt(par1, par2);
    062        }
    063
    064        /**
    065         * Returns a list of rainfall values for the specified blocks. Args: listToReuse, x, z, width, length.
    066         */
    067        public float[] getRainfall(float[] par1ArrayOfFloat, int par2, int par3, int par4, int par5)
    068        {
    069            IntCache.resetIntCache();
    070
    071            if (par1ArrayOfFloat == null || par1ArrayOfFloat.length < par4 * par5)
    072            {
    073                par1ArrayOfFloat = new float[par4 * par5];
    074            }
    075
    076            int[] var6 = this.biomeIndexLayer.getInts(par2, par3, par4, par5);
    077
    078            for (int var7 = 0; var7 < par4 * par5; ++var7)
    079            {
    080                float var8 = (float)BiomeGenBase.biomeList[var6[var7]].getIntRainfall() / 65536.0F;
    081
    082                if (var8 > 1.0F)
    083                {
    084                    var8 = 1.0F;
    085                }
    086
    087                par1ArrayOfFloat[var7] = var8;
    088            }
    089
    090            return par1ArrayOfFloat;
    091        }
    092
    093        @SideOnly(Side.CLIENT)
    094
    095        /**
    096         * Return an adjusted version of a given temperature based on the y height
    097         */
    098        public float getTemperatureAtHeight(float par1, int par2)
    099        {
    100            return par1;
    101        }
    102
    103        /**
    104         * Returns a list of temperatures to use for the specified blocks.  Args: listToReuse, x, y, width, length
    105         */
    106        public float[] getTemperatures(float[] par1ArrayOfFloat, int par2, int par3, int par4, int par5)
    107        {
    108            IntCache.resetIntCache();
    109
    110            if (par1ArrayOfFloat == null || par1ArrayOfFloat.length < par4 * par5)
    111            {
    112                par1ArrayOfFloat = new float[par4 * par5];
    113            }
    114
    115            int[] var6 = this.biomeIndexLayer.getInts(par2, par3, par4, par5);
    116
    117            for (int var7 = 0; var7 < par4 * par5; ++var7)
    118            {
    119                float var8 = (float)BiomeGenBase.biomeList[var6[var7]].getIntTemperature() / 65536.0F;
    120
    121                if (var8 > 1.0F)
    122                {
    123                    var8 = 1.0F;
    124                }
    125
    126                par1ArrayOfFloat[var7] = var8;
    127            }
    128
    129            return par1ArrayOfFloat;
    130        }
    131
    132        /**
    133         * Returns an array of biomes for the location input.
    134         */
    135        public BiomeGenBase[] getBiomesForGeneration(BiomeGenBase[] par1ArrayOfBiomeGenBase, int par2, int par3, int par4, int par5)
    136        {
    137            IntCache.resetIntCache();
    138
    139            if (par1ArrayOfBiomeGenBase == null || par1ArrayOfBiomeGenBase.length < par4 * par5)
    140            {
    141                par1ArrayOfBiomeGenBase = new BiomeGenBase[par4 * par5];
    142            }
    143
    144            int[] var6 = this.genBiomes.getInts(par2, par3, par4, par5);
    145
    146            for (int var7 = 0; var7 < par4 * par5; ++var7)
    147            {
    148                par1ArrayOfBiomeGenBase[var7] = BiomeGenBase.biomeList[var6[var7]];
    149            }
    150
    151            return par1ArrayOfBiomeGenBase;
    152        }
    153
    154        /**
    155         * Returns biomes to use for the blocks and loads the other data like temperature and humidity onto the
    156         * WorldChunkManager Args: oldBiomeList, x, z, width, depth
    157         */
    158        public BiomeGenBase[] loadBlockGeneratorData(BiomeGenBase[] par1ArrayOfBiomeGenBase, int par2, int par3, int par4, int par5)
    159        {
    160            return this.getBiomeGenAt(par1ArrayOfBiomeGenBase, par2, par3, par4, par5, true);
    161        }
    162
    163        /**
    164         * Return a list of biomes for the specified blocks. Args: listToReuse, x, y, width, length, cacheFlag (if false,
    165         * don't check biomeCache to avoid infinite loop in BiomeCacheBlock)
    166         */
    167        public BiomeGenBase[] getBiomeGenAt(BiomeGenBase[] par1ArrayOfBiomeGenBase, int par2, int par3, int par4, int par5, boolean par6)
    168        {
    169            IntCache.resetIntCache();
    170
    171            if (par1ArrayOfBiomeGenBase == null || par1ArrayOfBiomeGenBase.length < par4 * par5)
    172            {
    173                par1ArrayOfBiomeGenBase = new BiomeGenBase[par4 * par5];
    174            }
    175
    176            if (par6 && par4 == 16 && par5 == 16 && (par2 & 15) == 0 && (par3 & 15) == 0)
    177            {
    178                BiomeGenBase[] var9 = this.biomeCache.getCachedBiomes(par2, par3);
    179                System.arraycopy(var9, 0, par1ArrayOfBiomeGenBase, 0, par4 * par5);
    180                return par1ArrayOfBiomeGenBase;
    181            }
    182            else
    183            {
    184                int[] var7 = this.biomeIndexLayer.getInts(par2, par3, par4, par5);
    185
    186                for (int var8 = 0; var8 < par4 * par5; ++var8)
    187                {
    188                    par1ArrayOfBiomeGenBase[var8] = BiomeGenBase.biomeList[var7[var8]];
    189                }
    190
    191                return par1ArrayOfBiomeGenBase;
    192            }
    193        }
    194
    195        /**
    196         * checks given Chunk's Biomes against List of allowed ones
    197         */
    198        public boolean areBiomesViable(int par1, int par2, int par3, List par4List)
    199        {
    200            int var5 = par1 - par3 >> 2;
    201            int var6 = par2 - par3 >> 2;
    202            int var7 = par1 + par3 >> 2;
    203            int var8 = par2 + par3 >> 2;
    204            int var9 = var7 - var5 + 1;
    205            int var10 = var8 - var6 + 1;
    206            int[] var11 = this.genBiomes.getInts(var5, var6, var9, var10);
    207
    208            for (int var12 = 0; var12 < var9 * var10; ++var12)
    209            {
    210                BiomeGenBase var13 = BiomeGenBase.biomeList[var11[var12]];
    211
    212                if (!par4List.contains(var13))
    213                {
    214                    return false;
    215                }
    216            }
    217
    218            return true;
    219        }
    220
    221        /**
    222         * Finds a valid position within a range, that is in one of the listed biomes. Searches {par1,par2} +-par3 blocks.
    223         * Strongly favors positive y positions.
    224         */
    225        public ChunkPosition findBiomePosition(int par1, int par2, int par3, List par4List, Random par5Random)
    226        {
    227            int var6 = par1 - par3 >> 2;
    228            int var7 = par2 - par3 >> 2;
    229            int var8 = par1 + par3 >> 2;
    230            int var9 = par2 + par3 >> 2;
    231            int var10 = var8 - var6 + 1;
    232            int var11 = var9 - var7 + 1;
    233            int[] var12 = this.genBiomes.getInts(var6, var7, var10, var11);
    234            ChunkPosition var13 = null;
    235            int var14 = 0;
    236
    237            for (int var15 = 0; var15 < var12.length; ++var15)
    238            {
    239                int var16 = var6 + var15 % var10 << 2;
    240                int var17 = var7 + var15 / var10 << 2;
    241                BiomeGenBase var18 = BiomeGenBase.biomeList[var12[var15]];
    242
    243                if (par4List.contains(var18) && (var13 == null || par5Random.nextInt(var14 + 1) == 0))
    244                {
    245                    var13 = new ChunkPosition(var16, 0, var17);
    246                    ++var14;
    247                }
    248            }
    249
    250            return var13;
    251        }
    252
    253        /**
    254         * Calls the WorldChunkManager's biomeCache.cleanupCache()
    255         */
    256        public void cleanupCache()
    257        {
    258            this.biomeCache.cleanupCache();
    259        }
    260    }