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