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