001    package net.minecraft.client.renderer;
002    
003    import cpw.mods.fml.common.Side;
004    import cpw.mods.fml.common.asm.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.func_76333_a(this.smoothCamYaw, 0.05F * var2);
219                this.smoothCamFilterY = this.mouseFilterYAxis.func_76333_a(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.func_72721_a(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.func_72971_b(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.lightningFlash > 0)
761                    {
762                        var5 = var2.provider.lightBrightnessTable[var3 / 16];
763                    }
764    
765                    float var7 = var5 * (var2.func_72971_b(1.0F) * 0.65F + 0.35F);
766                    float var8 = var5 * (var2.func_72971_b(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.func_82830_a(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        private float func_82830_a(EntityPlayer par1EntityPlayer, float par2)
885        {
886            int var3 = par1EntityPlayer.getActivePotionEffect(Potion.nightVision).getDuration();
887            return var3 > 200 ? 1.0F : 0.7F + MathHelper.sin(((float)var3 - par2) * (float)Math.PI * 0.2F) * 0.3F;
888        }
889    
890        /**
891         * Will update any inputs that effect the camera angle (mouse) and then render the world and GUI
892         */
893        public void updateCameraAndRender(float par1)
894        {
895            this.mc.mcProfiler.startSection("lightTex");
896    
897            if (this.lightmapUpdateNeeded)
898            {
899                this.updateLightmap(par1);
900            }
901    
902            this.mc.mcProfiler.endSection();
903            boolean var2 = Display.isActive();
904    
905            if (!var2 && this.mc.gameSettings.pauseOnLostFocus && (!this.mc.gameSettings.field_85185_A || !Mouse.isButtonDown(1)))
906            {
907                if (Minecraft.getSystemTime() - this.prevFrameTime > 500L)
908                {
909                    this.mc.displayInGameMenu();
910                }
911            }
912            else
913            {
914                this.prevFrameTime = Minecraft.getSystemTime();
915            }
916    
917            this.mc.mcProfiler.startSection("mouse");
918    
919            if (this.mc.inGameHasFocus && var2)
920            {
921                this.mc.mouseHelper.mouseXYChange();
922                float var3 = this.mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
923                float var4 = var3 * var3 * var3 * 8.0F;
924                float var5 = (float)this.mc.mouseHelper.deltaX * var4;
925                float var6 = (float)this.mc.mouseHelper.deltaY * var4;
926                byte var7 = 1;
927    
928                if (this.mc.gameSettings.invertMouse)
929                {
930                    var7 = -1;
931                }
932    
933                if (this.mc.gameSettings.smoothCamera)
934                {
935                    this.smoothCamYaw += var5;
936                    this.smoothCamPitch += var6;
937                    float var8 = par1 - this.smoothCamPartialTicks;
938                    this.smoothCamPartialTicks = par1;
939                    var5 = this.smoothCamFilterX * var8;
940                    var6 = this.smoothCamFilterY * var8;
941                    this.mc.thePlayer.setAngles(var5, var6 * (float)var7);
942                }
943                else
944                {
945                    this.mc.thePlayer.setAngles(var5, var6 * (float)var7);
946                }
947            }
948    
949            this.mc.mcProfiler.endSection();
950    
951            if (!this.mc.skipRenderWorld)
952            {
953                anaglyphEnable = this.mc.gameSettings.anaglyph;
954                ScaledResolution var13 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
955                int var14 = var13.getScaledWidth();
956                int var15 = var13.getScaledHeight();
957                int var16 = Mouse.getX() * var14 / this.mc.displayWidth;
958                int var17 = var15 - Mouse.getY() * var15 / this.mc.displayHeight - 1;
959                int var18 = func_78465_a(this.mc.gameSettings.limitFramerate);
960    
961                if (this.mc.theWorld != null)
962                {
963                    this.mc.mcProfiler.startSection("level");
964    
965                    if (this.mc.gameSettings.limitFramerate == 0)
966                    {
967                        this.renderWorld(par1, 0L);
968                    }
969                    else
970                    {
971                        this.renderWorld(par1, this.renderEndNanoTime + (long)(1000000000 / var18));
972                    }
973    
974                    this.renderEndNanoTime = System.nanoTime();
975                    this.mc.mcProfiler.endStartSection("gui");
976    
977                    if (!this.mc.gameSettings.hideGUI || this.mc.currentScreen != null)
978                    {
979                        this.mc.ingameGUI.renderGameOverlay(par1, this.mc.currentScreen != null, var16, var17);
980                    }
981    
982                    this.mc.mcProfiler.endSection();
983                }
984                else
985                {
986                    GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
987                    GL11.glMatrixMode(GL11.GL_PROJECTION);
988                    GL11.glLoadIdentity();
989                    GL11.glMatrixMode(GL11.GL_MODELVIEW);
990                    GL11.glLoadIdentity();
991                    this.setupOverlayRendering();
992                    this.renderEndNanoTime = System.nanoTime();
993                }
994    
995                if (this.mc.currentScreen != null)
996                {
997                    GL11.glClear(256);
998    
999                    try
1000                    {
1001                        this.mc.currentScreen.drawScreen(var16, var17, par1);
1002                    }
1003                    catch (Throwable var12)
1004                    {
1005                        CrashReport var10 = CrashReport.func_85055_a(var12, "Rendering screen");
1006                        CrashReportCategory var11 = var10.func_85058_a("Screen render details");
1007                        var11.addCrashSectionCallable("Screen name", new CallableScreenName(this));
1008                        var11.addCrashSectionCallable("Mouse location", new CallableMouseLocation(this, var16, var17));
1009                        var11.addCrashSectionCallable("Screen size", new CallableScreenSize(this, var13));
1010                        throw new ReportedException(var10);
1011                    }
1012    
1013                    if (this.mc.currentScreen != null && this.mc.currentScreen.guiParticles != null)
1014                    {
1015                        this.mc.currentScreen.guiParticles.draw(par1);
1016                    }
1017                }
1018            }
1019        }
1020    
1021        public void renderWorld(float par1, long par2)
1022        {
1023            this.mc.mcProfiler.startSection("lightTex");
1024    
1025            if (this.lightmapUpdateNeeded)
1026            {
1027                this.updateLightmap(par1);
1028            }
1029    
1030            GL11.glEnable(GL11.GL_CULL_FACE);
1031            GL11.glEnable(GL11.GL_DEPTH_TEST);
1032    
1033            if (this.mc.renderViewEntity == null)
1034            {
1035                this.mc.renderViewEntity = this.mc.thePlayer;
1036            }
1037    
1038            this.mc.mcProfiler.endStartSection("pick");
1039            this.getMouseOver(par1);
1040            EntityLiving var4 = this.mc.renderViewEntity;
1041            RenderGlobal var5 = this.mc.renderGlobal;
1042            EffectRenderer var6 = this.mc.effectRenderer;
1043            double var7 = var4.lastTickPosX + (var4.posX - var4.lastTickPosX) * (double)par1;
1044            double var9 = var4.lastTickPosY + (var4.posY - var4.lastTickPosY) * (double)par1;
1045            double var11 = var4.lastTickPosZ + (var4.posZ - var4.lastTickPosZ) * (double)par1;
1046            this.mc.mcProfiler.endStartSection("center");
1047    
1048            for (int var13 = 0; var13 < 2; ++var13)
1049            {
1050                if (this.mc.gameSettings.anaglyph)
1051                {
1052                    anaglyphField = var13;
1053    
1054                    if (anaglyphField == 0)
1055                    {
1056                        GL11.glColorMask(false, true, true, false);
1057                    }
1058                    else
1059                    {
1060                        GL11.glColorMask(true, false, false, false);
1061                    }
1062                }
1063    
1064                this.mc.mcProfiler.endStartSection("clear");
1065                GL11.glViewport(0, 0, this.mc.displayWidth, this.mc.displayHeight);
1066                this.updateFogColor(par1);
1067                GL11.glClear(16640);
1068                GL11.glEnable(GL11.GL_CULL_FACE);
1069                this.mc.mcProfiler.endStartSection("camera");
1070                this.setupCameraTransform(par1, var13);
1071                ActiveRenderInfo.updateRenderInfo(this.mc.thePlayer, this.mc.gameSettings.thirdPersonView == 2);
1072                this.mc.mcProfiler.endStartSection("frustrum");
1073                ClippingHelperImpl.getInstance();
1074    
1075                if (this.mc.gameSettings.renderDistance < 2)
1076                {
1077                    this.setupFog(-1, par1);
1078                    this.mc.mcProfiler.endStartSection("sky");
1079                    var5.renderSky(par1);
1080                }
1081    
1082                GL11.glEnable(GL11.GL_FOG);
1083                this.setupFog(1, par1);
1084    
1085                if (this.mc.gameSettings.ambientOcclusion)
1086                {
1087                    GL11.glShadeModel(GL11.GL_SMOOTH);
1088                }
1089    
1090                this.mc.mcProfiler.endStartSection("culling");
1091                Frustrum var14 = new Frustrum();
1092                var14.setPosition(var7, var9, var11);
1093                this.mc.renderGlobal.clipRenderersByFrustum(var14, par1);
1094    
1095                if (var13 == 0)
1096                {
1097                    this.mc.mcProfiler.endStartSection("updatechunks");
1098    
1099                    while (!this.mc.renderGlobal.updateRenderers(var4, false) && par2 != 0L)
1100                    {
1101                        long var15 = par2 - System.nanoTime();
1102    
1103                        if (var15 < 0L || var15 > 1000000000L)
1104                        {
1105                            break;
1106                        }
1107                    }
1108                }
1109    
1110                if (var4.posY < 128.0D)
1111                {
1112                    this.func_82829_a(var5, par1);
1113                }
1114    
1115                this.setupFog(0, par1);
1116                GL11.glEnable(GL11.GL_FOG);
1117                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/terrain.png"));
1118                RenderHelper.disableStandardItemLighting();
1119                this.mc.mcProfiler.endStartSection("terrain");
1120                var5.sortAndRender(var4, 0, (double)par1);
1121                GL11.glShadeModel(GL11.GL_FLAT);
1122                EntityPlayer var17;
1123    
1124                if (this.debugViewDirection == 0)
1125                {
1126                    RenderHelper.enableStandardItemLighting();
1127                    this.mc.mcProfiler.endStartSection("entities");
1128                    var5.renderEntities(var4.getPosition(par1), var14, par1);
1129                    this.enableLightmap((double)par1);
1130                    this.mc.mcProfiler.endStartSection("litParticles");
1131                    var6.renderLitParticles(var4, par1);
1132                    RenderHelper.disableStandardItemLighting();
1133                    this.setupFog(0, par1);
1134                    this.mc.mcProfiler.endStartSection("particles");
1135                    var6.renderParticles(var4, par1);
1136                    this.disableLightmap((double)par1);
1137    
1138                    if (this.mc.objectMouseOver != null && var4.isInsideOfMaterial(Material.water) && var4 instanceof EntityPlayer && !this.mc.gameSettings.hideGUI)
1139                    {
1140                        var17 = (EntityPlayer)var4;
1141                        GL11.glDisable(GL11.GL_ALPHA_TEST);
1142                        this.mc.mcProfiler.endStartSection("outline");
1143                        if (!ForgeHooksClient.onDrawBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))
1144                        {
1145                            var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1146                            var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1147                        }
1148                        GL11.glEnable(GL11.GL_ALPHA_TEST);
1149                    }
1150                }
1151    
1152                GL11.glDisable(GL11.GL_BLEND);
1153                GL11.glEnable(GL11.GL_CULL_FACE);
1154                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
1155                GL11.glDepthMask(true);
1156                this.setupFog(0, par1);
1157                GL11.glEnable(GL11.GL_BLEND);
1158                GL11.glDisable(GL11.GL_CULL_FACE);
1159                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/terrain.png"));
1160    
1161                if (this.mc.gameSettings.fancyGraphics)
1162                {
1163                    this.mc.mcProfiler.endStartSection("water");
1164    
1165                    if (this.mc.gameSettings.ambientOcclusion)
1166                    {
1167                        GL11.glShadeModel(GL11.GL_SMOOTH);
1168                    }
1169    
1170                    GL11.glColorMask(false, false, false, false);
1171                    int var18 = var5.sortAndRender(var4, 1, (double)par1);
1172    
1173                    if (this.mc.gameSettings.anaglyph)
1174                    {
1175                        if (anaglyphField == 0)
1176                        {
1177                            GL11.glColorMask(false, true, true, true);
1178                        }
1179                        else
1180                        {
1181                            GL11.glColorMask(true, false, false, true);
1182                        }
1183                    }
1184                    else
1185                    {
1186                        GL11.glColorMask(true, true, true, true);
1187                    }
1188    
1189                    if (var18 > 0)
1190                    {
1191                        var5.renderAllRenderLists(1, (double)par1);
1192                    }
1193    
1194                    GL11.glShadeModel(GL11.GL_FLAT);
1195                }
1196                else
1197                {
1198                    this.mc.mcProfiler.endStartSection("water");
1199                    var5.sortAndRender(var4, 1, (double)par1);
1200                }
1201    
1202                GL11.glDepthMask(true);
1203                GL11.glEnable(GL11.GL_CULL_FACE);
1204                GL11.glDisable(GL11.GL_BLEND);
1205    
1206                if (this.cameraZoom == 1.0D && var4 instanceof EntityPlayer && !this.mc.gameSettings.hideGUI && this.mc.objectMouseOver != null && !var4.isInsideOfMaterial(Material.water))
1207                {
1208                    var17 = (EntityPlayer)var4;
1209                    GL11.glDisable(GL11.GL_ALPHA_TEST);
1210                    this.mc.mcProfiler.endStartSection("outline");
1211                    if (!ForgeHooksClient.onDrawBlockHighlight(var5, var17, mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1))
1212                    {
1213                        var5.drawBlockBreaking(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1214                        var5.drawSelectionBox(var17, this.mc.objectMouseOver, 0, var17.inventory.getCurrentItem(), par1);
1215                    }
1216                    GL11.glEnable(GL11.GL_ALPHA_TEST);
1217                }
1218    
1219                this.mc.mcProfiler.endStartSection("destroyProgress");
1220                GL11.glEnable(GL11.GL_BLEND);
1221                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
1222                var5.drawBlockDamageTexture(Tessellator.instance, var4, par1);
1223                GL11.glDisable(GL11.GL_BLEND);
1224                this.mc.mcProfiler.endStartSection("weather");
1225                this.renderRainSnow(par1);
1226                GL11.glDisable(GL11.GL_FOG);
1227    
1228                if (var4.posY >= 128.0D)
1229                {
1230                    this.func_82829_a(var5, par1);
1231                }
1232    
1233                this.mc.mcProfiler.endStartSection("FRenderLast");
1234                ForgeHooksClient.dispatchRenderLast(var5, par1);
1235    
1236                this.mc.mcProfiler.endStartSection("hand");
1237    
1238                if (this.cameraZoom == 1.0D)
1239                {
1240                    GL11.glClear(256);
1241                    this.renderHand(par1, var13);
1242                }
1243    
1244                if (!this.mc.gameSettings.anaglyph)
1245                {
1246                    this.mc.mcProfiler.endSection();
1247                    return;
1248                }
1249            }
1250    
1251            GL11.glColorMask(true, true, true, false);
1252            this.mc.mcProfiler.endSection();
1253        }
1254    
1255        private void func_82829_a(RenderGlobal par1RenderGlobal, float par2)
1256        {
1257            if (this.mc.gameSettings.shouldRenderClouds())
1258            {
1259                this.mc.mcProfiler.endStartSection("clouds");
1260                GL11.glPushMatrix();
1261                this.setupFog(0, par2);
1262                GL11.glEnable(GL11.GL_FOG);
1263                par1RenderGlobal.renderClouds(par2);
1264                GL11.glDisable(GL11.GL_FOG);
1265                this.setupFog(1, par2);
1266                GL11.glPopMatrix();
1267            }
1268        }
1269    
1270        private void addRainParticles()
1271        {
1272            float var1 = this.mc.theWorld.getRainStrength(1.0F);
1273    
1274            if (!this.mc.gameSettings.fancyGraphics)
1275            {
1276                var1 /= 2.0F;
1277            }
1278    
1279            if (var1 != 0.0F)
1280            {
1281                this.random.setSeed((long)this.rendererUpdateCount * 312987231L);
1282                EntityLiving var2 = this.mc.renderViewEntity;
1283                WorldClient var3 = this.mc.theWorld;
1284                int var4 = MathHelper.floor_double(var2.posX);
1285                int var5 = MathHelper.floor_double(var2.posY);
1286                int var6 = MathHelper.floor_double(var2.posZ);
1287                byte var7 = 10;
1288                double var8 = 0.0D;
1289                double var10 = 0.0D;
1290                double var12 = 0.0D;
1291                int var14 = 0;
1292                int var15 = (int)(100.0F * var1 * var1);
1293    
1294                if (this.mc.gameSettings.particleSetting == 1)
1295                {
1296                    var15 >>= 1;
1297                }
1298                else if (this.mc.gameSettings.particleSetting == 2)
1299                {
1300                    var15 = 0;
1301                }
1302    
1303                for (int var16 = 0; var16 < var15; ++var16)
1304                {
1305                    int var17 = var4 + this.random.nextInt(var7) - this.random.nextInt(var7);
1306                    int var18 = var6 + this.random.nextInt(var7) - this.random.nextInt(var7);
1307                    int var19 = var3.getPrecipitationHeight(var17, var18);
1308                    int var20 = var3.getBlockId(var17, var19 - 1, var18);
1309                    BiomeGenBase var21 = var3.getBiomeGenForCoords(var17, var18);
1310    
1311                    if (var19 <= var5 + var7 && var19 >= var5 - var7 && var21.canSpawnLightningBolt() && var21.getFloatTemperature() >= 0.2F)
1312                    {
1313                        float var22 = this.random.nextFloat();
1314                        float var23 = this.random.nextFloat();
1315    
1316                        if (var20 > 0)
1317                        {
1318                            if (Block.blocksList[var20].blockMaterial == Material.lava)
1319                            {
1320                                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));
1321                            }
1322                            else
1323                            {
1324                                ++var14;
1325    
1326                                if (this.random.nextInt(var14) == 0)
1327                                {
1328                                    var8 = (double)((float)var17 + var22);
1329                                    var10 = (double)((float)var19 + 0.1F) - Block.blocksList[var20].getBlockBoundsMinY();
1330                                    var12 = (double)((float)var18 + var23);
1331                                }
1332    
1333                                this.mc.effectRenderer.addEffect(new EntityRainFX(var3, (double)((float)var17 + var22), (double)((float)var19 + 0.1F) - Block.blocksList[var20].getBlockBoundsMinY(), (double)((float)var18 + var23)));
1334                            }
1335                        }
1336                    }
1337                }
1338    
1339                if (var14 > 0 && this.random.nextInt(3) < this.rainSoundCounter++)
1340                {
1341                    this.rainSoundCounter = 0;
1342    
1343                    if (var10 > var2.posY + 1.0D && var3.getPrecipitationHeight(MathHelper.floor_double(var2.posX), MathHelper.floor_double(var2.posZ)) > MathHelper.floor_double(var2.posY))
1344                    {
1345                        this.mc.theWorld.playSound(var8, var10, var12, "ambient.weather.rain", 0.1F, 0.5F);
1346                    }
1347                    else
1348                    {
1349                        this.mc.theWorld.playSound(var8, var10, var12, "ambient.weather.rain", 0.2F, 1.0F);
1350                    }
1351                }
1352            }
1353        }
1354    
1355        /**
1356         * Render rain and snow
1357         */
1358        protected void renderRainSnow(float par1)
1359        {
1360            float var2 = this.mc.theWorld.getRainStrength(par1);
1361    
1362            if (var2 > 0.0F)
1363            {
1364                this.enableLightmap((double)par1);
1365    
1366                if (this.rainXCoords == null)
1367                {
1368                    this.rainXCoords = new float[1024];
1369                    this.rainYCoords = new float[1024];
1370    
1371                    for (int var3 = 0; var3 < 32; ++var3)
1372                    {
1373                        for (int var4 = 0; var4 < 32; ++var4)
1374                        {
1375                            float var5 = (float)(var4 - 16);
1376                            float var6 = (float)(var3 - 16);
1377                            float var7 = MathHelper.sqrt_float(var5 * var5 + var6 * var6);
1378                            this.rainXCoords[var3 << 5 | var4] = -var6 / var7;
1379                            this.rainYCoords[var3 << 5 | var4] = var5 / var7;
1380                        }
1381                    }
1382                }
1383    
1384                EntityLiving var41 = this.mc.renderViewEntity;
1385                WorldClient var42 = this.mc.theWorld;
1386                int var43 = MathHelper.floor_double(var41.posX);
1387                int var44 = MathHelper.floor_double(var41.posY);
1388                int var45 = MathHelper.floor_double(var41.posZ);
1389                Tessellator var8 = Tessellator.instance;
1390                GL11.glDisable(GL11.GL_CULL_FACE);
1391                GL11.glNormal3f(0.0F, 1.0F, 0.0F);
1392                GL11.glEnable(GL11.GL_BLEND);
1393                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
1394                GL11.glAlphaFunc(GL11.GL_GREATER, 0.01F);
1395                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/environment/snow.png"));
1396                double var9 = var41.lastTickPosX + (var41.posX - var41.lastTickPosX) * (double)par1;
1397                double var11 = var41.lastTickPosY + (var41.posY - var41.lastTickPosY) * (double)par1;
1398                double var13 = var41.lastTickPosZ + (var41.posZ - var41.lastTickPosZ) * (double)par1;
1399                int var15 = MathHelper.floor_double(var11);
1400                byte var16 = 5;
1401    
1402                if (this.mc.gameSettings.fancyGraphics)
1403                {
1404                    var16 = 10;
1405                }
1406    
1407                boolean var17 = false;
1408                byte var18 = -1;
1409                float var19 = (float)this.rendererUpdateCount + par1;
1410    
1411                if (this.mc.gameSettings.fancyGraphics)
1412                {
1413                    var16 = 10;
1414                }
1415    
1416                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
1417                var17 = false;
1418    
1419                for (int var20 = var45 - var16; var20 <= var45 + var16; ++var20)
1420                {
1421                    for (int var21 = var43 - var16; var21 <= var43 + var16; ++var21)
1422                    {
1423                        int var22 = (var20 - var45 + 16) * 32 + var21 - var43 + 16;
1424                        float var23 = this.rainXCoords[var22] * 0.5F;
1425                        float var24 = this.rainYCoords[var22] * 0.5F;
1426                        BiomeGenBase var25 = var42.getBiomeGenForCoords(var21, var20);
1427    
1428                        if (var25.canSpawnLightningBolt() || var25.getEnableSnow())
1429                        {
1430                            int var26 = var42.getPrecipitationHeight(var21, var20);
1431                            int var27 = var44 - var16;
1432                            int var28 = var44 + var16;
1433    
1434                            if (var27 < var26)
1435                            {
1436                                var27 = var26;
1437                            }
1438    
1439                            if (var28 < var26)
1440                            {
1441                                var28 = var26;
1442                            }
1443    
1444                            float var29 = 1.0F;
1445                            int var30 = var26;
1446    
1447                            if (var26 < var15)
1448                            {
1449                                var30 = var15;
1450                            }
1451    
1452                            if (var27 != var28)
1453                            {
1454                                this.random.setSeed((long)(var21 * var21 * 3121 + var21 * 45238971 ^ var20 * var20 * 418711 + var20 * 13761));
1455                                float var31 = var25.getFloatTemperature();
1456                                double var35;
1457                                float var32;
1458    
1459                                if (var42.getWorldChunkManager().getTemperatureAtHeight(var31, var26) >= 0.15F)
1460                                {
1461                                    if (var18 != 0)
1462                                    {
1463                                        if (var18 >= 0)
1464                                        {
1465                                            var8.draw();
1466                                        }
1467    
1468                                        var18 = 0;
1469                                        GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/environment/rain.png"));
1470                                        var8.startDrawingQuads();
1471                                    }
1472    
1473                                    var32 = ((float)(this.rendererUpdateCount + var21 * var21 * 3121 + var21 * 45238971 + var20 * var20 * 418711 + var20 * 13761 & 31) + par1) / 32.0F * (3.0F + this.random.nextFloat());
1474                                    double var33 = (double)((float)var21 + 0.5F) - var41.posX;
1475                                    var35 = (double)((float)var20 + 0.5F) - var41.posZ;
1476                                    float var37 = MathHelper.sqrt_double(var33 * var33 + var35 * var35) / (float)var16;
1477                                    float var38 = 1.0F;
1478                                    var8.setBrightness(var42.getLightBrightnessForSkyBlocks(var21, var30, var20, 0));
1479                                    var8.setColorRGBA_F(var38, var38, var38, ((1.0F - var37 * var37) * 0.5F + 0.5F) * var2);
1480                                    var8.setTranslation(-var9 * 1.0D, -var11 * 1.0D, -var13 * 1.0D);
1481                                    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));
1482                                    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));
1483                                    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));
1484                                    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));
1485                                    var8.setTranslation(0.0D, 0.0D, 0.0D);
1486                                }
1487                                else
1488                                {
1489                                    if (var18 != 1)
1490                                    {
1491                                        if (var18 >= 0)
1492                                        {
1493                                            var8.draw();
1494                                        }
1495    
1496                                        var18 = 1;
1497                                        GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture("/environment/snow.png"));
1498                                        var8.startDrawingQuads();
1499                                    }
1500    
1501                                    var32 = ((float)(this.rendererUpdateCount & 511) + par1) / 512.0F;
1502                                    float var46 = this.random.nextFloat() + var19 * 0.01F * (float)this.random.nextGaussian();
1503                                    float var34 = this.random.nextFloat() + var19 * (float)this.random.nextGaussian() * 0.001F;
1504                                    var35 = (double)((float)var21 + 0.5F) - var41.posX;
1505                                    double var47 = (double)((float)var20 + 0.5F) - var41.posZ;
1506                                    float var39 = MathHelper.sqrt_double(var35 * var35 + var47 * var47) / (float)var16;
1507                                    float var40 = 1.0F;
1508                                    var8.setBrightness((var42.getLightBrightnessForSkyBlocks(var21, var30, var20, 0) * 3 + 15728880) / 4);
1509                                    var8.setColorRGBA_F(var40, var40, var40, ((1.0F - var39 * var39) * 0.3F + 0.5F) * var2);
1510                                    var8.setTranslation(-var9 * 1.0D, -var11 * 1.0D, -var13 * 1.0D);
1511                                    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));
1512                                    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));
1513                                    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));
1514                                    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));
1515                                    var8.setTranslation(0.0D, 0.0D, 0.0D);
1516                                }
1517                            }
1518                        }
1519                    }
1520                }
1521    
1522                if (var18 >= 0)
1523                {
1524                    var8.draw();
1525                }
1526    
1527                GL11.glEnable(GL11.GL_CULL_FACE);
1528                GL11.glDisable(GL11.GL_BLEND);
1529                GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
1530                this.disableLightmap((double)par1);
1531            }
1532        }
1533    
1534        /**
1535         * Setup orthogonal projection for rendering GUI screen overlays
1536         */
1537        public void setupOverlayRendering()
1538        {
1539            ScaledResolution var1 = new ScaledResolution(this.mc.gameSettings, this.mc.displayWidth, this.mc.displayHeight);
1540            GL11.glClear(256);
1541            GL11.glMatrixMode(GL11.GL_PROJECTION);
1542            GL11.glLoadIdentity();
1543            GL11.glOrtho(0.0D, var1.getScaledWidth_double(), var1.getScaledHeight_double(), 0.0D, 1000.0D, 3000.0D);
1544            GL11.glMatrixMode(GL11.GL_MODELVIEW);
1545            GL11.glLoadIdentity();
1546            GL11.glTranslatef(0.0F, 0.0F, -2000.0F);
1547        }
1548    
1549        /**
1550         * calculates fog and calls glClearColor
1551         */
1552        private void updateFogColor(float par1)
1553        {
1554            WorldClient var2 = this.mc.theWorld;
1555            EntityLiving var3 = this.mc.renderViewEntity;
1556            float var4 = 1.0F / (float)(4 - this.mc.gameSettings.renderDistance);
1557            var4 = 1.0F - (float)Math.pow((double)var4, 0.25D);
1558            Vec3 var5 = var2.getSkyColor(this.mc.renderViewEntity, par1);
1559            float var6 = (float)var5.xCoord;
1560            float var7 = (float)var5.yCoord;
1561            float var8 = (float)var5.zCoord;
1562            Vec3 var9 = var2.getFogColor(par1);
1563            this.fogColorRed = (float)var9.xCoord;
1564            this.fogColorGreen = (float)var9.yCoord;
1565            this.fogColorBlue = (float)var9.zCoord;
1566            float var11;
1567    
1568            if (this.mc.gameSettings.renderDistance < 2)
1569            {
1570                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);
1571                var11 = (float)var3.getLook(par1).dotProduct(var10);
1572    
1573                if (var11 < 0.0F)
1574                {
1575                    var11 = 0.0F;
1576                }
1577    
1578                if (var11 > 0.0F)
1579                {
1580                    float[] var12 = var2.provider.calcSunriseSunsetColors(var2.getCelestialAngle(par1), par1);
1581    
1582                    if (var12 != null)
1583                    {
1584                        var11 *= var12[3];
1585                        this.fogColorRed = this.fogColorRed * (1.0F - var11) + var12[0] * var11;
1586                        this.fogColorGreen = this.fogColorGreen * (1.0F - var11) + var12[1] * var11;
1587                        this.fogColorBlue = this.fogColorBlue * (1.0F - var11) + var12[2] * var11;
1588                    }
1589                }
1590            }
1591    
1592            this.fogColorRed += (var6 - this.fogColorRed) * var4;
1593            this.fogColorGreen += (var7 - this.fogColorGreen) * var4;
1594            this.fogColorBlue += (var8 - this.fogColorBlue) * var4;
1595            float var19 = var2.getRainStrength(par1);
1596            float var20;
1597    
1598            if (var19 > 0.0F)
1599            {
1600                var11 = 1.0F - var19 * 0.5F;
1601                var20 = 1.0F - var19 * 0.4F;
1602                this.fogColorRed *= var11;
1603                this.fogColorGreen *= var11;
1604                this.fogColorBlue *= var20;
1605            }
1606    
1607            var11 = var2.getWeightedThunderStrength(par1);
1608    
1609            if (var11 > 0.0F)
1610            {
1611                var20 = 1.0F - var11 * 0.5F;
1612                this.fogColorRed *= var20;
1613                this.fogColorGreen *= var20;
1614                this.fogColorBlue *= var20;
1615            }
1616    
1617            int var21 = ActiveRenderInfo.getBlockIdAtEntityViewpoint(this.mc.theWorld, var3, par1);
1618    
1619            if (this.cloudFog)
1620            {
1621                Vec3 var13 = var2.drawClouds(par1);
1622                this.fogColorRed = (float)var13.xCoord;
1623                this.fogColorGreen = (float)var13.yCoord;
1624                this.fogColorBlue = (float)var13.zCoord;
1625            }
1626            else if (var21 != 0 && Block.blocksList[var21].blockMaterial == Material.water)
1627            {
1628                this.fogColorRed = 0.02F;
1629                this.fogColorGreen = 0.02F;
1630                this.fogColorBlue = 0.2F;
1631            }
1632            else if (var21 != 0 && Block.blocksList[var21].blockMaterial == Material.lava)
1633            {
1634                this.fogColorRed = 0.6F;
1635                this.fogColorGreen = 0.1F;
1636                this.fogColorBlue = 0.0F;
1637            }
1638    
1639            float var22 = this.fogColor2 + (this.fogColor1 - this.fogColor2) * par1;
1640            this.fogColorRed *= var22;
1641            this.fogColorGreen *= var22;
1642            this.fogColorBlue *= var22;
1643            double var14 = (var3.lastTickPosY + (var3.posY - var3.lastTickPosY) * (double)par1) * var2.provider.getVoidFogYFactor();
1644    
1645            if (var3.isPotionActive(Potion.blindness))
1646            {
1647                int var16 = var3.getActivePotionEffect(Potion.blindness).getDuration();
1648    
1649                if (var16 < 20)
1650                {
1651                    var14 *= (double)(1.0F - (float)var16 / 20.0F);
1652                }
1653                else
1654                {
1655                    var14 = 0.0D;
1656                }
1657            }
1658    
1659            if (var14 < 1.0D)
1660            {
1661                if (var14 < 0.0D)
1662                {
1663                    var14 = 0.0D;
1664                }
1665    
1666                var14 *= var14;
1667                this.fogColorRed = (float)((double)this.fogColorRed * var14);
1668                this.fogColorGreen = (float)((double)this.fogColorGreen * var14);
1669                this.fogColorBlue = (float)((double)this.fogColorBlue * var14);
1670            }
1671    
1672            float var23;
1673    
1674            if (this.field_82831_U > 0.0F)
1675            {
1676                var23 = this.field_82832_V + (this.field_82831_U - this.field_82832_V) * par1;
1677                this.fogColorRed = this.fogColorRed * (1.0F - var23) + this.fogColorRed * 0.7F * var23;
1678                this.fogColorGreen = this.fogColorGreen * (1.0F - var23) + this.fogColorGreen * 0.6F * var23;
1679                this.fogColorBlue = this.fogColorBlue * (1.0F - var23) + this.fogColorBlue * 0.6F * var23;
1680            }
1681    
1682            float var17;
1683    
1684            if (var3.isPotionActive(Potion.nightVision))
1685            {
1686                var23 = this.func_82830_a(this.mc.thePlayer, par1);
1687                var17 = 1.0F / this.fogColorRed;
1688    
1689                if (var17 > 1.0F / this.fogColorGreen)
1690                {
1691                    var17 = 1.0F / this.fogColorGreen;
1692                }
1693    
1694                if (var17 > 1.0F / this.fogColorBlue)
1695                {
1696                    var17 = 1.0F / this.fogColorBlue;
1697                }
1698    
1699                this.fogColorRed = this.fogColorRed * (1.0F - var23) + this.fogColorRed * var17 * var23;
1700                this.fogColorGreen = this.fogColorGreen * (1.0F - var23) + this.fogColorGreen * var17 * var23;
1701                this.fogColorBlue = this.fogColorBlue * (1.0F - var23) + this.fogColorBlue * var17 * var23;
1702            }
1703    
1704            if (this.mc.gameSettings.anaglyph)
1705            {
1706                var23 = (this.fogColorRed * 30.0F + this.fogColorGreen * 59.0F + this.fogColorBlue * 11.0F) / 100.0F;
1707                var17 = (this.fogColorRed * 30.0F + this.fogColorGreen * 70.0F) / 100.0F;
1708                float var18 = (this.fogColorRed * 30.0F + this.fogColorBlue * 70.0F) / 100.0F;
1709                this.fogColorRed = var23;
1710                this.fogColorGreen = var17;
1711                this.fogColorBlue = var18;
1712            }
1713    
1714            GL11.glClearColor(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 0.0F);
1715        }
1716    
1717        /**
1718         * 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
1719         * distance and is used for sky rendering.
1720         */
1721        private void setupFog(int par1, float par2)
1722        {
1723            EntityLiving var3 = this.mc.renderViewEntity;
1724            boolean var4 = false;
1725    
1726            if (var3 instanceof EntityPlayer)
1727            {
1728                var4 = ((EntityPlayer)var3).capabilities.isCreativeMode;
1729            }
1730    
1731            if (par1 == 999)
1732            {
1733                GL11.glFog(GL11.GL_FOG_COLOR, this.setFogColorBuffer(0.0F, 0.0F, 0.0F, 1.0F));
1734                GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);
1735                GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1736                GL11.glFogf(GL11.GL_FOG_END, 8.0F);
1737    
1738                if (GLContext.getCapabilities().GL_NV_fog_distance)
1739                {
1740                    GL11.glFogi(34138, 34139);
1741                }
1742    
1743                GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1744            }
1745            else
1746            {
1747                GL11.glFog(GL11.GL_FOG_COLOR, this.setFogColorBuffer(this.fogColorRed, this.fogColorGreen, this.fogColorBlue, 1.0F));
1748                GL11.glNormal3f(0.0F, -1.0F, 0.0F);
1749                GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
1750                int var5 = ActiveRenderInfo.getBlockIdAtEntityViewpoint(this.mc.theWorld, var3, par2);
1751                float var6;
1752    
1753                if (var3.isPotionActive(Potion.blindness))
1754                {
1755                    var6 = 5.0F;
1756                    int var7 = var3.getActivePotionEffect(Potion.blindness).getDuration();
1757    
1758                    if (var7 < 20)
1759                    {
1760                        var6 = 5.0F + (this.farPlaneDistance - 5.0F) * (1.0F - (float)var7 / 20.0F);
1761                    }
1762    
1763                    GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);
1764    
1765                    if (par1 < 0)
1766                    {
1767                        GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1768                        GL11.glFogf(GL11.GL_FOG_END, var6 * 0.8F);
1769                    }
1770                    else
1771                    {
1772                        GL11.glFogf(GL11.GL_FOG_START, var6 * 0.25F);
1773                        GL11.glFogf(GL11.GL_FOG_END, var6);
1774                    }
1775    
1776                    if (GLContext.getCapabilities().GL_NV_fog_distance)
1777                    {
1778                        GL11.glFogi(34138, 34139);
1779                    }
1780                }
1781                else
1782                {
1783                    float var8;
1784                    float var9;
1785                    float var10;
1786                    float var11;
1787                    float var12;
1788    
1789                    if (this.cloudFog)
1790                    {
1791                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);
1792                        GL11.glFogf(GL11.GL_FOG_DENSITY, 0.1F);
1793                        var6 = 1.0F;
1794                        var12 = 1.0F;
1795                        var8 = 1.0F;
1796    
1797                        if (this.mc.gameSettings.anaglyph)
1798                        {
1799                            var9 = (var6 * 30.0F + var12 * 59.0F + var8 * 11.0F) / 100.0F;
1800                            var10 = (var6 * 30.0F + var12 * 70.0F) / 100.0F;
1801                            var11 = (var6 * 30.0F + var8 * 70.0F) / 100.0F;
1802                        }
1803                    }
1804                    else if (var5 > 0 && Block.blocksList[var5].blockMaterial == Material.water)
1805                    {
1806                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);
1807    
1808                        if (var3.isPotionActive(Potion.waterBreathing))
1809                        {
1810                            GL11.glFogf(GL11.GL_FOG_DENSITY, 0.05F);
1811                        }
1812                        else
1813                        {
1814                            GL11.glFogf(GL11.GL_FOG_DENSITY, 0.1F);
1815                        }
1816    
1817                        var6 = 0.4F;
1818                        var12 = 0.4F;
1819                        var8 = 0.9F;
1820    
1821                        if (this.mc.gameSettings.anaglyph)
1822                        {
1823                            var9 = (var6 * 30.0F + var12 * 59.0F + var8 * 11.0F) / 100.0F;
1824                            var10 = (var6 * 30.0F + var12 * 70.0F) / 100.0F;
1825                            var11 = (var6 * 30.0F + var8 * 70.0F) / 100.0F;
1826                        }
1827                    }
1828                    else if (var5 > 0 && Block.blocksList[var5].blockMaterial == Material.lava)
1829                    {
1830                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_EXP);
1831                        GL11.glFogf(GL11.GL_FOG_DENSITY, 2.0F);
1832                        var6 = 0.4F;
1833                        var12 = 0.3F;
1834                        var8 = 0.3F;
1835    
1836                        if (this.mc.gameSettings.anaglyph)
1837                        {
1838                            var9 = (var6 * 30.0F + var12 * 59.0F + var8 * 11.0F) / 100.0F;
1839                            var10 = (var6 * 30.0F + var12 * 70.0F) / 100.0F;
1840                            var11 = (var6 * 30.0F + var8 * 70.0F) / 100.0F;
1841                        }
1842                    }
1843                    else
1844                    {
1845                        var6 = this.farPlaneDistance;
1846    
1847                        if (this.mc.theWorld.provider.getWorldHasVoidParticles() && !var4)
1848                        {
1849                            double var13 = (double)((var3.getBrightnessForRender(par2) & 15728640) >> 20) / 16.0D + (var3.lastTickPosY + (var3.posY - var3.lastTickPosY) * (double)par2 + 4.0D) / 32.0D;
1850    
1851                            if (var13 < 1.0D)
1852                            {
1853                                if (var13 < 0.0D)
1854                                {
1855                                    var13 = 0.0D;
1856                                }
1857    
1858                                var13 *= var13;
1859                                var9 = 100.0F * (float)var13;
1860    
1861                                if (var9 < 5.0F)
1862                                {
1863                                    var9 = 5.0F;
1864                                }
1865    
1866                                if (var6 > var9)
1867                                {
1868                                    var6 = var9;
1869                                }
1870                            }
1871                        }
1872    
1873                        GL11.glFogi(GL11.GL_FOG_MODE, GL11.GL_LINEAR);
1874    
1875                        if (par1 < 0)
1876                        {
1877                            GL11.glFogf(GL11.GL_FOG_START, 0.0F);
1878                            GL11.glFogf(GL11.GL_FOG_END, var6 * 0.8F);
1879                        }
1880                        else
1881                        {
1882                            GL11.glFogf(GL11.GL_FOG_START, var6 * 0.25F);
1883                            GL11.glFogf(GL11.GL_FOG_END, var6);
1884                        }
1885    
1886                        if (GLContext.getCapabilities().GL_NV_fog_distance)
1887                        {
1888                            GL11.glFogi(34138, 34139);
1889                        }
1890    
1891                        if (this.mc.theWorld.provider.doesXZShowFog((int)var3.posX, (int)var3.posZ))
1892                        {
1893                            GL11.glFogf(GL11.GL_FOG_START, var6 * 0.05F);
1894                            GL11.glFogf(GL11.GL_FOG_END, Math.min(var6, 192.0F) * 0.5F);
1895                        }
1896                    }
1897                }
1898    
1899                GL11.glEnable(GL11.GL_COLOR_MATERIAL);
1900                GL11.glColorMaterial(GL11.GL_FRONT, GL11.GL_AMBIENT);
1901            }
1902        }
1903    
1904        /**
1905         * Update and return fogColorBuffer with the RGBA values passed as arguments
1906         */
1907        private FloatBuffer setFogColorBuffer(float par1, float par2, float par3, float par4)
1908        {
1909            this.fogColorBuffer.clear();
1910            this.fogColorBuffer.put(par1).put(par2).put(par3).put(par4);
1911            this.fogColorBuffer.flip();
1912            return this.fogColorBuffer;
1913        }
1914    
1915        public static int func_78465_a(int par0)
1916        {
1917            short var1 = 200;
1918    
1919            if (par0 == 1)
1920            {
1921                var1 = 120;
1922            }
1923    
1924            if (par0 == 2)
1925            {
1926                var1 = 35;
1927            }
1928    
1929            return var1;
1930        }
1931    
1932        static Minecraft func_90030_a(EntityRenderer par0EntityRenderer)
1933        {
1934            return par0EntityRenderer.mc;
1935        }
1936    }