001    package net.minecraft.client.renderer;
002    
003    import cpw.mods.fml.relauncher.Side;
004    import cpw.mods.fml.relauncher.SideOnly;
005    import java.awt.image.BufferedImage;
006    import java.nio.FloatBuffer;
007    import java.util.List;
008    import java.util.Random;
009    import net.minecraft.block.Block;
010    import net.minecraft.block.material.Material;
011    import net.minecraft.client.Minecraft;
012    import net.minecraft.client.entity.EntityPlayerSP;
013    import net.minecraft.client.gui.ScaledResolution;
014    import net.minecraft.client.multiplayer.WorldClient;
015    import net.minecraft.client.particle.EffectRenderer;
016    import net.minecraft.client.particle.EntityRainFX;
017    import net.minecraft.client.particle.EntitySmokeFX;
018    import net.minecraft.client.renderer.culling.ClippingHelperImpl;
019    import net.minecraft.client.renderer.culling.Frustrum;
020    import net.minecraft.crash.CrashReport;
021    import net.minecraft.crash.CrashReportCategory;
022    import net.minecraft.entity.Entity;
023    import net.minecraft.entity.EntityLiving;
024    import net.minecraft.entity.boss.BossStatus;
025    import net.minecraft.entity.player.EntityPlayer;
026    import net.minecraft.potion.Potion;
027    import net.minecraft.util.AxisAlignedBB;
028    import net.minecraft.util.MathHelper;
029    import net.minecraft.util.MouseFilter;
030    import net.minecraft.util.MovingObjectPosition;
031    import net.minecraft.util.ReportedException;
032    import net.minecraft.util.Vec3;
033    import net.minecraft.world.biome.BiomeGenBase;
034    import org.lwjgl.input.Mouse;
035    import org.lwjgl.opengl.Display;
036    import org.lwjgl.opengl.GL11;
037    import org.lwjgl.opengl.GLContext;
038    import org.lwjgl.util.glu.GLU;
039    
040    import net.minecraftforge.client.ForgeHooksClient;
041    import net.minecraftforge.client.event.DrawBlockHighlightEvent;
042    import net.minecraftforge.client.event.RenderWorldLastEvent;
043    import net.minecraftforge.common.MinecraftForge;
044    
045    @SideOnly(Side.CLIENT)
046    public class EntityRenderer
047    {
048        public static boolean anaglyphEnable = false;
049    
050        /** Anaglyph field (0=R, 1=GB) */
051        public static int anaglyphField;
052    
053        /** A reference to the Minecraft object. */
054        private Minecraft mc;
055        private float farPlaneDistance = 0.0F;
056        public ItemRenderer itemRenderer;
057    
058        /** Entity renderer update count */
059        private int rendererUpdateCount;
060    
061        /** Pointed entity */
062        private Entity pointedEntity = null;
063        private MouseFilter mouseFilterXAxis = new MouseFilter();
064        private MouseFilter mouseFilterYAxis = new MouseFilter();
065    
066        /** Mouse filter dummy 1 */
067        private MouseFilter mouseFilterDummy1 = new MouseFilter();
068    
069        /** Mouse filter dummy 2 */
070        private MouseFilter mouseFilterDummy2 = new MouseFilter();
071    
072        /** Mouse filter dummy 3 */
073        private MouseFilter mouseFilterDummy3 = new MouseFilter();
074    
075        /** Mouse filter dummy 4 */
076        private MouseFilter mouseFilterDummy4 = new MouseFilter();
077        private float thirdPersonDistance = 4.0F;
078    
079        /** Third person distance temp */
080        private float thirdPersonDistanceTemp = 4.0F;
081        private float debugCamYaw = 0.0F;
082        private float prevDebugCamYaw = 0.0F;
083        private float debugCamPitch = 0.0F;
084        private float prevDebugCamPitch = 0.0F;
085    
086        /** Smooth cam yaw */
087        private float smoothCamYaw;
088    
089        /** Smooth cam pitch */
090        private float smoothCamPitch;
091    
092        /** Smooth cam filter X */
093        private float smoothCamFilterX;
094    
095        /** Smooth cam filter Y */
096        private float smoothCamFilterY;
097    
098        /** Smooth cam partial ticks */
099        private float smoothCamPartialTicks;
100        private float debugCamFOV = 0.0F;
101        private float prevDebugCamFOV = 0.0F;
102        private float camRoll = 0.0F;
103        private float prevCamRoll = 0.0F;
104    
105        /**
106         * The texture id of the blocklight/skylight texture used for lighting effects
107         */
108        public int lightmapTexture;
109    
110        /**
111         * Colors computed in updateLightmap() and loaded into the lightmap emptyTexture
112         */
113        private int[] lightmapColors;
114    
115        /** FOV modifier hand */
116        private float fovModifierHand;
117    
118        /** FOV modifier hand prev */
119        private float fovModifierHandPrev;
120    
121        /** FOV multiplier temp */
122        private float fovMultiplierTemp;
123        private float field_82831_U;
124        private float field_82832_V;
125    
126        /** Cloud fog mode */
127        private boolean cloudFog = false;
128        private double cameraZoom = 1.0D;
129        private double cameraYaw = 0.0D;
130        private double cameraPitch = 0.0D;
131    
132        /** Previous frame time in milliseconds */
133        private long prevFrameTime = Minecraft.getSystemTime();
134    
135        /** End time of last render (ns) */
136        private long renderEndNanoTime = 0L;
137    
138        /**
139         * Is set, updateCameraAndRender() calls updateLightmap(); set by updateTorchFlicker()
140         */
141        private boolean lightmapUpdateNeeded = false;
142    
143        /** Torch flicker X */
144        float torchFlickerX = 0.0F;
145    
146        /** Torch flicker DX */
147        float torchFlickerDX = 0.0F;
148    
149        /** Torch flicker Y */
150        float torchFlickerY = 0.0F;
151    
152        /** Torch flicker DY */
153        float torchFlickerDY = 0.0F;
154        private Random random = new Random();
155    
156        /** Rain sound counter */
157        private int rainSoundCounter = 0;
158    
159        /** Rain X coords */
160        float[] rainXCoords;
161    
162        /** Rain Y coords */
163        float[] rainYCoords;
164        volatile int field_78523_k = 0;
165        volatile int field_78520_l = 0;
166    
167        /** Fog color buffer */
168        FloatBuffer fogColorBuffer = GLAllocation.createDirectFloatBuffer(16);
169    
170        /** red component of the fog color */
171        float fogColorRed;
172    
173        /** green component of the fog color */
174        float fogColorGreen;
175    
176        /** blue component of the fog color */
177        float fogColorBlue;
178    
179        /** Fog color 2 */
180        private float fogColor2;
181    
182        /** Fog color 1 */
183        private float fogColor1;
184    
185        /**
186         * Debug view direction (0=OFF, 1=Front, 2=Right, 3=Back, 4=Left, 5=TiltLeft, 6=TiltRight)
187         */
188        public int debugViewDirection;
189    
190        public EntityRenderer(Minecraft par1Minecraft)
191        {
192            this.mc = par1Minecraft;
193            this.itemRenderer = new ItemRenderer(par1Minecraft);
194            this.lightmapTexture = par1Minecraft.renderEngine.allocateAndSetupTexture(new BufferedImage(16, 16, 1));
195            this.lightmapColors = new int[256];
196        }
197    
198        /**
199         * Updates the entity renderer
200         */
201        public void updateRenderer()
202        {
203            this.updateFovModifierHand();
204            this.updateTorchFlicker();
205            this.fogColor2 = this.fogColor1;
206            this.thirdPersonDistanceTemp = this.thirdPersonDistance;
207            this.prevDebugCamYaw = this.debugCamYaw;
208            this.prevDebugCamPitch = this.debugCamPitch;
209            this.prevDebugCamFOV = this.debugCamFOV;
210            this.prevCamRoll = this.camRoll;
211            float var1;
212            float var2;
213    
214            if (this.mc.gameSettings.smoothCamera)
215            {
216                var1 = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
217                var2 = var1 * var1 * var1 * 8.0F;
218                this.smoothCamFilterX = this.mouseFilterXAxis.smooth(this.smoothCamYaw, 0.05F * var2);
219                this.smoothCamFilterY = this.mouseFilterYAxis.smooth(this.smoothCamPitch, 0.05F * var2);
220                this.smoothCamPartialTicks = 0.0F;
221                this.smoothCamYaw = 0.0F;
222                this.smoothCamPitch = 0.0F;
223            }
224    
225            if (this.mc.renderViewEntity == null)
226            {
227                this.mc.renderViewEntity = this.mc.thePlayer;
228            }
229    
230            var1 = this.mc.theWorld.getLightBrightness(MathHelper.floor_double(this.mc.renderViewEntity.posX), MathHelper.floor_double(this.mc.renderViewEntity.posY), MathHelper.floor_double(this.mc.renderViewEntity.posZ));
231            var2 = (float)(3 - this.mc.gameSettings.renderDistance) / 3.0F;
232            float var3 = var1 * (1.0F - var2) + var2;
233            this.fogColor1 += (var3 - this.fogColor1) * 0.1F;
234            ++this.rendererUpdateCount;
235            this.itemRenderer.updateEquippedItem();
236            this.addRainParticles();
237            this.field_82832_V = this.field_82831_U;
238    
239            if (BossStatus.field_82825_d)
240            {
241                this.field_82831_U += 0.05F;
242    
243                if (this.field_82831_U > 1.0F)
244                {
245                    this.field_82831_U = 1.0F;
246                }
247    
248                BossStatus.field_82825_d = false;
249            }
250            else if (this.field_82831_U > 0.0F)
251            {
252                this.field_82831_U -= 0.0125F;
253            }
254        }
255    
256        /**
257         * Finds what block or object the mouse is over at the specified partial tick time. Args: partialTickTime
258         */
259        public void getMouseOver(float par1)
260        {
261            if (this.mc.renderViewEntity != null)
262            {
263                if (this.mc.theWorld != null)
264                {
265                    double var2 = (double)this.mc.playerController.getBlockReachDistance();
266                    this.mc.objectMouseOver = this.mc.renderViewEntity.rayTrace(var2, par1);
267                    double var4 = var2;
268                    Vec3 var6 = this.mc.renderViewEntity.getPosition(par1);
269    
270                    if (this.mc.playerController.extendedReach())
271                    {
272                        var2 = 6.0D;
273                        var4 = 6.0D;
274                    }
275                    else
276                    {
277                        if (var2 > 3.0D)
278                        {
279                            var4 = 3.0D;
280                        }
281    
282                        var2 = var4;
283                    }
284    
285                    if (this.mc.objectMouseOver != null)
286                    {
287                        var4 = this.mc.objectMouseOver.hitVec.distanceTo(var6);
288                    }
289    
290                    Vec3 var7 = this.mc.renderViewEntity.getLook(par1);
291                    Vec3 var8 = var6.addVector(var7.xCoord * var2, var7.yCoord * var2, var7.zCoord * var2);
292                    this.pointedEntity = null;
293                    float var9 = 1.0F;
294                    List var10 = this.mc.theWorld.getEntitiesWithinAABBExcludingEntity(this.mc.renderViewEntity, this.mc.renderViewEntity.boundingBox.addCoord(var7.xCoord * var2, var7.yCoord * var2, var7.zCoord * var2).expand((double)var9, (double)var9, (double)var9));
295                    double var11 = var4;
296    
297                    for (int var13 = 0; var13 < var10.size(); ++var13)
298                    {
299                        Entity var14 = (Entity)var10.get(var13);
300    
301                        if (var14.canBeCollidedWith())
302                        {
303                            float var15 = var14.getCollisionBorderSize();
304                            AxisAlignedBB var16 = var14.boundingBox.expand((double)var15, (double)var15, (double)var15);
305                            MovingObjectPosition var17 = var16.calculateIntercept(var6, var8);
306    
307                            if (var16.isVecInside(var6))
308                            {
309                                if (0.0D < var11 || var11 == 0.0D)
310                                {
311                                    this.pointedEntity = var14;
312                                    var11 = 0.0D;
313                                }
314                            }
315                            else if (var17 != null)
316                            {
317                                double var18 = var6.distanceTo(var17.hitVec);
318    
319                                if (var18 < var11 || var11 == 0.0D)
320                                {
321                                    this.pointedEntity = var14;
322                                    var11 = var18;
323                                }
324                            }
325                        }
326                    }
327    
328                    if (this.pointedEntity != null && (var11 < var4 || this.mc.objectMouseOver == null))
329                    {
330                        this.mc.objectMouseOver = new MovingObjectPosition(this.pointedEntity);
331                    }
332                }
333            }
334        }
335    
336        /**
337         * Update FOV modifier hand
338         */
339        private void updateFovModifierHand()
340        {
341            if (mc.renderViewEntity instanceof EntityPlayerSP)
342            {
343                EntityPlayerSP var1 = (EntityPlayerSP)this.mc.renderViewEntity;
344                this.fovMultiplierTemp = var1.getFOVMultiplier();
345            }
346            else
347            {
348                this.fovMultiplierTemp = mc.thePlayer.getFOVMultiplier();
349            }
350            this.fovModifierHandPrev = this.fovModifierHand;
351            this.fovModifierHand += (this.fovMultiplierTemp - this.fovModifierHand) * 0.5F;
352        }
353    
354        /**
355         * Changes the field of view of the player depending on if they are underwater or not
356         */
357        private float getFOVModifier(float par1, boolean par2)
358        {
359            if (this.debugViewDirection > 0)
360            {
361                return 90.0F;
362            }
363            else
364            {
365                EntityLiving var3 = (EntityLiving)this.mc.renderViewEntity;
366                float var4 = 70.0F;
367    
368                if (par2)
369                {
370                    var4 += this.mc.gameSettings.fovSetting * 40.0F;
371                    var4 *= this.fovModifierHandPrev + (this.fovModifierHand - this.fovModifierHandPrev) * par1;
372                }
373    
374                if (var3.getHealth() <= 0)
375                {
376                    float var5 = (float)var3.deathTime + par1;
377                    var4 /= (1.0F - 500.0F / (var5 + 500.0F)) * 2.0F + 1.0F;
378                }
379    
380                int var6 = ActiveRenderInfo.getBlockIdAtEntityViewpoint(this.mc.theWorld, var3, par1);
381    
382                if (var6 != 0 && Block.blocksList[var6].blockMaterial == Material.water)
383                {
384                    var4 = var4 * 60.0F / 70.0F;
385                }
386    
387                return var4 + this.prevDebugCamFOV + (this.debugCamFOV - this.prevDebugCamFOV) * par1;
388            }
389        }
390    
391        private void hurtCameraEffect(float par1)
392        {
393            EntityLiving var2 = this.mc.renderViewEntity;
394            float var3 = (float)var2.hurtTime - par1;
395            float var4;
396    
397            if (var2.getHealth() <= 0)
398            {
399                var4 = (float)var2.deathTime + par1;
400                GL11.glRotatef(40.0F - 8000.0F / (var4 + 200.0F), 0.0F, 0.0F, 1.0F);
401            }
402    
403            if (var3 >= 0.0F)
404            {
405                var3 /= (float)var2.maxHurtTime;
406                var3 = MathHelper.sin(var3 * var3 * var3 * var3 * (float)Math.PI);
407                var4 = var2.attackedAtYaw;
408                GL11.glRotatef(-var4, 0.0F, 1.0F, 0.0F);
409                GL11.glRotatef(-var3 * 14.0F, 0.0F, 0.0F, 1.0F);
410                GL11.glRotatef(var4, 0.0F, 1.0F, 0.0F);
411            }
412        }
413    
414        /**
415         * Setups all the GL settings for view bobbing. Args: partialTickTime
416         */
417        private void setupViewBobbing(float par1)
418        {
419            if (this.mc.renderViewEntity instanceof EntityPlayer)
420            {
421                EntityPlayer var2 = (EntityPlayer)this.mc.renderViewEntity;
422                float var3 = var2.distanceWalkedModified - var2.prevDistanceWalkedModified;
423                float var4 = -(var2.distanceWalkedModified + var3 * par1);
424                float var5 = var2.prevCameraYaw + (var2.cameraYaw - var2.prevCameraYaw) * par1;
425                float var6 = var2.prevCameraPitch + (var2.cameraPitch - var2.prevCameraPitch) * par1;
426                GL11.glTranslatef(MathHelper.sin(var4 * (float)Math.PI) * var5 * 0.5F, -Math.abs(MathHelper.cos(var4 * (float)Math.PI) * var5), 0.0F);
427                GL11.glRotatef(MathHelper.sin(var4 * (float)Math.PI) * var5 * 3.0F, 0.0F, 0.0F, 1.0F);
428                GL11.glRotatef(Math.abs(MathHelper.cos(var4 * (float)Math.PI - 0.2F) * var5) * 5.0F, 1.0F, 0.0F, 0.0F);
429                GL11.glRotatef(var6, 1.0F, 0.0F, 0.0F);
430            }
431        }
432    
433        /**
434         * sets up player's eye (or camera in third person mode)
435         */
436        private void orientCamera(float par1)
437        {
438            EntityLiving var2 = this.mc.renderViewEntity;
439            float var3 = var2.yOffset - 1.62F;
440            double var4 = var2.prevPosX + (var2.posX - var2.prevPosX) * (double)par1;
441            double var6 = var2.prevPosY + (var2.posY - var2.prevPosY) * (double)par1 - (double)var3;
442            double var8 = var2.prevPosZ + (var2.posZ - var2.prevPosZ) * (double)par1;
443            GL11.glRotatef(this.prevCamRoll + (this.camRoll - this.prevCamRoll) * par1, 0.0F, 0.0F, 1.0F);
444    
445            if (var2.isPlayerSleeping())
446            {
447                var3 = (float)((double)var3 + 1.0D);
448                GL11.glTranslatef(0.0F, 0.3F, 0.0F);
449    
450                if (!this.mc.gameSettings.debugCamEnable)
451                {
452                    ForgeHooksClient.orientBedCamera(mc, var2);
453                    GL11.glRotatef(var2.prevRotationYaw + (var2.rotationYaw - var2.prevRotationYaw) * par1 + 180.0F, 0.0F, -1.0F, 0.0F);
454                    GL11.glRotatef(var2.prevRotationPitch + (var2.rotationPitch - var2.prevRotationPitch) * par1, -1.0F, 0.0F, 0.0F);
455                }
456            }
457            else if (this.mc.gameSettings.thirdPersonView > 0)
458            {
459                double var27 = (double)(this.thirdPersonDistanceTemp + (this.thirdPersonDistance - this.thirdPersonDistanceTemp) * par1);
460                float var13;
461                float var28;
462    
463                if (this.mc.gameSettings.debugCamEnable)
464                {
465                    var28 = this.prevDebugCamYaw + (this.debugCamYaw - this.prevDebugCamYaw) * par1;
466                    var13 = this.prevDebugCamPitch + (this.debugCamPitch - this.prevDebugCamPitch) * par1;
467                    GL11.glTranslatef(0.0F, 0.0F, (float)(-var27));
468                    GL11.glRotatef(var13, 1.0F, 0.0F, 0.0F);
469                    GL11.glRotatef(var28, 0.0F, 1.0F, 0.0F);
470                }
471                else
472                {
473                    var28 = var2.rotationYaw;
474                    var13 = var2.rotationPitch;
475    
476                    if (this.mc.gameSettings.thirdPersonView == 2)
477                    {
478                        var13 += 180.0F;
479                    }
480    
481                    double var14 = (double)(-MathHelper.sin(var28 / 180.0F * (float)Math.PI) * MathHelper.cos(var13 / 180.0F * (float)Math.PI)) * var27;
482                    double var16 = (double)(MathHelper.cos(var28 / 180.0F * (float)Math.PI) * MathHelper.cos(var13 / 180.0F * (float)Math.PI)) * var27;
483                    double var18 = (double)(-MathHelper.sin(var13 / 180.0F * (float)Math.PI)) * var27;
484    
485                    for (int var20 = 0; var20 < 8; ++var20)
486                    {
487                        float var21 = (float)((var20 & 1) * 2 - 1);
488                        float var22 = (float)((var20 >> 1 & 1) * 2 - 1);
489                        float var23 = (float)((var20 >> 2 & 1) * 2 - 1);
490                        var21 *= 0.1F;
491                        var22 *= 0.1F;
492                        var23 *= 0.1F;
493                        MovingObjectPosition var24 = this.mc.theWorld.rayTraceBlocks(this.mc.theWorld.getWorldVec3Pool().getVecFromPool(var4 + (double)var21, var6 + (double)var22, var8 + (double)var23), this.mc.theWorld.getWorldVec3Pool().getVecFromPool(var4 - var14 + (double)var21 + (double)var23, var6 - var18 + (double)var22, var8 - var16 + (double)var23));
494    
495                        if (var24 != null)
496                        {
497                            double var25 = var24.hitVec.distanceTo(this.mc.theWorld.getWorldVec3Pool().getVecFromPool(var4, var6, var8));
498    
499                            if (var25 < var27)
500                            {
501                                var27 = var25;
502                            }
503                        }
504                    }
505    
506                    if (this.mc.gameSettings.thirdPersonView == 2)
507                    {
508                        GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
509                    }
510    
511                    GL11.glRotatef(var2.rotationPitch - var13, 1.0F, 0.0F, 0.0F);
512                    GL11.glRotatef(var2.rotationYaw - var28, 0.0F, 1.0F, 0.0F);
513                    GL11.glTranslatef(0.0F, 0.0F, (float)(-var27));
514                    GL11.glRotatef(var28 - var2.rotationYaw, 0.0F, 1.0F, 0.0F);
515                    GL11.glRotatef(var13 - var2.rotationPitch, 1.0F, 0.0F, 0.0F);
516                }
517            }
518            else
519            {
520                GL11.glTranslatef(0.0F, 0.0F, -0.1F);
521            }
522    
523            if (!this.mc.gameSettings.debugCamEnable)
524            {
525                GL11.glRotatef(var2.prevRotationPitch + (var2.rotationPitch - var2.prevRotationPitch) * par1, 1.0F, 0.0F, 0.0F);
526                GL11.glRotatef(var2.prevRotationYaw + (var2.rotationYaw - var2.prevRotationYaw) * par1 + 180.0F, 0.0F, 1.0F, 0.0F);
527            }
528    
529            GL11.glTranslatef(0.0F, var3, 0.0F);
530            var4 = var2.prevPosX + (var2.posX - var2.prevPosX) * (double)par1;
531            var6 = var2.prevPosY + (var2.posY - var2.prevPosY) * (double)par1 - (double)var3;
532            var8 = var2.prevPosZ + (var2.posZ - var2.prevPosZ) * (double)par1;
533            this.cloudFog = this.mc.renderGlobal.hasCloudFog(var4, var6, var8, par1);
534        }
535    
536        /**
537         * sets up projection, view effects, camera position/rotation
538         */
539        private void setupCameraTransform(float par1, int par2)
540        {
541            this.farPlaneDistance = (float)(256 >> this.mc.gameSettings.renderDistance);
542            GL11.glMatrixMode(GL11.GL_PROJECTION);
543            GL11.glLoadIdentity();
544            float var3 = 0.07F;
545    
546            if (this.mc.gameSettings.anaglyph)
547            {
548                GL11.glTranslatef((float)(-(par2 * 2 - 1)) * var3, 0.0F, 0.0F);
549            }
550    
551            if (this.cameraZoom != 1.0D)
552            {
553                GL11.glTranslatef((float)this.cameraYaw, (float)(-this.cameraPitch), 0.0F);
554                GL11.glScaled(this.cameraZoom, this.cameraZoom, 1.0D);
555            }
556    
557            GLU.gluPerspective(this.getFOVModifier(par1, true), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * 2.0F);
558            float var4;
559    
560            if (this.mc.playerController.func_78747_a())
561            {
562                var4 = 0.6666667F;
563                GL11.glScalef(1.0F, var4, 1.0F);
564            }
565    
566            GL11.glMatrixMode(GL11.GL_MODELVIEW);
567            GL11.glLoadIdentity();
568    
569            if (this.mc.gameSettings.anaglyph)
570            {
571                GL11.glTranslatef((float)(par2 * 2 - 1) * 0.1F, 0.0F, 0.0F);
572            }
573    
574            this.hurtCameraEffect(par1);
575    
576            if (this.mc.gameSettings.viewBobbing)
577            {
578                this.setupViewBobbing(par1);
579            }
580    
581            var4 = this.mc.thePlayer.prevTimeInPortal + (this.mc.thePlayer.timeInPortal - this.mc.thePlayer.prevTimeInPortal) * par1;
582    
583            if (var4 > 0.0F)
584            {
585                byte var5 = 20;
586    
587                if (this.mc.thePlayer.isPotionActive(Potion.confusion))
588                {
589                    var5 = 7;
590                }
591    
592                float var6 = 5.0F / (var4 * var4 + 5.0F) - var4 * 0.04F;
593                var6 *= var6;
594                GL11.glRotatef(((float)this.rendererUpdateCount + par1) * (float)var5, 0.0F, 1.0F, 1.0F);
595                GL11.glScalef(1.0F / var6, 1.0F, 1.0F);
596                GL11.glRotatef(-((float)this.rendererUpdateCount + par1) * (float)var5, 0.0F, 1.0F, 1.0F);
597            }
598    
599            this.orientCamera(par1);
600    
601            if (this.debugViewDirection > 0)
602            {
603                int var7 = this.debugViewDirection - 1;
604    
605                if (var7 == 1)
606                {
607                    GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
608                }
609    
610                if (var7 == 2)
611                {
612                    GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
613                }
614    
615                if (var7 == 3)
616                {
617                    GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
618                }
619    
620                if (var7 == 4)
621                {
622                    GL11.glRotatef(90.0F, 1.0F, 0.0F, 0.0F);
623                }
624    
625                if (var7 == 5)
626                {
627                    GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
628                }
629            }
630        }
631    
632        /**
633         * Render player hand
634         */
635        private void renderHand(float par1, int par2)
636        {
637            if (this.debugViewDirection <= 0)
638            {
639                GL11.glMatrixMode(GL11.GL_PROJECTION);
640                GL11.glLoadIdentity();
641                float var3 = 0.07F;
642    
643                if (this.mc.gameSettings.anaglyph)
644                {
645                    GL11.glTranslatef((float)(-(par2 * 2 - 1)) * var3, 0.0F, 0.0F);
646                }
647    
648                if (this.cameraZoom != 1.0D)
649                {
650                    GL11.glTranslatef((float)this.cameraYaw, (float)(-this.cameraPitch), 0.0F);
651                    GL11.glScaled(this.cameraZoom, this.cameraZoom, 1.0D);
652                }
653    
654                GLU.gluPerspective(this.getFOVModifier(par1, false), (float)this.mc.displayWidth / (float)this.mc.displayHeight, 0.05F, this.farPlaneDistance * 2.0F);
655    
656                if (this.mc.playerController.func_78747_a())
657                {
658                    float var4 = 0.6666667F;
659                    GL11.glScalef(1.0F, var4, 1.0F);
660                }
661    
662                GL11.glMatrixMode(GL11.GL_MODELVIEW);
663                GL11.glLoadIdentity();
664    
665                if (this.mc.gameSettings.anaglyph)
666                {
667                    GL11.glTranslatef((float)(par2 * 2 - 1) * 0.1F, 0.0F, 0.0F);
668                }
669    
670                GL11.glPushMatrix();
671                this.hurtCameraEffect(par1);
672    
673                if (this.mc.gameSettings.viewBobbing)
674                {
675                    this.setupViewBobbing(par1);
676                }
677    
678                if (this.mc.gameSettings.thirdPersonView == 0 && !this.mc.renderViewEntity.isPlayerSleeping() && !this.mc.gameSettings.hideGUI && !this.mc.playerController.func_78747_a())
679                {
680                    this.enableLightmap((double)par1);
681                    this.itemRenderer.renderItemInFirstPerson(par1);
682                    this.disableLightmap((double)par1);
683                }
684    
685                GL11.glPopMatrix();
686    
687                if (this.mc.gameSettings.thirdPersonView == 0 && !this.mc.renderViewEntity.isPlayerSleeping())
688                {
689                    this.itemRenderer.renderOverlays(par1);
690                    this.hurtCameraEffect(par1);
691                }
692    
693                if (this.mc.gameSettings.viewBobbing)
694                {
695                    this.setupViewBobbing(par1);
696                }
697            }
698        }
699    
700        /**
701         * Disable secondary texture unit used by lightmap
702         */
703        public void disableLightmap(double par1)
704        {
705            OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
706            GL11.glDisable(GL11.GL_TEXTURE_2D);
707            OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
708        }
709    
710        /**
711         * Enable lightmap in secondary texture unit
712         */
713        public void enableLightmap(double par1)
714        {
715            OpenGlHelper.setActiveTexture(OpenGlHelper.lightmapTexUnit);
716            GL11.glMatrixMode(GL11.GL_TEXTURE);
717            GL11.glLoadIdentity();
718            float var3 = 0.00390625F;
719            GL11.glScalef(var3, var3, var3);
720            GL11.glTranslatef(8.0F, 8.0F, 8.0F);
721            GL11.glMatrixMode(GL11.GL_MODELVIEW);
722            this.mc.renderEngine.bindTexture(this.lightmapTexture);
723            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
724            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
725            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
726            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
727            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP);
728            GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP);
729            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
730            GL11.glEnable(GL11.GL_TEXTURE_2D);
731            OpenGlHelper.setActiveTexture(OpenGlHelper.defaultTexUnit);
732        }
733    
734        /**
735         * Recompute a random value that is applied to block color in updateLightmap()
736         */
737        private void updateTorchFlicker()
738        {
739            this.torchFlickerDX = (float)((double)this.torchFlickerDX + (Math.random() - Math.random()) * Math.random() * Math.random());
740            this.torchFlickerDY = (float)((double)this.torchFlickerDY + (Math.random() - Math.random()) * Math.random() * Math.random());
741            this.torchFlickerDX = (float)((double)this.torchFlickerDX * 0.9D);
742            this.torchFlickerDY = (float)((double)this.torchFlickerDY * 0.9D);
743            this.torchFlickerX += (this.torchFlickerDX - this.torchFlickerX) * 1.0F;
744            this.torchFlickerY += (this.torchFlickerDY - this.torchFlickerY) * 1.0F;
745            this.lightmapUpdateNeeded = true;
746        }
747    
748        private void updateLightmap(float par1)
749        {
750            WorldClient var2 = this.mc.theWorld;
751    
752            if (var2 != null)
753            {
754                for (int var3 = 0; var3 < 256; ++var3)
755                {
756                    float var4 = var2.getSunBrightness(1.0F) * 0.95F + 0.05F;
757                    float var5 = var2.provider.lightBrightnessTable[var3 / 16] * var4;
758                    float var6 = var2.provider.lightBrightnessTable[var3 % 16] * (this.torchFlickerX * 0.1F + 1.5F);
759    
760                    if (var2.lastLightningBolt > 0)
761                    {
762                        var5 = var2.provider.lightBrightnessTable[var3 / 16];
763                    }
764    
765                    float var7 = var5 * (var2.getSunBrightness(1.0F) * 0.65F + 0.35F);
766                    float var8 = var5 * (var2.getSunBrightness(1.0F) * 0.65F + 0.35F);
767                    float var11 = var6 * ((var6 * 0.6F + 0.4F) * 0.6F + 0.4F);
768                    float var12 = var6 * (var6 * var6 * 0.6F + 0.4F);
769                    float var13 = var7 + var6;
770                    float var14 = var8 + var11;
771                    float var15 = var5 + var12;
772                    var13 = var13 * 0.96F + 0.03F;
773                    var14 = var14 * 0.96F + 0.03F;
774                    var15 = var15 * 0.96F + 0.03F;
775                    float var16;
776    
777                    if (this.field_82831_U > 0.0F)
778                    {
779                        var16 = this.field_82832_V + (this.field_82831_U - this.field_82832_V) * par1;
780                        var13 = var13 * (1.0F - var16) + var13 * 0.7F * var16;
781                        var14 = var14 * (1.0F - var16) + var14 * 0.6F * var16;
782                        var15 = var15 * (1.0F - var16) + var15 * 0.6F * var16;
783                    }
784    
785                    if (var2.provider.dimensionId == 1)
786                    {
787                        var13 = 0.22F + var6 * 0.75F;
788                        var14 = 0.28F + var11 * 0.75F;
789                        var15 = 0.25F + var12 * 0.75F;
790                    }
791    
792                    float var17;
793    
794                    if (this.mc.thePlayer.isPotionActive(Potion.nightVision))
795                    {
796                        var16 = this.getNightVisionBrightness(this.mc.thePlayer, par1);
797                        var17 = 1.0F / var13;
798    
799                        if (var17 > 1.0F / var14)
800                        {
801                            var17 = 1.0F / var14;
802                        }
803    
804                        if (var17 > 1.0F / var15)
805                        {
806                            var17 = 1.0F / var15;
807                        }
808    
809                        var13 = var13 * (1.0F - var16) + var13 * var17 * var16;
810                        var14 = var14 * (1.0F - var16) + var14 * var17 * var16;
811                        var15 = var15 * (1.0F - var16) + var15 * var17 * var16;
812                    }
813    
814                    if (var13 > 1.0F)
815                    {
816                        var13 = 1.0F;
817                    }
818    
819                    if (var14 > 1.0F)
820                    {
821                        var14 = 1.0F;
822                    }
823    
824                    if (var15 > 1.0F)
825                    {
826                        var15 = 1.0F;
827                    }
828    
829                    var16 = this.mc.gameSettings.gammaSetting;
830                    var17 = 1.0F - var13;
831                    float var18 = 1.0F - var14;
832                    float var19 = 1.0F - var15;
833                    var17 = 1.0F - var17 * var17 * var17 * var17;
834                    var18 = 1.0F - var18 * var18 * var18 * var18;
835                    var19 = 1.0F - var19 * var19 * var19 * var19;
836                    var13 = var13 * (1.0F - var16) + var17 * var16;
837                    var14 = var14 * (1.0F - var16) + var18 * var16;
838                    var15 = var15 * (1.0F - var16) + var19 * var16;
839                    var13 = var13 * 0.96F + 0.03F;
840                    var14 = var14 * 0.96F + 0.03F;
841                    var15 = var15 * 0.96F + 0.03F;
842    
843                    if (var13 > 1.0F)
844                    {
845                        var13 = 1.0F;
846                    }
847    
848                    if (var14 > 1.0F)
849                    {
850                        var14 = 1.0F;
851                    }
852    
853                    if (var15 > 1.0F)
854                    {
855                        var15 = 1.0F;
856                    }
857    
858                    if (var13 < 0.0F)
859                    {
860                        var13 = 0.0F;
861                    }
862    
863                    if (var14 < 0.0F)
864                    {
865                        var14 = 0.0F;
866                    }
867    
868                    if (var15 < 0.0F)
869                    {
870                        var15 = 0.0F;
871                    }
872    
873                    short var20 = 255;
874                    int var21 = (int)(var13 * 255.0F);
875                    int var22 = (int)(var14 * 255.0F);
876                    int var23 = (int)(var15 * 255.0F);
877                    this.lightmapColors[var3] = var20 << 24 | var21 << 16 | var22 << 8 | var23;
878                }
879    
880                this.mc.renderEngine.createTextureFromBytes(this.lightmapColors, 16, 16, this.lightmapTexture);
881            }
882        }
883    
884        /**
885         * Gets the night vision brightness
886         */
887        private float getNightVisionBrightness(EntityPlayer par1EntityPlayer, float par2)
888        {
889            int var3 = par1EntityPlayer.getActivePotionEffect(Potion.nightVision).getDuration();
890            return var3 > 200 ? 1.0F : 0.7F + MathHelper.sin(((float)var3 - par2) * (float)Math.PI * 0.2F) * 0.3F;
891        }
892    
893        /**
894         * Will update any inputs that effect the camera angle (mouse) and then render the world and GUI
895         */
896        public void updateCameraAndRender(float par1)
897        {
898            this.mc.mcProfiler.startSection("lightTex");
899    
900            if (this.lightmapUpdateNeeded)
901            {
902                this.updateLightmap(par1);
903            }
904    
905            this.mc.mcProfiler.endSection();
906            boolean var2 = Display.isActive();
907    
908            if (!var2 && this.mc.gameSettings.pauseOnLostFocus && (!this.mc.gameSettings.touchscreen || !Mouse.isButtonDown(1)))
909            {
910                if (Minecraft.getSystemTime() - this.prevFrameTime > 500L)
911                {
912                    this.mc.displayInGameMenu();
913                }
914            }
915            else
916            {
917                this.prevFrameTime = Minecraft.getSystemTime();
918            }
919    
920            this.mc.mcProfiler.startSection("mouse");
921    
922            if (this.mc.inGameHasFocus && var2)
923            {
924                this.mc.mouseHelper.mouseXYChange();
925                float var3 = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
926                float var4 = var3 * var3 * var3 * 8.0F;
927                float var5 = (float)this.mc.mouseHelper.deltaX * var4;
928                float var6 = (float)this.mc.mouseHelper.deltaY * var4;
929                byte var7 = 1;
930    
931                if (this.mc.gameSettings.invertMouse)
932                {
933                    var7 = -1;
934                }
935    
936                if (this.mc.gameSettings.smoothCamera)
937                {
938                    this.smoothCamYaw += var5;
939                    this.smoothCamPitch += var6;
940                    float var8 = par1 - this.smoothCamPartialTicks;
941                    this.smoothCamPartialTicks = par1;
942                    var5 = this.smoothCamFilterX * var8;
943                    var6 = this.smoothCamFilterY * var8;
944                    this.mc.thePlayer.setAngles(var5, var6 * (float)var7);
945                }
946                else
947                {
948                    this.mc.thePlayer.setAngles(var5, var6 * (float)var7);
949                }
950            }
951    
952            this.mc.mcProfiler.endSection();
953    
954            if (!this.mc.skipRenderWorld)
955            {
956                anaglyphEnable = this.mc.gameSettings.anaglyph;
957                ScaledResolution var13 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
958                int var14 = var13.getScaledWidth();
959                int var15 = var13.getScaledHeight();
960                int var16 = Mouse.getX() * var14 / this.mc.displayWidth;
961                int var17 = var15 - Mouse.getY() * var15 / this.mc.displayHeight - 1;
962                int var18 = performanceToFps(this.mc.gameSettings.limitFramerate);
963    
964                if (this.mc.theWorld != null)
965                {
966                    this.mc.mcProfiler.startSection("level");
967    
968                    if (this.mc.gameSettings.limitFramerate == 0)
969                    {
970                        this.renderWorld(par1, 0L);
971                    }
972                    else
973                    {
974                        this.renderWorld(par1, this.renderEndNanoTime + (long)(1000000000 / var18));
975                    }
976    
977                    this.renderEndNanoTime = System.nanoTime();
978                    this.mc.mcProfiler.endStartSection("gui");
979    
980                    if (!this.mc.gameSettings.hideGUI || this.mc.currentScreen != null)
981                    {
982                        this.mc.ingameGUI.renderGameOverlay(par1, this.mc.currentScreen != null, var16, var17);
983                    }
984    
985                    this.mc.mcProfiler.endSection();
986                }
987                else
988                {
989                    GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
990                    GL11.glMatrixMode(GL11.GL_PROJECTION);
991                    GL11.glLoadIdentity();
992                    GL11.glMatrixMode(GL11.GL_MODELVIEW);
993                    GL11.glLoadIdentity();
994                    this.setupOverlayRendering();
995                    this.renderEndNanoTime = System.nanoTime();
996                }
997    
998                if (this.mc.currentScreen != null)
999                {
1000                    GL11.glClear(256);
1001    
1002                    try
1003                    {
1004                        this.mc.currentScreen.drawScreen(var16, var17, par1);
1005                    }
1006                    catch (Throwable var12)
1007                    {
1008                        CrashReport var10 = CrashReport.makeCrashReport(var12, "Rendering screen");
1009                        CrashReportCategory var11 = var10.makeCategory("Screen render details");
1010                        var11.addCrashSectionCallable("Screen name", new CallableScreenName(this));
1011                        var11.addCrashSectionCallable("Mouse location", new CallableMouseLocation(this, var16, var17));
1012                        var11.addCrashSectionCallable("Screen size", new CallableScreenSize(this, var13));
1013                        throw new ReportedException(var10);
1014                    }
1015    
1016                    if (this.mc.currentScreen != null && this.mc.currentScreen.guiParticles != null)
1017                    {
1018                        this.mc.currentScreen.guiParticles.draw(par1);
1019                    }
1020                }
1021            }
1022        }
1023    
1024        public void renderWorld(float par1, long par2)
1025        {
1026            this.mc.mcProfiler.startSection("lightTex");
1027    
1028            if (this.lightmapUpdateNeeded)
1029            {
1030                this.updateLightmap(par1);
1031            }
1032    
1033            GL11.glEnable(GL11.GL_CULL_FACE);
1034            GL11.glEnable(GL11.GL_DEPTH_TEST);
1035    
1036            if (this.mc.renderViewEntity == null)
1037            {
1038                this.mc.renderViewEntity = this.mc.thePlayer;
1039            }
1040    
1041            this.mc.mcProfiler.endStartSection("pick");
1042            this.getMouseOver(par1);
1043            EntityLiving var4 = this.mc.renderViewEntity;
1044            RenderGlobal var5 = this.mc.renderGlobal;
1045            EffectRenderer var6 = this.mc.effectRenderer;
1046            double var7 = var4.lastTickPosX + (var4.posX - var4.lastTickPosX) * (double)par1;
1047            double var9 = var4.lastTickPosY + (var4.posY - var4.lastTickPosY) * (double)par1;
1048            double var11 = var4.lastTickPosZ + (var4.posZ - var4.lastTickPosZ) * (double)par1;
1049            this.mc.mcProfiler.endStartSection("center");
1050    
1051            for (int var13 = 0; var13 < 2; ++var13)
1052            {
1053                if (this.mc.gameSettings.anaglyph)
1054                {
1055                    anaglyphField = var13;
1056    
1057                    if (anaglyphField == 0)
1058                    {
1059                        GL11.glColorMask(false, true, true, false);
1060                    }
1061                    else
1062                    {
1063                        GL11.glColorMask(true, false, false, false);
1064                    }
1065                }
1066    
1067                this.mc.mcProfiler.endStartSection("clear");
1068                GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
1069                this.updateFogColor(par1);
1070                GL11.glClear(16640);
1071                GL11.glEnable(GL11.GL_CULL_FACE);
1072                this.mc.mcProfiler.endStartSection("camera");
1073                this.setupCameraTransform(par1, var13);
1074                ActiveRenderInfo.updateRenderInfo(this.mc.thePlayer, this.mc.gameSettings.thirdPersonView == 2);
1075                this.mc.mcProfiler.endStartSection("frustrum");
1076                ClippingHelperImpl.getInstance();
1077    
1078                if (this.mc.gameSettings.renderDistance < 2)
1079                {
1080                    this.setupFog(-1, par1);
1081                    this.mc.mcProfiler.endStartSection("sky");
1082                    var5.renderSky(par1);
1083                }
1084    
1085                GL11.glEnable(GL11.GL_FOG);
1086                this.setupFog(1, par1);
1087    
1088                if (this.mc.gameSettings.ambientOcclusion)
1089                {
1090                    GL11.glShadeModel(GL11.GL_SMOOTH);
1091                }
1092    
1093                this.mc.mcProfiler.endStartSection("culling");
1094                Frustrum var14 = new Frustrum();
1095                var14.setPosition(var7, var9, var11);
1096                this.mc.renderGlobal.clipRenderersByFrustum(var14, par1);
1097    
1098                if (var13 == 0)
1099                {
1100                    this.mc.mcProfiler.endStartSection("updatechunks");
1101    
1102                    while (!this.mc.renderGlobal.updateRenderers(var4, false) && par2 != 0L)
1103                    {
1104                        long var15 = par2 - System.nanoTime();
1105    
1106                        if (var15 < 0L || var15 > 1000000000L)
1107                        {
1108                            break;
1109                        }
1110                    }
1111                }
1112    
1113                if (var4.posY < 128.0D)
1114                {
1115                    this.renderCloudsCheck(var5, par1);
1116                }
1117    
1118                this.setupFog(0, par1);
1119                GL11.glEnable(GL11.GL_FOG);
1120                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/terrain.png"));
1121                RenderHelper.disableStandardItemLighting();
1122                this.mc.mcProfiler.endStartSection("terrain");
1123                var5.sortAndRender(var4, 0, (double)par1);
1124                GL11.glShadeModel(GL11.GL_FLAT);
1125                EntityPlayer var17;
1126    
1127                if (this.debugViewDirection == 0)
1128                {
1129                    RenderHelper.enableStandardItemLighting();
1130                    this.mc.mcProfiler.endStartSection("entities");
1131                    var5.renderEntities(var4.getPosition(par1), var14, par1);
1132                    this.enableLightmap((double)par1);
1133                    this.mc.mcProfiler.endStartSection("litParticles");
1134                    var6.renderLitParticles(var4, par1);
1135                    RenderHelper.disableStandardItemLighting();
1136                    this.setupFog(0, par1);
1137                    this.mc.mcProfiler.endStartSection("particles");
1138                    var6.renderParticles(var4, par1);
1139                    this.disableLightmap((double)par1);
1140    
1141                    if (this.mc.objectMouseOver != null && var4.isInsideOfMaterial(Material.water) && var4 instanceof EntityPlayer && !this.mc.gameSettings.hideGUI)
1142                    {
1143                        var17 = (EntityPlayer)var4;
1144                        GL11.glDisable(GL11.GL_ALPHA_TEST);
1145                        this.mc.mcProfiler.endStartSection("outline");
1146                        if (!ForgeHooksClient.onDrawBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))
1147                        {
1148                            var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1149                            var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1150                        }
1151                        GL11.glEnable(GL11.GL_ALPHA_TEST);
1152                    }
1153                }
1154    
1155                GL11.glDisable(GL11.GL_BLEND);
1156                GL11.glEnable(GL11.GL_CULL_FACE);
1157                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
1158                GL11.glDepthMask(true);
1159                this.setupFog(0, par1);
1160                GL11.glEnable(GL11.GL_BLEND);
1161                GL11.glDisable(GL11.GL_CULL_FACE);
1162                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/terrain.png"));
1163    
1164                if (this.mc.gameSettings.fancyGraphics)
1165                {
1166                    this.mc.mcProfiler.endStartSection("water");
1167    
1168                    if (this.mc.gameSettings.ambientOcclusion)
1169                    {
1170                        GL11.glShadeModel(GL11.GL_SMOOTH);
1171                    }
1172    
1173                    GL11.glColorMask(false, false, false, false);
1174                    int var18 = var5.sortAndRender(var4, 1, (double)par1);
1175    
1176                    if (this.mc.gameSettings.anaglyph)
1177                    {
1178                        if (anaglyphField == 0)
1179                        {
1180                            GL11.glColorMask(false, true, true, true);
1181                        }
1182                        else
1183                        {
1184                            GL11.glColorMask(true, false, false, true);
1185                        }
1186                    }
1187                    else
1188                    {
1189                        GL11.glColorMask(true, true, true, true);
1190                    }
1191    
1192                    if (var18 > 0)
1193                    {
1194                        var5.renderAllRenderLists(1, (double)par1);
1195                    }
1196    
1197                    GL11.glShadeModel(GL11.GL_FLAT);
1198                }
1199                else
1200                {
1201                    this.mc.mcProfiler.endStartSection("water");
1202                    var5.sortAndRender(var4, 1, (double)par1);
1203                }
1204    
1205                GL11.glDepthMask(true);
1206                GL11.glEnable(GL11.GL_CULL_FACE);
1207                GL11.glDisable(GL11.GL_BLEND);
1208    
1209                if (this.cameraZoom == 1.0D && var4 instanceof EntityPlayer && !this.mc.gameSettings.hideGUI && this.mc.objectMouseOver != null && !var4.isInsideOfMaterial(Material.water))
1210                {
1211                    var17 = (EntityPlayer)var4;
1212                    GL11.glDisable(GL11.GL_ALPHA_TEST);
1213                    this.mc.mcProfiler.endStartSection("outline");
1214                    if (!ForgeHooksClient.onDrawBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))
1215                    {
1216                        var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1217                        var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1218                    }
1219                    GL11.glEnable(GL11.GL_ALPHA_TEST);
1220                }
1221    
1222                this.mc.mcProfiler.endStartSection("destroyProgress");
1223                GL11.glEnable(GL11.GL_BLEND);
1224                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
1225                var5.drawBlockDamageTexture(Tessellator.instance, var4, par1);
1226                GL11.glDisable(GL11.GL_BLEND);
1227                this.mc.mcProfiler.endStartSection("weather");
1228                this.renderRainSnow(par1);
1229                GL11.glDisable(GL11.GL_FOG);
1230    
1231                if (var4.posY >= 128.0D)
1232                {
1233                    this.renderCloudsCheck(var5, par1);
1234                }
1235    
1236                this.mc.mcProfiler.endStartSection("FRenderLast");
1237                ForgeHooksClient.dispatchRenderLast(var5, par1);
1238    
1239                this.mc.mcProfiler.endStartSection("hand");
1240    
1241                if (this.cameraZoom == 1.0D)
1242                {
1243                    GL11.glClear(256);
1244                    this.renderHand(par1, var13);
1245                }
1246    
1247                if (!this.mc.gameSettings.anaglyph)
1248                {
1249                    this.mc.mcProfiler.endSection();
1250                    return;
1251                }
1252            }
1253    
1254            GL11.glColorMask(true, true, true, false);
1255            this.mc.mcProfiler.endSection();
1256        }
1257    
1258        /**
1259         * Render clouds if enabled
1260         */
1261        private void renderCloudsCheck(RenderGlobal par1RenderGlobal, float par2)
1262        {
1263            if (this.mc.gameSettings.shouldRenderClouds())
1264            {
1265                this.mc.mcProfiler.endStartSection("clouds");
1266                GL11.glPushMatrix();
1267                this.setupFog(0, par2);
1268                GL11.glEnable(GL11.GL_FOG);
1269                par1RenderGlobal.renderClouds(par2);
1270                GL11.glDisable(GL11.GL_FOG);
1271                this.setupFog(1, par2);
1272                GL11.glPopMatrix();
1273            }
1274        }
1275    
1276        private void addRainParticles()
1277        {
1278            float var1 = this.mc.theWorld.getRainStrength(1.0F);
1279    
1280            if (!this.mc.gameSettings.fancyGraphics)
1281            {
1282                var1 /= 2.0F;
1283            }
1284    
1285            if (var1 != 0.0F)
1286            {
1287                this.random.setSeed((long)this.rendererUpdateCount * 312987231L);
1288                EntityLiving var2 = this.mc.renderViewEntity;
1289                WorldClient var3 = this.mc.theWorld;
1290                int var4 = MathHelper.floor_double(var2.posX);
1291                int var5 = MathHelper.floor_double(var2.posY);
1292                int var6 = MathHelper.floor_double(var2.posZ);
1293                byte var7 = 10;
1294                double var8 = 0.0D;
1295                double var10 = 0.0D;
1296                double var12 = 0.0D;
1297                int var14 = 0;
1298                int var15 = (int)(100.0F * var1 * var1);
1299    
1300                if (this.mc.gameSettings.particleSetting == 1)
1301                {
1302                    var15 >>= 1;
1303                }
1304                else if (this.mc.gameSettings.particleSetting == 2)
1305                {
1306                    var15 = 0;
1307                }
1308    
1309                for (int var16 = 0; var16 < var15; ++var16)
1310                {
1311                    int var17 = var4 + this.random.nextInt(var7) - this.random.nextInt(var7);
1312                    int var18 = var6 + this.random.nextInt(var7) - this.random.nextInt(var7);
1313                    int var19 = var3.getPrecipitationHeight(var17, var18);
1314                    int var20 = var3.getBlockId(var17, var19 - 1, var18);
1315                    BiomeGenBase var21 = var3.getBiomeGenForCoords(var17, var18);
1316    
1317                    if (var19 <= var5 + var7 && var19 >= var5 - var7 && var21.canSpawnLightningBolt() && var21.getFloatTemperature() >= 0.2F)
1318                    {
1319                        float var22 = this.random.nextFloat();
1320                        float var23 = this.random.nextFloat();
1321    
1322                        if (var20 > 0)
1323                        {
1324                            if (Block.blocksList[var20].blockMaterial == Material.lava)
1325                            {
1326                                this.mc.effectRenderer.addEffect(new EntitySmokeFX(var3, (double)((float)var17 + var22), (double)((float)var19 + 0.1F) - Block.blocksList[var20].getBlockBoundsMinY(), (double)((float)var18 + var23), 0.0D, 0.0D, 0.0D));
1327                            }
1328                            else
1329                            {
1330                                ++var14;
1331    
1332                                if (this.random.nextInt(var14) == 0)
1333                                {
1334                                    var8 = (double)((float)var17 + var22);
1335                                    var10 = (double)((float)var19 + 0.1F) - Block.blocksList[var20].getBlockBoundsMinY();
1336                                    var12 = (double)((float)var18 + var23);
1337                                }
1338    
1339                                this.mc.effectRenderer.addEffect(new EntityRainFX(var3, (double)((float)var17 + var22), (double)((float)var19 + 0.1F) - Block.blocksList[var20].getBlockBoundsMinY(), (double)((float)var18 + var23)));
1340                            }
1341                        }
1342                    }
1343                }
1344    
1345                if (var14 > 0 && this.random.nextInt(3) < this.rainSoundCounter++)
1346                {
1347                    this.rainSoundCounter = 0;
1348    
1349                    if (var10 > var2.posY + 1.0D && var3.getPrecipitationHeight(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posZ)) > MathHelper.floor_double(var2.posY))
1350                    {
1351                        this.mc.theWorld.playSound(var8, var10, var12, "ambient.weather.rain", 0.1F, 0.5F, false);
1352                    }
1353                    else
1354                    {
1355                        this.mc.theWorld.playSound(var8, var10, var12, "ambient.weather.rain", 0.2F, 1.0F, false);
1356                    }
1357                }
1358            }
1359        }
1360    
1361        /**
1362         * Render rain and snow
1363         */
1364        protected void renderRainSnow(float par1)
1365        {
1366            float var2 = this.mc.theWorld.getRainStrength(par1);
1367    
1368            if (var2 > 0.0F)
1369            {
1370                this.enableLightmap((double)par1);
1371    
1372                if (this.rainXCoords == null)
1373                {
1374                    this.rainXCoords = new float[1024];
1375                    this.rainYCoords = new float[1024];
1376    
1377                    for (int var3 = 0; var3 < 32; ++var3)
1378                    {
1379                        for (int var4 = 0; var4 < 32; ++var4)
1380                        {
1381                            float var5 = (float)(var4 - 16);
1382                            float var6 = (float)(var3 - 16);
1383                            float var7 = MathHelper.sqrt_float(var5 * var5 + var6 * var6);
1384                            this.rainXCoords[var3 << 5 | var4] = -var6 / var7;
1385                            this.rainYCoords[var3 << 5 | var4] = var5 / var7;
1386                        }
1387                    }
1388                }
1389    
1390                EntityLiving var41 = this.mc.renderViewEntity;
1391                WorldClient var42 = this.mc.theWorld;
1392                int var43 = MathHelper.floor_double(var41.posX);
1393                int var44 = MathHelper.floor_double(var41.posY);
1394                int var45 = MathHelper.floor_double(var41.posZ);
1395                Tessellator var8 = Tessellator.instance;
1396                GL11.glDisable(GL11.GL_CULL_FACE);
1397                GL11.glNormal3f(0.0F, 1.0F, 0.0F);
1398                GL11.glEnable(GL11.GL_BLEND);
1399                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
1400                GL11.glAlphaFunc(GL11.GL_GREATER, 0.01F);
1401                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/environment/snow.png"));
1402                double var9 = var41.lastTickPosX + (var41.posX - var41.lastTickPosX) * (double)par1;
1403                double var11 = var41.lastTickPosY + (var41.posY - var41.lastTickPosY) * (double)par1;
1404                double var13 = var41.lastTickPosZ + (var41.posZ - var41.lastTickPosZ) * (double)par1;
1405                int var15 = MathHelper.floor_double(var11);
1406                byte var16 = 5;
1407    
1408                if (this.mc.gameSettings.fancyGraphics)
1409                {
1410                    var16 = 10;
1411                }
1412    
1413                boolean var17 = false;
1414                byte var18 = -1;
1415                float var19 = (float)this.rendererUpdateCount + par1;
1416    
1417                if (this.mc.gameSettings.fancyGraphics)
1418                {
1419                    var16 = 10;
1420                }
1421    
1422                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
1423                var17 = false;
1424    
1425                for (int var20 = var45 - var16; var20 <= var45 + var16; ++var20)
1426                {
1427                    for (int var21 = var43 - var16; var21 <= var43 + var16; ++var21)
1428                    {
1429                        int var22 = (var20 - var45 + 16) * 32 + var21 - var43 + 16;
1430                        float var23 = this.rainXCoords[var22] * 0.5F;
1431                        float var24 = this.rainYCoords[var22] * 0.5F;
1432                        BiomeGenBase var25 = var42.getBiomeGenForCoords(var21, var20);
1433    
1434                        if (var25.canSpawnLightningBolt() || var25.getEnableSnow())
1435                        {
1436                            int var26 = var42.getPrecipitationHeight(var21, var20);
1437                            int var27 = var44 - var16;
1438                            int var28 = var44 + var16;
1439    
1440                            if (var27 < var26)
1441                            {
1442                                var27 = var26;
1443                            }
1444    
1445                            if (var28 < var26)
1446                            {
1447                                var28 = var26;
1448                            }
1449    
1450                            float var29 = 1.0F;
1451                            int var30 = var26;
1452    
1453                            if (var26 < var15)
1454                            {
1455                                var30 = var15;
1456                            }
1457    
1458                            if (var27 != var28)
1459                            {
1460                                this.random.setSeed((long)(var21 * var21 * 3121 + var21 * 45238971 ^ var20 * var20 * 418711 + var20 * 13761));
1461                                float var31 = var25.getFloatTemperature();
1462                                double var35;
1463                                float var32;
1464    
1465                                if (var42.getWorldChunkManager().getTemperatureAtHeight(var31, var26) >= 0.15F)
1466                                {
1467                                    if (var18 != 0)
1468                                    {
1469                                        if (var18 >= 0)
1470                                        {
1471                                            var8.draw();
1472                                        }
1473    
1474                                        var18 = 0;
1475                                        GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/environment/rain.png"));
1476                                        var8.startDrawingQuads();
1477                                    }
1478    
1479                                    var32 = ((float)(this.rendererUpdateCount + var21 * var21 * 3121 + var21 * 45238971 + var20 * var20 * 418711 + var20 * 13761 & 31) + par1) / 32.0F * (3.0F + this.random.nextFloat());
1480                                    double var33 = (double)((float)var21 + 0.5F) - var41.posX;
1481                                    var35 = (double)((float)var20 + 0.5F) - var41.posZ;
1482                                    float var37 = MathHelper.sqrt_double(var33 * var33 + var35 * var35) / (float)var16;
1483                                    float var38 = 1.0F;
1484                                    var8.setBrightness(var42.getLightBrightnessForSkyBlocks(var21, var30, var20, 0));
1485                                    var8.setColorRGBA_F(var38, var38, var38, ((1.0F - var37 * var37) * 0.5F + 0.5F) * var2);
1486                                    var8.setTranslation(-var9 * 1.0D, -var11 * 1.0D, -var13 * 1.0D);
1487                                    var8.addVertexWithUV((double)((float)var21 - var23) + 0.5D, (double)var27, (double)((float)var20 - var24) + 0.5D, (double)(0.0F * var29), (double)((float)var27 * var29 / 4.0F + var32 * var29));
1488                                    var8.addVertexWithUV((double)((float)var21 + var23) + 0.5D, (double)var27, (double)((float)var20 + var24) + 0.5D, (double)(1.0F * var29), (double)((float)var27 * var29 / 4.0F + var32 * var29));
1489                                    var8.addVertexWithUV((double)((float)var21 + var23) + 0.5D, (double)var28, (double)((float)var20 + var24) + 0.5D, (double)(1.0F * var29), (double)((float)var28 * var29 / 4.0F + var32 * var29));
1490                                    var8.addVertexWithUV((double)((float)var21 - var23) + 0.5D, (double)var28, (double)((float)var20 - var24) + 0.5D, (double)(0.0F * var29), (double)((float)var28 * var29 / 4.0F + var32 * var29));
1491                                    var8.setTranslation(0.0D, 0.0D, 0.0D);
1492                                }
1493                                else
1494                                {
1495                                    if (var18 != 1)
1496                                    {
1497                                        if (var18 >= 0)
1498                                        {
1499                                            var8.draw();
1500                                        }
1501    
1502                                        var18 = 1;
1503                                        GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/environment/snow.png"));
1504                                        var8.startDrawingQuads();
1505                                    }
1506    
1507                                    var32 = ((float)(this.rendererUpdateCount & 511) + par1) / 512.0F;
1508                                    float var46 = this.random.nextFloat() + var19 * 0.01F * (float)this.random.nextGaussian();
1509                                    float var34 = this.random.nextFloat() + var19 * (float)this.random.nextGaussian() * 0.001F;
1510                                    var35 = (double)((float)var21 + 0.5F) - var41.posX;
1511                                    double var47 = (double)((float)var20 + 0.5F) - var41.posZ;
1512                                    float var39 = MathHelper.sqrt_double(var35 * var35 + var47 * var47) / (float)var16;
1513                                    float var40 = 1.0F;
1514                                    var8.setBrightness((var42.getLightBrightnessForSkyBlocks(var21, var30, var20, 0) * 3 + 15728880) / 4);
1515                                    var8.setColorRGBA_F(var40, var40, var40, ((1.0F - var39 * var39) * 0.3F + 0.5F) * var2);
1516                                    var8.setTranslation(-var9 * 1.0D, -var11 * 1.0D, -var13 * 1.0D);
1517                                    var8.addVertexWithUV((double)((float)var21 - var23) + 0.5D, (double)var27, (double)((float)var20 - var24) + 0.5D, (double)(0.0F * var29 + var46), (double)((float)var27 * var29 / 4.0F + var32 * var29 + var34));
1518                                    var8.addVertexWithUV((double)((float)var21 + var23) + 0.5D, (double)var27, (double)((float)var20 + var24) + 0.5D, (double)(1.0F * var29 + var46), (double)((float)var27 * var29 / 4.0F + var32 * var29 + var34));
1519                                    var8.addVertexWithUV((double)((float)var21 + var23) + 0.5D, (double)var28, (double)((float)var20 + var24) + 0.5D, (double)(1.0F * var29 + var46), (double)((float)var28 * var29 / 4.0F + var32 * var29 + var34));
1520                                    var8.addVertexWithUV((double)((float)var21 - var23) + 0.5D, (double)var28, (double)((float)var20 - var24) + 0.5D, (double)(0.0F * var29 + var46), (double)((float)var28 * var29 / 4.0F + var32 * var29 + var34));
1521                                    var8.setTranslation(0.0D, 0.0D, 0.0D);
1522                                }
1523                            }
1524                        }
1525                    }
1526                }
1527    
1528                if (var18 >= 0)
1529                {
1530                    var8.draw();
1531                }
1532    
1533                GL11.glEnable(GL11.GL_CULL_FACE);
1534                GL11.glDisable(GL11.GL_BLEND);
1535                GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
1536                this.disableLightmap((double)par1);
1537            }
1538        }
1539    
1540        /**
1541         * Setup orthogonal projection for rendering GUI screen overlays
1542         */
1543        public void setupOverlayRendering()
1544        {
1545            ScaledResolution var1 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
1546            GL11.glClear(256);
1547            GL11.glMatrixMode(GL11.GL_PROJECTION);
1548            GL11.glLoadIdentity();
1549            GL11.glOrtho(0.0D, var1.getScaledWidth_double(), var1.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D);
1550            GL11.glMatrixMode(GL11.GL_MODELVIEW);
1551            GL11.glLoadIdentity();
1552            GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
1553        }
1554    
1555        /**
1556         * calculates fog and calls glClearColor
1557         */
1558        private void updateFogColor(float par1)
1559        {
1560            WorldClient var2 = this.mc.theWorld;
1561            EntityLiving var3 = this.mc.renderViewEntity;
1562            float var4 = 1.0F / (float)(4 - this.mc.gameSettings.renderDistance);
1563            var4 = 1.0F - (float)Math.pow((double)var4, 0.25D);
1564            Vec3 var5 = var2.getSkyColor(this.mc.renderViewEntity, par1);
1565            float var6 = (float)var5.xCoord;
1566            float var7 = (float)var5.yCoord;
1567            float var8 = (float)var5.zCoord;
1568            Vec3 var9 = var2.getFogColor(par1);
1569            this.fogColorRed = (float)var9.xCoord;
1570            this.fogColorGreen = (float)var9.yCoord;
1571            this.fogColorBlue = (float)var9.zCoord;
1572            float var11;
1573    
1574            if (this.mc.gameSettings.renderDistance < 2)
1575            {
1576                Vec3 var10 = MathHelper.sin(var2.getCelestialAngleRadians(par1)) > 0.0F ? var2.getWorldVec3Pool().getVecFromPool(-1.0D, 0.0D, 0.0D) : var2.getWorldVec3Pool().getVecFromPool(1.0D, 0.0D, 0.0D);
1577                var11 = (float)var3.getLook(par1).dotProduct(var10);
1578    
1579                if (var11 < 0.0F)
1580                {
1581                    var11 = 0.0F;
1582                }
1583    
1584                if (var11 > 0.0F)
1585                {
1586                    float[] var12 = var2.provider.calcSunriseSunsetColors(var2.getCelestialAngle(par1), par1);
1587    
1588                    if (var12 != null)
1589                    {
1590                        var11 *= var12[3];
1591                        this.fogColorRed = this.fogColorRed * (1.0F - var11) + var12[0] * var11;
1592                        this.fogColorGreen = this.fogColorGreen * (1.0F - var11) + var12[1] * var11;
1593                        this.fogColorBlue = this.fogColorBlue * (1.0F - var11) + var12[2] * var11;
1594                    }
1595                }
1596            }
1597    
1598            this.fogColorRed += (var6 - this.fogColorRed) * var4;
1599            this.fogColorGreen += (var7 - this.fogColorGreen) * var4;
1600            this.fogColorBlue += (var8 - this.fogColorBlue) * var4;
1601            float var19 = var2.getRainStrength(par1);
1602            float var20;
1603    
1604            if (var19 > 0.0F)
1605            {
1606                var11 = 1.0F - var19 * 0.5F;
1607                var20 = 1.0F - var19 * 0.4F;
1608                this.fogColorRed *= var11;
1609                this.fogColorGreen *= var11;
1610                this.fogColorBlue *= var20;
1611            }
1612    
1613            var11 = var2.getWeightedThunderStrength(par1);
1614    
1615            if (var11 > 0.0F)
1616            {
1617                var20 = 1.0F - var11 * 0.5F;
1618                this.fogColorRed *= var20;
1619                this.fogColorGreen *= var20;
1620                this.fogColorBlue *= var20;
1621            }
1622    
1623            int var21 = ActiveRenderInfo.getBlockIdAtEntityViewpoint(this.mc.theWorld, var3, par1);
1624    
1625            if (this.cloudFog)
1626            {
1627                Vec3 var13 = var2.drawClouds(par1);
1628                this.fogColorRed = (float)var13.xCoord;
1629                this.fogColorGreen = (float)var13.yCoord;
1630                this.fogColorBlue = (float)var13.zCoord;
1631            }
1632            else if (var21 != 0 && Block.blocksList[var21].blockMaterial == Material.water)
1633            {
1634                this.fogColorRed = 0.02F;
1635                this.fogColorGreen = 0.02F;
1636                this.fogColorBlue = 0.2F;
1637            }
1638            else if (var21 != 0 && Block.blocksList[var21].blockMaterial == Material.lava)
1639            {
1640                this.fogColorRed = 0.6F;
1641                this.fogColorGreen = 0.1F;
1642                this.fogColorBlue = 0.0F;
1643            }
1644    
1645            float var22 = this.fogColor2 + (this.fogColor1 - this.fogColor2) * par1;
1646            this.fogColorRed *= var22;
1647            this.fogColorGreen *= var22;
1648            this.fogColorBlue *= var22;
1649            double var14 = (var3.lastTickPosY + (var3.posY - var3.lastTickPosY) * (double)par1) * var2.provider.getVoidFogYFactor();
1650    
1651            if (var3.isPotionActive(Potion.blindness))
1652            {
1653                int var16 = var3.getActivePotionEffect(Potion.blindness).getDuration();
1654    
1655                if (var16 < 20)
1656                {
1657                    var14 *= (double)(1.0F - (float)var16 / 20.0F);
1658                }
1659                else
1660                {
1661                    var14 = 0.0D;
1662                }
1663            }
1664    
1665            if (var14 < 1.0D)
1666            {
1667                if (var14 < 0.0D)
1668                {
1669                    var14 = 0.0D;
1670                }
1671    
1672                var14 *= var14;
1673                this.fogColorRed = (float)((double)this.fogColorRed * var14);
1674                this.fogColorGreen = (float)((double)this.fogColorGreen * var14);
1675                this.fogColorBlue = (float)((double)this.fogColorBlue * var14);
1676            }
1677    
1678            float var23;
1679    
1680            if (this.field_82831_U > 0.0F)
1681            {
1682                var23 = this.field_82832_V + (this.field_82831_U - this.field_82832_V) * par1;
1683                this.fogColorRed = this.fogColorRed * (1.0F - var23) + this.fogColorRed * 0.7F * var23;
1684                this.fogColorGreen = this.fogColorGreen * (1.0F - var23) + this.fogColorGreen * 0.6F * var23;
1685                this.fogColorBlue = this.fogColorBlue * (1.0F - var23) + this.fogColorBlue * 0.6F * var23;
1686            }
1687    
1688            float var17;
1689    
1690            if (var3.isPotionActive(Potion.nightVision))
1691            {
1692                var23 = this.getNightVisionBrightness(this.mc.thePlayer, par1);
1693                var17 = 1.0F / this.fogColorRed;
1694    
1695                if (var17 > 1.0F / this.fogColorGreen)
1696                {
1697                    var17 = 1.0F / this.fogColorGreen;
1698                }
1699    
1700                if (var17 > 1.0F / this.fogColorBlue)
1701                {
1702                    var17 = 1.0F / this.fogColorBlue;
1703                }
1704    
1705                this.fogColorRed = this.fogColorRed * (1.0F - var23) + this.fogColorRed * var17 * var23;
1706                this.fogColorGreen = this.fogColorGreen * (1.0F - var23) + this.fogColorGreen * var17 * var23;
1707                this.fogColorBlue = this.fogColorBlue * (1.0F - var23) + this.fogColorBlue * var17 * var23;
1708            }
1709    
1710            if (this.mc.gameSettings.anaglyph)
1711            {
1712                var23 = (this.fogColorRed * 30.0F + this.fogColorGreen * 59.0F + this.fogColorBlue * 11.0F) / 100.0F;
1713                var17 = (this.fogColorRed * 30.0F + this.fogColorGreen * 70.0F) / 100.0F;
1714                float var18 = (this.fogColorRed * 30.0F + this.fogColorBlue * 70.0F) / 100.0F;
1715                this.fogColorRed = var23;
1716                this.fogColorGreen = var17;
1717                this.fogColorBlue = var18;
1718            }
1719    
1720            GL11.glClearColor(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 0.0F);
1721        }
1722    
1723        /**
1724         * Sets up the fog to be rendered. If the arg passed in is -1 the fog starts at 0 and goes to 80% of far plane
1725         * distance and is used for sky rendering.
1726         */
1727        private void setupFog(int par1, float par2)
1728        {
1729            EntityLiving var3 = this.mc.renderViewEntity;
1730            boolean var4 = false;
1731    
1732            if (var3 instanceof EntityPlayer)
1733            {
1734                var4 = ((EntityPlayer)var3).capabilities.isCreativeMode;
1735            }
1736    
1737            if (par1 == 999)
1738            {
1739                GL11.glFog(GL11.GL_FOG_COLOR, this.setFogColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
1740                GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);
1741                GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1742                GL11.glFogf(GL11.GL_FOG_END, 8.0F);
1743    
1744                if (GLContext.getCapabilities().GL_NV_fog_distance)
1745                {
1746                    GL11.glFogi(34138, 34139);
1747                }
1748    
1749                GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1750            }
1751            else
1752            {
1753                GL11.glFog(GL11.GL_FOG_COLOR, this.setFogColorBuffer(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 1.0F));
1754                GL11.glNormal3f(0.0F, -1.0F, 0.0F);
1755                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
1756                int var5 = ActiveRenderInfo.getBlockIdAtEntityViewpoint(this.mc.theWorld, var3, par2);
1757                float var6;
1758    
1759                if (var3.isPotionActive(Potion.blindness))
1760                {
1761                    var6 = 5.0F;
1762                    int var7 = var3.getActivePotionEffect(Potion.blindness).getDuration();
1763    
1764                    if (var7 < 20)
1765                    {
1766                        var6 = 5.0F + (this.farPlaneDistance - 5.0F) * (1.0F - (float)var7 / 20.0F);
1767                    }
1768    
1769                    GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);
1770    
1771                    if (par1 < 0)
1772                    {
1773                        GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1774                        GL11.glFogf(GL11.GL_FOG_END, var6 * 0.8F);
1775                    }
1776                    else
1777                    {
1778                        GL11.glFogf(GL11.GL_FOG_START, var6 * 0.25F);
1779                        GL11.glFogf(GL11.GL_FOG_END, var6);
1780                    }
1781    
1782                    if (GLContext.getCapabilities().GL_NV_fog_distance)
1783                    {
1784                        GL11.glFogi(34138, 34139);
1785                    }
1786                }
1787                else
1788                {
1789                    float var8;
1790                    float var9;
1791                    float var10;
1792                    float var11;
1793                    float var12;
1794    
1795                    if (this.cloudFog)
1796                    {
1797                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);
1798                        GL11.glFogf(GL11.GL_FOG_DENSITY, 0.1F);
1799                        var6 = 1.0F;
1800                        var12 = 1.0F;
1801                        var8 = 1.0F;
1802    
1803                        if (this.mc.gameSettings.anaglyph)
1804                        {
1805                            var9 = (var6 * 30.0F + var12 * 59.0F + var8 * 11.0F) / 100.0F;
1806                            var10 = (var6 * 30.0F + var12 * 70.0F) / 100.0F;
1807                            var11 = (var6 * 30.0F + var8 * 70.0F) / 100.0F;
1808                        }
1809                    }
1810                    else if (var5 > 0 && Block.blocksList[var5].blockMaterial == Material.water)
1811                    {
1812                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);
1813    
1814                        if (var3.isPotionActive(Potion.waterBreathing))
1815                        {
1816                            GL11.glFogf(GL11.GL_FOG_DENSITY, 0.05F);
1817                        }
1818                        else
1819                        {
1820                            GL11.glFogf(GL11.GL_FOG_DENSITY, 0.1F);
1821                        }
1822    
1823                        var6 = 0.4F;
1824                        var12 = 0.4F;
1825                        var8 = 0.9F;
1826    
1827                        if (this.mc.gameSettings.anaglyph)
1828                        {
1829                            var9 = (var6 * 30.0F + var12 * 59.0F + var8 * 11.0F) / 100.0F;
1830                            var10 = (var6 * 30.0F + var12 * 70.0F) / 100.0F;
1831                            var11 = (var6 * 30.0F + var8 * 70.0F) / 100.0F;
1832                        }
1833                    }
1834                    else if (var5 > 0 && Block.blocksList[var5].blockMaterial == Material.lava)
1835                    {
1836                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);
1837                        GL11.glFogf(GL11.GL_FOG_DENSITY, 2.0F);
1838                        var6 = 0.4F;
1839                        var12 = 0.3F;
1840                        var8 = 0.3F;
1841    
1842                        if (this.mc.gameSettings.anaglyph)
1843                        {
1844                            var9 = (var6 * 30.0F + var12 * 59.0F + var8 * 11.0F) / 100.0F;
1845                            var10 = (var6 * 30.0F + var12 * 70.0F) / 100.0F;
1846                            var11 = (var6 * 30.0F + var8 * 70.0F) / 100.0F;
1847                        }
1848                    }
1849                    else
1850                    {
1851                        var6 = this.farPlaneDistance;
1852    
1853                        if (this.mc.theWorld.provider.getWorldHasVoidParticles() && !var4)
1854                        {
1855                            double var13 = (double)((var3.getBrightnessForRender(par2) & 15728640) >> 20) / 16.0D + (var3.lastTickPosY + (var3.posY - var3.lastTickPosY) * (double)par2 + 4.0D) / 32.0D;
1856    
1857                            if (var13 < 1.0D)
1858                            {
1859                                if (var13 < 0.0D)
1860                                {
1861                                    var13 = 0.0D;
1862                                }
1863    
1864                                var13 *= var13;
1865                                var9 = 100.0F * (float)var13;
1866    
1867                                if (var9 < 5.0F)
1868                                {
1869                                    var9 = 5.0F;
1870                                }
1871    
1872                                if (var6 > var9)
1873                                {
1874                                    var6 = var9;
1875                                }
1876                            }
1877                        }
1878    
1879                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);
1880    
1881                        if (par1 < 0)
1882                        {
1883                            GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1884                            GL11.glFogf(GL11.GL_FOG_END, var6 * 0.8F);
1885                        }
1886                        else
1887                        {
1888                            GL11.glFogf(GL11.GL_FOG_START, var6 * 0.25F);
1889                            GL11.glFogf(GL11.GL_FOG_END, var6);
1890                        }
1891    
1892                        if (GLContext.getCapabilities().GL_NV_fog_distance)
1893                        {
1894                            GL11.glFogi(34138, 34139);
1895                        }
1896    
1897                        if (this.mc.theWorld.provider.doesXZShowFog((int)var3.posX, (int)var3.posZ))
1898                        {
1899                            GL11.glFogf(GL11.GL_FOG_START, var6 * 0.05F);
1900                            GL11.glFogf(GL11.GL_FOG_END, Math.min(var6, 192.0F) * 0.5F);
1901                        }
1902                    }
1903                }
1904    
1905                GL11.glEnable(GL11.GL_COLOR_MATERIAL);
1906                GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT);
1907            }
1908        }
1909    
1910        /**
1911         * Update and return fogColorBuffer with the RGBA values passed as arguments
1912         */
1913        private FloatBuffer setFogColorBuffer(float par1, float par2, float par3, float par4)
1914        {
1915            this.fogColorBuffer.clear();
1916            this.fogColorBuffer.put(par1).put(par2).put(par3).put(par4);
1917            this.fogColorBuffer.flip();
1918            return this.fogColorBuffer;
1919        }
1920    
1921        /**
1922         * Converts performance value (0-2) to FPS (35-200)
1923         */
1924        public static int performanceToFps(int par0)
1925        {
1926            short var1 = 200;
1927    
1928            if (par0 == 1)
1929            {
1930                var1 = 120;
1931            }
1932    
1933            if (par0 == 2)
1934            {
1935                var1 = 35;
1936            }
1937    
1938            return var1;
1939        }
1940    
1941        /**
1942         * Get minecraft reference from the EntityRenderer
1943         */
1944        static Minecraft getRendererMinecraft(EntityRenderer par0EntityRenderer)
1945        {
1946            return par0EntityRenderer.mc;
1947        }
1948    }