001    package net.minecraft.src;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.SideOnly;
005    import java.awt.Color;
006    import java.util.ArrayList;
007    import java.util.List;
008    import java.util.Random;
009    
010    public abstract class BiomeGenBase
011    {
012        /** An array of all the biomes, indexed by biome id. */
013        public static final BiomeGenBase[] biomeList = new BiomeGenBase[256];
014        public static final BiomeGenBase ocean = (new BiomeGenOcean(0)).setColor(112).setBiomeName("Ocean").setMinMaxHeight(-1.0F, 0.4F);
015        public static final BiomeGenBase plains = (new BiomeGenPlains(1)).setColor(9286496).setBiomeName("Plains").setTemperatureRainfall(0.8F, 0.4F);
016        public static final BiomeGenBase desert = (new BiomeGenDesert(2)).setColor(16421912).setBiomeName("Desert").setDisableRain().setTemperatureRainfall(2.0F, 0.0F).setMinMaxHeight(0.1F, 0.2F);
017        public static final BiomeGenBase extremeHills = (new BiomeGenHills(3)).setColor(6316128).setBiomeName("Extreme Hills").setMinMaxHeight(0.3F, 1.5F).setTemperatureRainfall(0.2F, 0.3F);
018        public static final BiomeGenBase forest = (new BiomeGenForest(4)).setColor(353825).setBiomeName("Forest").func_76733_a(5159473).setTemperatureRainfall(0.7F, 0.8F);
019        public static final BiomeGenBase taiga = (new BiomeGenTaiga(5)).setColor(747097).setBiomeName("Taiga").func_76733_a(5159473).setEnableSnow().setTemperatureRainfall(0.05F, 0.8F).setMinMaxHeight(0.1F, 0.4F);
020        public static final BiomeGenBase swampland = (new BiomeGenSwamp(6)).setColor(522674).setBiomeName("Swampland").func_76733_a(9154376).setMinMaxHeight(-0.2F, 0.1F).setTemperatureRainfall(0.8F, 0.9F);
021        public static final BiomeGenBase river = (new BiomeGenRiver(7)).setColor(255).setBiomeName("River").setMinMaxHeight(-0.5F, 0.0F);
022        public static final BiomeGenBase hell = (new BiomeGenHell(8)).setColor(16711680).setBiomeName("Hell").setDisableRain().setTemperatureRainfall(2.0F, 0.0F);
023    
024        /** Is the biome used for sky world. */
025        public static final BiomeGenBase sky = (new BiomeGenEnd(9)).setColor(8421631).setBiomeName("Sky").setDisableRain();
026        public static final BiomeGenBase frozenOcean = (new BiomeGenOcean(10)).setColor(9474208).setBiomeName("FrozenOcean").setEnableSnow().setMinMaxHeight(-1.0F, 0.5F).setTemperatureRainfall(0.0F, 0.5F);
027        public static final BiomeGenBase frozenRiver = (new BiomeGenRiver(11)).setColor(10526975).setBiomeName("FrozenRiver").setEnableSnow().setMinMaxHeight(-0.5F, 0.0F).setTemperatureRainfall(0.0F, 0.5F);
028        public static final BiomeGenBase icePlains = (new BiomeGenSnow(12)).setColor(16777215).setBiomeName("Ice Plains").setEnableSnow().setTemperatureRainfall(0.0F, 0.5F);
029        public static final BiomeGenBase iceMountains = (new BiomeGenSnow(13)).setColor(10526880).setBiomeName("Ice Mountains").setEnableSnow().setMinMaxHeight(0.3F, 1.3F).setTemperatureRainfall(0.0F, 0.5F);
030        public static final BiomeGenBase mushroomIsland = (new BiomeGenMushroomIsland(14)).setColor(16711935).setBiomeName("MushroomIsland").setTemperatureRainfall(0.9F, 1.0F).setMinMaxHeight(0.2F, 1.0F);
031        public static final BiomeGenBase mushroomIslandShore = (new BiomeGenMushroomIsland(15)).setColor(10486015).setBiomeName("MushroomIslandShore").setTemperatureRainfall(0.9F, 1.0F).setMinMaxHeight(-1.0F, 0.1F);
032    
033        /** Beach biome. */
034        public static final BiomeGenBase beach = (new BiomeGenBeach(16)).setColor(16440917).setBiomeName("Beach").setTemperatureRainfall(0.8F, 0.4F).setMinMaxHeight(0.0F, 0.1F);
035    
036        /** Desert Hills biome. */
037        public static final BiomeGenBase desertHills = (new BiomeGenDesert(17)).setColor(13786898).setBiomeName("DesertHills").setDisableRain().setTemperatureRainfall(2.0F, 0.0F).setMinMaxHeight(0.3F, 0.8F);
038    
039        /** Forest Hills biome. */
040        public static final BiomeGenBase forestHills = (new BiomeGenForest(18)).setColor(2250012).setBiomeName("ForestHills").func_76733_a(5159473).setTemperatureRainfall(0.7F, 0.8F).setMinMaxHeight(0.3F, 0.7F);
041    
042        /** Taiga Hills biome. */
043        public static final BiomeGenBase taigaHills = (new BiomeGenTaiga(19)).setColor(1456435).setBiomeName("TaigaHills").setEnableSnow().func_76733_a(5159473).setTemperatureRainfall(0.05F, 0.8F).setMinMaxHeight(0.3F, 0.8F);
044    
045        /** Extreme Hills Edge biome. */
046        public static final BiomeGenBase extremeHillsEdge = (new BiomeGenHills(20)).setColor(7501978).setBiomeName("Extreme Hills Edge").setMinMaxHeight(0.2F, 0.8F).setTemperatureRainfall(0.2F, 0.3F);
047    
048        /** Jungle biome identifier */
049        public static final BiomeGenBase jungle = (new BiomeGenJungle(21)).setColor(5470985).setBiomeName("Jungle").func_76733_a(5470985).setTemperatureRainfall(1.2F, 0.9F).setMinMaxHeight(0.2F, 0.4F);
050        public static final BiomeGenBase jungleHills = (new BiomeGenJungle(22)).setColor(2900485).setBiomeName("JungleHills").func_76733_a(5470985).setTemperatureRainfall(1.2F, 0.9F).setMinMaxHeight(1.8F, 0.5F);
051        public String biomeName;
052        public int color;
053    
054        /** The block expected to be on the top of this biome */
055        public byte topBlock;
056    
057        /** The block to fill spots in when not on the top */
058        public byte fillerBlock;
059        public int field_76754_C;
060    
061        /** The minimum height of this biome. Default 0.1. */
062        public float minHeight;
063    
064        /** The maximum height of this biome. Default 0.3. */
065        public float maxHeight;
066    
067        /** The temperature of this biome. */
068        public float temperature;
069    
070        /** The rainfall in this biome. */
071        public float rainfall;
072    
073        /** Color tint applied to water depending on biome */
074        public int waterColorMultiplier;
075    
076        /** The biome decorator. */
077        public BiomeDecorator theBiomeDecorator;
078    
079        /**
080         * Holds the classes of IMobs (hostile mobs) that can be spawned in the biome.
081         */
082        protected List spawnableMonsterList;
083    
084        /**
085         * Holds the classes of any creature that can be spawned in the biome as friendly creature.
086         */
087        protected List spawnableCreatureList;
088    
089        /**
090         * Holds the classes of any aquatic creature that can be spawned in the water of the biome.
091         */
092        protected List spawnableWaterCreatureList;
093    
094        /** Set to true if snow is enabled for this biome. */
095        private boolean enableSnow;
096    
097        /**
098         * Is true (default) if the biome support rain (desert and nether can't have rain)
099         */
100        private boolean enableRain;
101    
102        /** The id number to this biome, and its index in the biomeList array. */
103        public final int biomeID;
104    
105        /** The tree generator. */
106        protected WorldGenTrees worldGeneratorTrees;
107    
108        /** The big tree generator. */
109        protected WorldGenBigTree worldGeneratorBigTree;
110    
111        /** The forest generator. */
112        protected WorldGenForest worldGeneratorForest;
113    
114        /** The swamp tree generator. */
115        protected WorldGenSwamp worldGeneratorSwamp;
116    
117        protected BiomeGenBase(int par1)
118        {
119            this.topBlock = (byte)Block.grass.blockID;
120            this.fillerBlock = (byte)Block.dirt.blockID;
121            this.field_76754_C = 5169201;
122            this.minHeight = 0.1F;
123            this.maxHeight = 0.3F;
124            this.temperature = 0.5F;
125            this.rainfall = 0.5F;
126            this.waterColorMultiplier = 16777215;
127            this.spawnableMonsterList = new ArrayList();
128            this.spawnableCreatureList = new ArrayList();
129            this.spawnableWaterCreatureList = new ArrayList();
130            this.enableRain = true;
131            this.worldGeneratorTrees = new WorldGenTrees(false);
132            this.worldGeneratorBigTree = new WorldGenBigTree(false);
133            this.worldGeneratorForest = new WorldGenForest(false);
134            this.worldGeneratorSwamp = new WorldGenSwamp();
135            this.biomeID = par1;
136            biomeList[par1] = this;
137            this.theBiomeDecorator = this.createBiomeDecorator();
138            this.spawnableCreatureList.add(new SpawnListEntry(EntitySheep.class, 12, 4, 4));
139            this.spawnableCreatureList.add(new SpawnListEntry(EntityPig.class, 10, 4, 4));
140            this.spawnableCreatureList.add(new SpawnListEntry(EntityChicken.class, 10, 4, 4));
141            this.spawnableCreatureList.add(new SpawnListEntry(EntityCow.class, 8, 4, 4));
142            this.spawnableMonsterList.add(new SpawnListEntry(EntitySpider.class, 10, 4, 4));
143            this.spawnableMonsterList.add(new SpawnListEntry(EntityZombie.class, 10, 4, 4));
144            this.spawnableMonsterList.add(new SpawnListEntry(EntitySkeleton.class, 10, 4, 4));
145            this.spawnableMonsterList.add(new SpawnListEntry(EntityCreeper.class, 10, 4, 4));
146            this.spawnableMonsterList.add(new SpawnListEntry(EntitySlime.class, 10, 4, 4));
147            this.spawnableMonsterList.add(new SpawnListEntry(EntityEnderman.class, 1, 1, 4));
148            this.spawnableWaterCreatureList.add(new SpawnListEntry(EntitySquid.class, 10, 4, 4));
149        }
150    
151        /**
152         * Allocate a new BiomeDecorator for this BiomeGenBase
153         */
154        protected BiomeDecorator createBiomeDecorator()
155        {
156            return new BiomeDecorator(this);
157        }
158    
159        /**
160         * Sets the temperature and rainfall of this biome.
161         */
162        private BiomeGenBase setTemperatureRainfall(float par1, float par2)
163        {
164            if (par1 > 0.1F && par1 < 0.2F)
165            {
166                throw new IllegalArgumentException("Please avoid temperatures in the range 0.1 - 0.2 because of snow");
167            }
168            else
169            {
170                this.temperature = par1;
171                this.rainfall = par2;
172                return this;
173            }
174        }
175    
176        /**
177         * Sets the minimum and maximum height of this biome. Seems to go from -2.0 to 2.0.
178         */
179        private BiomeGenBase setMinMaxHeight(float par1, float par2)
180        {
181            this.minHeight = par1;
182            this.maxHeight = par2;
183            return this;
184        }
185    
186        /**
187         * Disable the rain for the biome.
188         */
189        private BiomeGenBase setDisableRain()
190        {
191            this.enableRain = false;
192            return this;
193        }
194    
195        /**
196         * Gets a WorldGen appropriate for this biome.
197         */
198        public WorldGenerator getRandomWorldGenForTrees(Random par1Random)
199        {
200            return (WorldGenerator)(par1Random.nextInt(10) == 0 ? this.worldGeneratorBigTree : this.worldGeneratorTrees);
201        }
202    
203        /**
204         * Gets a WorldGen appropriate for this biome.
205         */
206        public WorldGenerator getRandomWorldGenForGrass(Random par1Random)
207        {
208            return new WorldGenTallGrass(Block.tallGrass.blockID, 1);
209        }
210    
211        /**
212         * sets enableSnow to true during biome initialization. returns BiomeGenBase.
213         */
214        protected BiomeGenBase setEnableSnow()
215        {
216            this.enableSnow = true;
217            return this;
218        }
219    
220        protected BiomeGenBase setBiomeName(String par1Str)
221        {
222            this.biomeName = par1Str;
223            return this;
224        }
225    
226        protected BiomeGenBase func_76733_a(int par1)
227        {
228            this.field_76754_C = par1;
229            return this;
230        }
231    
232        protected BiomeGenBase setColor(int par1)
233        {
234            this.color = par1;
235            return this;
236        }
237    
238        @SideOnly(Side.CLIENT)
239    
240        /**
241         * takes temperature, returns color
242         */
243        public int getSkyColorByTemp(float par1)
244        {
245            par1 /= 3.0F;
246    
247            if (par1 < -1.0F)
248            {
249                par1 = -1.0F;
250            }
251    
252            if (par1 > 1.0F)
253            {
254                par1 = 1.0F;
255            }
256    
257            return Color.getHSBColor(0.62222224F - par1 * 0.05F, 0.5F + par1 * 0.1F, 1.0F).getRGB();
258        }
259    
260        /**
261         * Returns the correspondent list of the EnumCreatureType informed.
262         */
263        public List getSpawnableList(EnumCreatureType par1EnumCreatureType)
264        {
265            return par1EnumCreatureType == EnumCreatureType.monster ? this.spawnableMonsterList : (par1EnumCreatureType == EnumCreatureType.creature ? this.spawnableCreatureList : (par1EnumCreatureType == EnumCreatureType.waterCreature ? this.spawnableWaterCreatureList : null));
266        }
267    
268        /**
269         * Returns true if the biome have snowfall instead a normal rain.
270         */
271        public boolean getEnableSnow()
272        {
273            return this.enableSnow;
274        }
275    
276        /**
277         * Return true if the biome supports lightning bolt spawn, either by have the bolts enabled and have rain enabled.
278         */
279        public boolean canSpawnLightningBolt()
280        {
281            return this.enableSnow ? false : this.enableRain;
282        }
283    
284        /**
285         * Checks to see if the rainfall level of the biome is extremely high
286         */
287        public boolean isHighHumidity()
288        {
289            return this.rainfall > 0.85F;
290        }
291    
292        /**
293         * returns the chance a creature has to spawn.
294         */
295        public float getSpawningChance()
296        {
297            return 0.1F;
298        }
299    
300        /**
301         * Gets an integer representation of this biome's rainfall
302         */
303        public final int getIntRainfall()
304        {
305            return (int)(this.rainfall * 65536.0F);
306        }
307    
308        /**
309         * Gets an integer representation of this biome's temperature
310         */
311        public final int getIntTemperature()
312        {
313            return (int)(this.temperature * 65536.0F);
314        }
315    
316        @SideOnly(Side.CLIENT)
317    
318        /**
319         * Gets a floating point representation of this biome's rainfall
320         */
321        public final float getFloatRainfall()
322        {
323            return this.rainfall;
324        }
325    
326        /**
327         * Gets a floating point representation of this biome's temperature
328         */
329        public final float getFloatTemperature()
330        {
331            return this.temperature;
332        }
333    
334        public void decorate(World par1World, Random par2Random, int par3, int par4)
335        {
336            this.theBiomeDecorator.decorate(par1World, par2Random, par3, par4);
337        }
338    
339        @SideOnly(Side.CLIENT)
340    
341        /**
342         * Provides the basic grass color based on the biome temperature and rainfall
343         */
344        public int getBiomeGrassColor()
345        {
346            double var1 = (double)MathHelper.clamp_float(this.getFloatTemperature(), 0.0F, 1.0F);
347            double var3 = (double)MathHelper.clamp_float(this.getFloatRainfall(), 0.0F, 1.0F);
348            return ColorizerGrass.getGrassColor(var1, var3);
349        }
350    
351        @SideOnly(Side.CLIENT)
352    
353        /**
354         * Provides the basic foliage color based on the biome temperature and rainfall
355         */
356        public int getBiomeFoliageColor()
357        {
358            double var1 = (double)MathHelper.clamp_float(this.getFloatTemperature(), 0.0F, 1.0F);
359            double var3 = (double)MathHelper.clamp_float(this.getFloatRainfall(), 0.0F, 1.0F);
360            return ColorizerFoliage.getFoliageColor(var1, var3);
361        }
362    }