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