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