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