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