    001    package net.minecraft.client.renderer;
    002
    003    import cpw.mods.fml.client.TextureFXManager;
    004    import cpw.mods.fml.common.Side;
    005    import cpw.mods.fml.common.asm.SideOnly;
    006    import net.minecraft.block.Block;
    007    import net.minecraft.block.material.Material;
    008    import net.minecraft.client.Minecraft;
    009    import net.minecraft.client.entity.EntityClientPlayerMP;
    010    import net.minecraft.client.entity.EntityPlayerSP;
    011    import net.minecraft.client.gui.MapItemRenderer;
    012    import net.minecraft.client.renderer.entity.Render;
    013    import net.minecraft.client.renderer.entity.RenderManager;
    014    import net.minecraft.client.renderer.entity.RenderPlayer;
    015    import net.minecraft.entity.EntityLiving;
    016    import net.minecraft.item.EnumAction;
    017    import net.minecraft.item.Item;
    018    import net.minecraft.item.ItemBlock;
    019    import net.minecraft.item.ItemMap;
    020    import net.minecraft.item.ItemStack;
    021    import net.minecraft.util.MathHelper;
    022    import net.minecraft.world.storage.MapData;
    023    import org.lwjgl.opengl.GL11;
    024    import org.lwjgl.opengl.GL12;
    025
    026    import net.minecraftforge.client.ForgeHooksClient;
    027    import net.minecraftforge.client.IItemRenderer;
    028    import net.minecraftforge.client.MinecraftForgeClient;
    029    import static net.minecraftforge.client.IItemRenderer.ItemRenderType.*;
    030    import static net.minecraftforge.client.IItemRenderer.ItemRendererHelper.*;
    031
    032    @SideOnly(Side.CLIENT)
    033    public class ItemRenderer
    034    {
    035        /** A reference to the Minecraft object. */
    036        private Minecraft mc;
    037        private ItemStack itemToRender = null;
    038
    039        /**
    040         * How far the current item has been equipped (0 disequipped and 1 fully up)
    041         */
    042        private float equippedProgress = 0.0F;
    043        private float prevEquippedProgress = 0.0F;
    044
    045        /** Instance of RenderBlocks. */
    046        private RenderBlocks renderBlocksInstance = new RenderBlocks();
    047        public final MapItemRenderer mapItemRenderer;
    048
    049        /** The index of the currently held item (0-8, or -1 if not yet updated) */
    050        private int equippedItemSlot = -1;
    051
    052        public ItemRenderer(Minecraft par1Minecraft)
    053        {
    054            this.mc = par1Minecraft;
    055            this.mapItemRenderer = new MapItemRenderer(par1Minecraft.fontRenderer, par1Minecraft.gameSettings, par1Minecraft.renderEngine);
    056        }
    057
    058        /**
    059         * Renders the item stack for being in an entity's hand Args: itemStack
    060         */
    061        public void renderItem(EntityLiving par1EntityLiving, ItemStack par2ItemStack, int par3)
    062        {
    063            GL11.glPushMatrix();
    064
    065            IItemRenderer customRenderer = MinecraftForgeClient.getItemRenderer(par2ItemStack, EQUIPPED);
    066
    067            if (customRenderer != null)
    068            {
    069                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture(par2ItemStack.getItem().getTextureFile()));
    070                ForgeHooksClient.renderEquippedItem(customRenderer, renderBlocksInstance, par1EntityLiving, par2ItemStack);
    071            }
    072            else if (par2ItemStack.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.blocksList[par2ItemStack.itemID].getRenderType()))
    073            {
    074                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture(par2ItemStack.getItem().getTextureFile()));
    075                this.renderBlocksInstance.renderBlockAsItem(Block.blocksList[par2ItemStack.itemID], par2ItemStack.getItemDamage(), 1.0F);
    076            }
    077            else
    078            {
    079                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTexture(par2ItemStack.getItem().getTextureFile()));
    080
    081                Tessellator var5 = Tessellator.instance;
    082                int var6 = par1EntityLiving.getItemIcon(par2ItemStack, par3);
    083                float var7 = ((float)(var6 % 16 * 16) + 0.0F) / 256.0F;
    084                float var8 = ((float)(var6 % 16 * 16) + 15.99F) / 256.0F;
    085                float var9 = ((float)(var6 / 16 * 16) + 0.0F) / 256.0F;
    086                float var10 = ((float)(var6 / 16 * 16) + 15.99F) / 256.0F;
    087                float var11 = 0.0F;
    088                float var12 = 0.3F;
    089                GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    090                GL11.glTranslatef(-var11, -var12, 0.0F);
    091                float var13 = 1.5F;
    092                GL11.glScalef(var13, var13, var13);
    093                GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
    094                GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
    095                GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F);
    096                this.renderItemIn2D(var5, var8, var9, var7, var10);
    097
    098                if (par2ItemStack != null && par2ItemStack.hasEffect() && par3 == 0)
    099                {
    100                    GL11.glDepthFunc(GL11.GL_EQUAL);
    101                    GL11.glDisable(GL11.GL_LIGHTING);
    102                    this.mc.renderEngine.bindTexture(this.mc.renderEngine.getTexture("%blur%/misc/glint.png"));
    103                    GL11.glEnable(GL11.GL_BLEND);
    104                    GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
    105                    float var14 = 0.76F;
    106                    GL11.glColor4f(0.5F * var14, 0.25F * var14, 0.8F * var14, 1.0F);
    107                    GL11.glMatrixMode(GL11.GL_TEXTURE);
    108                    GL11.glPushMatrix();
    109                    float var15 = 0.125F;
    110                    GL11.glScalef(var15, var15, var15);
    111                    float var16 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F;
    112                    GL11.glTranslatef(var16, 0.0F, 0.0F);
    113                    GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F);
    114                    this.renderItemIn2D(var5, 0.0F, 0.0F, 1.0F, 1.0F);
    115                    GL11.glPopMatrix();
    116                    GL11.glPushMatrix();
    117                    GL11.glScalef(var15, var15, var15);
    118                    var16 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F;
    119                    GL11.glTranslatef(-var16, 0.0F, 0.0F);
    120                    GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F);
    121                    this.renderItemIn2D(var5, 0.0F, 0.0F, 1.0F, 1.0F);
    122                    GL11.glPopMatrix();
    123                    GL11.glMatrixMode(GL11.GL_MODELVIEW);
    124                    GL11.glDisable(GL11.GL_BLEND);
    125                    GL11.glEnable(GL11.GL_LIGHTING);
    126                    GL11.glDepthFunc(GL11.GL_LEQUAL);
    127                }
    128
    129                GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    130            }
    131
    132            GL11.glPopMatrix();
    133        }
    134
    135        /**
    136         * Renders an item held in hand as a 2D texture with thickness
    137         */
    138        private void renderItemIn2D(Tessellator par1Tessellator, float par2, float par3, float par4, float par5)
    139        {
    140            float var6 = 1.0F;
    141            float var7 = 0.0625F;
    142            par1Tessellator.startDrawingQuads();
    143            par1Tessellator.setNormal(0.0F, 0.0F, 1.0F);
    144            par1Tessellator.addVertexWithUV(0.0D, 0.0D, 0.0D, (double)par2, (double)par5);
    145            par1Tessellator.addVertexWithUV((double)var6, 0.0D, 0.0D, (double)par4, (double)par5);
    146            par1Tessellator.addVertexWithUV((double)var6, 1.0D, 0.0D, (double)par4, (double)par3);
    147            par1Tessellator.addVertexWithUV(0.0D, 1.0D, 0.0D, (double)par2, (double)par3);
    148            par1Tessellator.draw();
    149            par1Tessellator.startDrawingQuads();
    150            par1Tessellator.setNormal(0.0F, 0.0F, -1.0F);
    151            par1Tessellator.addVertexWithUV(0.0D, 1.0D, (double)(0.0F - var7), (double)par2, (double)par3);
    152            par1Tessellator.addVertexWithUV((double)var6, 1.0D, (double)(0.0F - var7), (double)par4, (double)par3);
    153            par1Tessellator.addVertexWithUV((double)var6, 0.0D, (double)(0.0F - var7), (double)par4, (double)par5);
    154            par1Tessellator.addVertexWithUV(0.0D, 0.0D, (double)(0.0F - var7), (double)par2, (double)par5);
    155            par1Tessellator.draw();
    156            par1Tessellator.startDrawingQuads();
    157            par1Tessellator.setNormal(-1.0F, 0.0F, 0.0F);
    158            int var8;
    159            float var9;
    160            float var10;
    161            float var11;
    162
    163            /* Gets the width/16 of the currently bound texture, used
    164             * to fix the side rendering issues on textures != 16 */
    165            int tileSize = TextureFXManager.instance().getTextureDimensions(GL11.glGetInteger(GL11.GL_TEXTURE_BINDING_2D)).width / 16;
    166
    167            float tx = 1.0f / (32 * tileSize);
    168            float tz = 1.0f /  tileSize;
    169
    170            for (var8 = 0; var8 < tileSize; ++var8)
    171            {
    172                var9 = (float)var8 / tileSize;
    173                var10 = par2 + (par4 - par2) * var9 - tx;
    174                var11 = var6 * var9;
    175                par1Tessellator.addVertexWithUV((double)var11, 0.0D, (double)(0.0F - var7), (double)var10, (double)par5);
    176                par1Tessellator.addVertexWithUV((double)var11, 0.0D, 0.0D, (double)var10, (double)par5);
    177                par1Tessellator.addVertexWithUV((double)var11, 1.0D, 0.0D, (double)var10, (double)par3);
    178                par1Tessellator.addVertexWithUV((double)var11, 1.0D, (double)(0.0F - var7), (double)var10, (double)par3);
    179            }
    180
    181            par1Tessellator.draw();
    182            par1Tessellator.startDrawingQuads();
    183            par1Tessellator.setNormal(1.0F, 0.0F, 0.0F);
    184
    185            for (var8 = 0; var8 < tileSize; ++var8)
    186            {
    187                var9 = (float)var8 / tileSize;
    188                var10 = par2 + (par4 - par2) * var9 - tx;
    189                var11 = var6 * var9 + tz;
    190                par1Tessellator.addVertexWithUV((double)var11, 1.0D, (double)(0.0F - var7), (double)var10, (double)par3);
    191                par1Tessellator.addVertexWithUV((double)var11, 1.0D, 0.0D, (double)var10, (double)par3);
    192                par1Tessellator.addVertexWithUV((double)var11, 0.0D, 0.0D, (double)var10, (double)par5);
    193                par1Tessellator.addVertexWithUV((double)var11, 0.0D, (double)(0.0F - var7), (double)var10, (double)par5);
    194            }
    195
    196            par1Tessellator.draw();
    197            par1Tessellator.startDrawingQuads();
    198            par1Tessellator.setNormal(0.0F, 1.0F, 0.0F);
    199
    200            for (var8 = 0; var8 < tileSize; ++var8)
    201            {
    202                var9 = (float)var8 / tileSize;
    203                var10 = par5 + (par3 - par5) * var9 - tx;
    204                var11 = var6 * var9 + tz;
    205                par1Tessellator.addVertexWithUV(0.0D, (double)var11, 0.0D, (double)par2, (double)var10);
    206                par1Tessellator.addVertexWithUV((double)var6, (double)var11, 0.0D, (double)par4, (double)var10);
    207                par1Tessellator.addVertexWithUV((double)var6, (double)var11, (double)(0.0F - var7), (double)par4, (double)var10);
    208                par1Tessellator.addVertexWithUV(0.0D, (double)var11, (double)(0.0F - var7), (double)par2, (double)var10);
    209            }
    210
    211            par1Tessellator.draw();
    212            par1Tessellator.startDrawingQuads();
    213            par1Tessellator.setNormal(0.0F, -1.0F, 0.0F);
    214
    215            for (var8 = 0; var8 < tileSize; ++var8)
    216            {
    217                var9 = (float)var8 / tileSize;
    218                var10 = par5 + (par3 - par5) * var9 - tx;
    219                var11 = var6 * var9;
    220                par1Tessellator.addVertexWithUV((double)var6, (double)var11, 0.0D, (double)par4, (double)var10);
    221                par1Tessellator.addVertexWithUV(0.0D, (double)var11, 0.0D, (double)par2, (double)var10);
    222                par1Tessellator.addVertexWithUV(0.0D, (double)var11, (double)(0.0F - var7), (double)par2, (double)var10);
    223                par1Tessellator.addVertexWithUV((double)var6, (double)var11, (double)(0.0F - var7), (double)par4, (double)var10);
    224            }
    225
    226            par1Tessellator.draw();
    227        }
    228
    229        /**
    230         * Renders the active item in the player's hand when in first person mode. Args: partialTickTime
    231         */
    232        public void renderItemInFirstPerson(float par1)
    233        {
    234            float var2 = this.prevEquippedProgress + (this.equippedProgress - this.prevEquippedProgress) * par1;
    235            EntityClientPlayerMP var3 = this.mc.thePlayer;
    236            float var4 = var3.prevRotationPitch + (var3.rotationPitch - var3.prevRotationPitch) * par1;
    237            GL11.glPushMatrix();
    238            GL11.glRotatef(var4, 1.0F, 0.0F, 0.0F);
    239            GL11.glRotatef(var3.prevRotationYaw + (var3.rotationYaw - var3.prevRotationYaw) * par1, 0.0F, 1.0F, 0.0F);
    240            RenderHelper.enableStandardItemLighting();
    241            GL11.glPopMatrix();
    242            float var6;
    243            float var7;
    244
    245            if (var3 instanceof EntityPlayerSP)
    246            {
    247                EntityPlayerSP var5 = (EntityPlayerSP)var3;
    248                var6 = var5.prevRenderArmPitch + (var5.renderArmPitch - var5.prevRenderArmPitch) * par1;
    249                var7 = var5.prevRenderArmYaw + (var5.renderArmYaw - var5.prevRenderArmYaw) * par1;
    250                GL11.glRotatef((var3.rotationPitch - var6) * 0.1F, 1.0F, 0.0F, 0.0F);
    251                GL11.glRotatef((var3.rotationYaw - var7) * 0.1F, 0.0F, 1.0F, 0.0F);
    252            }
    253
    254            ItemStack var17 = this.itemToRender;
    255            var6 = this.mc.theWorld.getLightBrightness(MathHelper.floor_double(var3.posX), MathHelper.floor_double(var3.posY), MathHelper.floor_double(var3.posZ));
    256            var6 = 1.0F;
    257            int var18 = this.mc.theWorld.getLightBrightnessForSkyBlocks(MathHelper.floor_double(var3.posX), MathHelper.floor_double(var3.posY), MathHelper.floor_double(var3.posZ), 0);
    258            int var8 = var18 % 65536;
    259            int var9 = var18 / 65536;
    260            OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var8 / 1.0F, (float)var9 / 1.0F);
    261            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    262            float var10;
    263            float var21;
    264            float var20;
    265
    266            if (var17 != null)
    267            {
    268                var18 = Item.itemsList[var17.itemID].getColorFromItemStack(var17, 0);
    269                var20 = (float)(var18 >> 16 & 255) / 255.0F;
    270                var21 = (float)(var18 >> 8 & 255) / 255.0F;
    271                var10 = (float)(var18 & 255) / 255.0F;
    272                GL11.glColor4f(var6 * var20, var6 * var21, var6 * var10, 1.0F);
    273            }
    274            else
    275            {
    276                GL11.glColor4f(var6, var6, var6, 1.0F);
    277            }
    278
    279            float var11;
    280            float var12;
    281            float var13;
    282            Render var24;
    283            RenderPlayer var26;
    284
    285            if (var17 != null && var17.getItem() instanceof ItemMap)
    286            {
    287                IItemRenderer custom = MinecraftForgeClient.getItemRenderer(var17, FIRST_PERSON_MAP);
    288                GL11.glPushMatrix();
    289                var7 = 0.8F;
    290                var20 = var3.getSwingProgress(par1);
    291                var21 = MathHelper.sin(var20 * (float)Math.PI);
    292                var10 = MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI);
    293                GL11.glTranslatef(-var10 * 0.4F, MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI * 2.0F) * 0.2F, -var21 * 0.2F);
    294                var20 = 1.0F - var4 / 45.0F + 0.1F;
    295
    296                if (var20 < 0.0F)
    297                {
    298                    var20 = 0.0F;
    299                }
    300
    301                if (var20 > 1.0F)
    302                {
    303                    var20 = 1.0F;
    304                }
    305
    306                var20 = -MathHelper.cos(var20 * (float)Math.PI) * 0.5F + 0.5F;
    307                GL11.glTranslatef(0.0F, 0.0F * var7 - (1.0F - var2) * 1.2F - var20 * 0.5F + 0.04F, -0.9F * var7);
    308                GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
    309                GL11.glRotatef(var20 * -85.0F, 0.0F, 0.0F, 1.0F);
    310                GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    311                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTextureForDownloadableImage(this.mc.thePlayer.skinUrl, this.mc.thePlayer.getTexture()));
    312
    313                for (var9 = 0; var9 < 2; ++var9)
    314                {
    315                    int var22 = var9 * 2 - 1;
    316                    GL11.glPushMatrix();
    317                    GL11.glTranslatef(-0.0F, -0.6F, 1.1F * (float)var22);
    318                    GL11.glRotatef((float)(-45 * var22), 1.0F, 0.0F, 0.0F);
    319                    GL11.glRotatef(-90.0F, 0.0F, 0.0F, 1.0F);
    320                    GL11.glRotatef(59.0F, 0.0F, 0.0F, 1.0F);
    321                    GL11.glRotatef((float)(-65 * var22), 0.0F, 1.0F, 0.0F);
    322                    var24 = RenderManager.instance.getEntityRenderObject(this.mc.thePlayer);
    323                    var26 = (RenderPlayer)var24;
    324                    var13 = 1.0F;
    325                    GL11.glScalef(var13, var13, var13);
    326                    var26.func_82441_a(this.mc.thePlayer);
    327                    GL11.glPopMatrix();
    328                }
    329
    330                var21 = var3.getSwingProgress(par1);
    331                var10 = MathHelper.sin(var21 * var21 * (float)Math.PI);
    332                var11 = MathHelper.sin(MathHelper.sqrt_float(var21) * (float)Math.PI);
    333                GL11.glRotatef(-var10 * 20.0F, 0.0F, 1.0F, 0.0F);
    334                GL11.glRotatef(-var11 * 20.0F, 0.0F, 0.0F, 1.0F);
    335                GL11.glRotatef(-var11 * 80.0F, 1.0F, 0.0F, 0.0F);
    336                var12 = 0.38F;
    337                GL11.glScalef(var12, var12, var12);
    338                GL11.glRotatef(90.0F, 0.0F, 1.0F, 0.0F);
    339                GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
    340                GL11.glTranslatef(-1.0F, -1.0F, 0.0F);
    341                var13 = 0.015625F;
    342                GL11.glScalef(var13, var13, var13);
    343                this.mc.renderEngine.bindTexture(this.mc.renderEngine.getTexture("/misc/mapbg.png"));
    344                Tessellator var28 = Tessellator.instance;
    345                GL11.glNormal3f(0.0F, 0.0F, -1.0F);
    346                var28.startDrawingQuads();
    347                byte var27 = 7;
    348                var28.addVertexWithUV((double)(0 - var27), (double)(128 + var27), 0.0D, 0.0D, 1.0D);
    349                var28.addVertexWithUV((double)(128 + var27), (double)(128 + var27), 0.0D, 1.0D, 1.0D);
    350                var28.addVertexWithUV((double)(128 + var27), (double)(0 - var27), 0.0D, 1.0D, 0.0D);
    351                var28.addVertexWithUV((double)(0 - var27), (double)(0 - var27), 0.0D, 0.0D, 0.0D);
    352                var28.draw();
    353                MapData var16 = ((ItemMap)var17.getItem()).getMapData(var17, this.mc.theWorld);
    354                if (custom == null)
    355                {
    356                    if (var16 != null)
    357                    {
    358                        this.mapItemRenderer.renderMap(this.mc.thePlayer, this.mc.renderEngine, var16);
    359                    }
    360                }
    361                else
    362                {
    363                    custom.renderItem(FIRST_PERSON_MAP, var17, mc.thePlayer, mc.renderEngine, var16);
    364                }
    365
    366                GL11.glPopMatrix();
    367            }
    368            else if (var17 != null)
    369            {
    370                GL11.glPushMatrix();
    371                var7 = 0.8F;
    372
    373                if (var3.getItemInUseCount() > 0)
    374                {
    375                    EnumAction var19 = var17.getItemUseAction();
    376
    377                    if (var19 == EnumAction.eat || var19 == EnumAction.drink)
    378                    {
    379                        var21 = (float)var3.getItemInUseCount() - par1 + 1.0F;
    380                        var10 = 1.0F - var21 / (float)var17.getMaxItemUseDuration();
    381                        var11 = 1.0F - var10;
    382                        var11 = var11 * var11 * var11;
    383                        var11 = var11 * var11 * var11;
    384                        var11 = var11 * var11 * var11;
    385                        var12 = 1.0F - var11;
    386                        GL11.glTranslatef(0.0F, MathHelper.abs(MathHelper.cos(var21 / 4.0F * (float)Math.PI) * 0.1F) * (float)((double)var10 > 0.2D ? 1 : 0), 0.0F);
    387                        GL11.glTranslatef(var12 * 0.6F, -var12 * 0.5F, 0.0F);
    388                        GL11.glRotatef(var12 * 90.0F, 0.0F, 1.0F, 0.0F);
    389                        GL11.glRotatef(var12 * 10.0F, 1.0F, 0.0F, 0.0F);
    390                        GL11.glRotatef(var12 * 30.0F, 0.0F, 0.0F, 1.0F);
    391                    }
    392                }
    393                else
    394                {
    395                    var20 = var3.getSwingProgress(par1);
    396                    var21 = MathHelper.sin(var20 * (float)Math.PI);
    397                    var10 = MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI);
    398                    GL11.glTranslatef(-var10 * 0.4F, MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI * 2.0F) * 0.2F, -var21 * 0.2F);
    399                }
    400
    401                GL11.glTranslatef(0.7F * var7, -0.65F * var7 - (1.0F - var2) * 0.6F, -0.9F * var7);
    402                GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    403                GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    404                var20 = var3.getSwingProgress(par1);
    405                var21 = MathHelper.sin(var20 * var20 * (float)Math.PI);
    406                var10 = MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI);
    407                GL11.glRotatef(-var21 * 20.0F, 0.0F, 1.0F, 0.0F);
    408                GL11.glRotatef(-var10 * 20.0F, 0.0F, 0.0F, 1.0F);
    409                GL11.glRotatef(-var10 * 80.0F, 1.0F, 0.0F, 0.0F);
    410                var11 = 0.4F;
    411                GL11.glScalef(var11, var11, var11);
    412                float var14;
    413                float var15;
    414
    415                if (var3.getItemInUseCount() > 0)
    416                {
    417                    EnumAction var23 = var17.getItemUseAction();
    418
    419                    if (var23 == EnumAction.block)
    420                    {
    421                        GL11.glTranslatef(-0.5F, 0.2F, 0.0F);
    422                        GL11.glRotatef(30.0F, 0.0F, 1.0F, 0.0F);
    423                        GL11.glRotatef(-80.0F, 1.0F, 0.0F, 0.0F);
    424                        GL11.glRotatef(60.0F, 0.0F, 1.0F, 0.0F);
    425                    }
    426                    else if (var23 == EnumAction.bow)
    427                    {
    428                        GL11.glRotatef(-18.0F, 0.0F, 0.0F, 1.0F);
    429                        GL11.glRotatef(-12.0F, 0.0F, 1.0F, 0.0F);
    430                        GL11.glRotatef(-8.0F, 1.0F, 0.0F, 0.0F);
    431                        GL11.glTranslatef(-0.9F, 0.2F, 0.0F);
    432                        var13 = (float)var17.getMaxItemUseDuration() - ((float)var3.getItemInUseCount() - par1 + 1.0F);
    433                        var14 = var13 / 20.0F;
    434                        var14 = (var14 * var14 + var14 * 2.0F) / 3.0F;
    435
    436                        if (var14 > 1.0F)
    437                        {
    438                            var14 = 1.0F;
    439                        }
    440
    441                        if (var14 > 0.1F)
    442                        {
    443                            GL11.glTranslatef(0.0F, MathHelper.sin((var13 - 0.1F) * 1.3F) * 0.01F * (var14 - 0.1F), 0.0F);
    444                        }
    445
    446                        GL11.glTranslatef(0.0F, 0.0F, var14 * 0.1F);
    447                        GL11.glRotatef(-335.0F, 0.0F, 0.0F, 1.0F);
    448                        GL11.glRotatef(-50.0F, 0.0F, 1.0F, 0.0F);
    449                        GL11.glTranslatef(0.0F, 0.5F, 0.0F);
    450                        var15 = 1.0F + var14 * 0.2F;
    451                        GL11.glScalef(1.0F, 1.0F, var15);
    452                        GL11.glTranslatef(0.0F, -0.5F, 0.0F);
    453                        GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F);
    454                        GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F);
    455                    }
    456                }
    457
    458                if (var17.getItem().shouldRotateAroundWhenRendering())
    459                {
    460                    GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
    461                }
    462
    463                if (var17.getItem().requiresMultipleRenderPasses())
    464                {
    465                    this.renderItem(var3, var17, 0);
    466                    for (int x = 1; x < var17.getItem().getRenderPasses(var17.getItemDamage()); x++)
    467                    {
    468                        int var25 = Item.itemsList[var17.itemID].getColorFromItemStack(var17, x);
    469                        var13 = (float)(var25 >> 16 & 255) / 255.0F;
    470                        var14 = (float)(var25 >> 8 & 255) / 255.0F;
    471                        var15 = (float)(var25 & 255) / 255.0F;
    472                        GL11.glColor4f(var6 * var13, var6 * var14, var6 * var15, 1.0F);
    473                        this.renderItem(var3, var17, x);
    474                    }
    475                }
    476                else
    477                {
    478                    this.renderItem(var3, var17, 0);
    479                }
    480
    481                GL11.glPopMatrix();
    482            }
    483            else if (!var3.getHasActivePotion())
    484            {
    485                GL11.glPushMatrix();
    486                var7 = 0.8F;
    487                var20 = var3.getSwingProgress(par1);
    488                var21 = MathHelper.sin(var20 * (float)Math.PI);
    489                var10 = MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI);
    490                GL11.glTranslatef(-var10 * 0.3F, MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI * 2.0F) * 0.4F, -var21 * 0.4F);
    491                GL11.glTranslatef(0.8F * var7, -0.75F * var7 - (1.0F - var2) * 0.6F, -0.9F * var7);
    492                GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    493                GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    494                var20 = var3.getSwingProgress(par1);
    495                var21 = MathHelper.sin(var20 * var20 * (float)Math.PI);
    496                var10 = MathHelper.sin(MathHelper.sqrt_float(var20) * (float)Math.PI);
    497                GL11.glRotatef(var10 * 70.0F, 0.0F, 1.0F, 0.0F);
    498                GL11.glRotatef(-var21 * 20.0F, 0.0F, 0.0F, 1.0F);
    499                GL11.glBindTexture(GL11.GL_TEXTURE_2D, this.mc.renderEngine.getTextureForDownloadableImage(this.mc.thePlayer.skinUrl, this.mc.thePlayer.getTexture()));
    500                GL11.glTranslatef(-1.0F, 3.6F, 3.5F);
    501                GL11.glRotatef(120.0F, 0.0F, 0.0F, 1.0F);
    502                GL11.glRotatef(200.0F, 1.0F, 0.0F, 0.0F);
    503                GL11.glRotatef(-135.0F, 0.0F, 1.0F, 0.0F);
    504                GL11.glScalef(1.0F, 1.0F, 1.0F);
    505                GL11.glTranslatef(5.6F, 0.0F, 0.0F);
    506                var24 = RenderManager.instance.getEntityRenderObject(this.mc.thePlayer);
    507                var26 = (RenderPlayer)var24;
    508                var13 = 1.0F;
    509                GL11.glScalef(var13, var13, var13);
    510                var26.func_82441_a(this.mc.thePlayer);
    511                GL11.glPopMatrix();
    512            }
    513
    514            GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    515            RenderHelper.disableStandardItemLighting();
    516        }
    517
    518        /**
    519         * Renders all the overlays that are in first person mode. Args: partialTickTime
    520         */
    521        public void renderOverlays(float par1)
    522        {
    523            GL11.glDisable(GL11.GL_ALPHA_TEST);
    524            int var2;
    525
    526            if (this.mc.thePlayer.isBurning())
    527            {
    528                var2 = this.mc.renderEngine.getTexture("/terrain.png");
    529                GL11.glBindTexture(GL11.GL_TEXTURE_2D, var2);
    530                this.renderFireInFirstPerson(par1);
    531            }
    532
    533            if (this.mc.thePlayer.isEntityInsideOpaqueBlock())
    534            {
    535                var2 = MathHelper.floor_double(this.mc.thePlayer.posX);
    536                int var3 = MathHelper.floor_double(this.mc.thePlayer.posY);
    537                int var4 = MathHelper.floor_double(this.mc.thePlayer.posZ);
    538                int var5 = this.mc.renderEngine.getTexture("/terrain.png");
    539                GL11.glBindTexture(GL11.GL_TEXTURE_2D, var5);
    540                int var6 = this.mc.theWorld.getBlockId(var2, var3, var4);
    541
    542                if (this.mc.theWorld.isBlockNormalCube(var2, var3, var4))
    543                {
    544                    this.renderInsideOfBlock(par1, Block.blocksList[var6].getBlockTextureFromSide(2));
    545                }
    546                else
    547                {
    548                    for (int var7 = 0; var7 < 8; ++var7)
    549                    {
    550                        float var8 = ((float)((var7 >> 0) % 2) - 0.5F) * this.mc.thePlayer.width * 0.9F;
    551                        float var9 = ((float)((var7 >> 1) % 2) - 0.5F) * this.mc.thePlayer.height * 0.2F;
    552                        float var10 = ((float)((var7 >> 2) % 2) - 0.5F) * this.mc.thePlayer.width * 0.9F;
    553                        int var11 = MathHelper.floor_float((float)var2 + var8);
    554                        int var12 = MathHelper.floor_float((float)var3 + var9);
    555                        int var13 = MathHelper.floor_float((float)var4 + var10);
    556
    557                        if (this.mc.theWorld.isBlockNormalCube(var11, var12, var13))
    558                        {
    559                            var6 = this.mc.theWorld.getBlockId(var11, var12, var13);
    560                        }
    561                    }
    562                }
    563
    564                if (Block.blocksList[var6] != null)
    565                {
    566                    this.renderInsideOfBlock(par1, Block.blocksList[var6].getBlockTextureFromSide(2));
    567                }
    568            }
    569
    570            if (this.mc.thePlayer.isInsideOfMaterial(Material.water))
    571            {
    572                var2 = this.mc.renderEngine.getTexture("/misc/water.png");
    573                GL11.glBindTexture(GL11.GL_TEXTURE_2D, var2);
    574                this.renderWarpedTextureOverlay(par1);
    575            }
    576
    577            GL11.glEnable(GL11.GL_ALPHA_TEST);
    578        }
    579
    580        /**
    581         * Renders the texture of the block the player is inside as an overlay. Args: partialTickTime, blockTextureIndex
    582         */
    583        private void renderInsideOfBlock(float par1, int par2)
    584        {
    585            Tessellator var3 = Tessellator.instance;
    586            this.mc.thePlayer.getBrightness(par1);
    587            float var4 = 0.1F;
    588            GL11.glColor4f(var4, var4, var4, 0.5F);
    589            GL11.glPushMatrix();
    590            float var5 = -1.0F;
    591            float var6 = 1.0F;
    592            float var7 = -1.0F;
    593            float var8 = 1.0F;
    594            float var9 = -0.5F;
    595            float var10 = 0.0078125F;
    596            float var11 = (float)(par2 % 16) / 256.0F - var10;
    597            float var12 = ((float)(par2 % 16) + 15.99F) / 256.0F + var10;
    598            float var13 = (float)(par2 / 16) / 256.0F - var10;
    599            float var14 = ((float)(par2 / 16) + 15.99F) / 256.0F + var10;
    600            var3.startDrawingQuads();
    601            var3.addVertexWithUV((double)var5, (double)var7, (double)var9, (double)var12, (double)var14);
    602            var3.addVertexWithUV((double)var6, (double)var7, (double)var9, (double)var11, (double)var14);
    603            var3.addVertexWithUV((double)var6, (double)var8, (double)var9, (double)var11, (double)var13);
    604            var3.addVertexWithUV((double)var5, (double)var8, (double)var9, (double)var12, (double)var13);
    605            var3.draw();
    606            GL11.glPopMatrix();
    607            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    608        }
    609
    610        /**
    611         * Renders a texture that warps around based on the direction the player is looking. Texture needs to be bound
    612         * before being called. Used for the water overlay. Args: parialTickTime
    613         */
    614        private void renderWarpedTextureOverlay(float par1)
    615        {
    616            Tessellator var2 = Tessellator.instance;
    617            float var3 = this.mc.thePlayer.getBrightness(par1);
    618            GL11.glColor4f(var3, var3, var3, 0.5F);
    619            GL11.glEnable(GL11.GL_BLEND);
    620            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    621            GL11.glPushMatrix();
    622            float var4 = 4.0F;
    623            float var5 = -1.0F;
    624            float var6 = 1.0F;
    625            float var7 = -1.0F;
    626            float var8 = 1.0F;
    627            float var9 = -0.5F;
    628            float var10 = -this.mc.thePlayer.rotationYaw / 64.0F;
    629            float var11 = this.mc.thePlayer.rotationPitch / 64.0F;
    630            var2.startDrawingQuads();
    631            var2.addVertexWithUV((double)var5, (double)var7, (double)var9, (double)(var4 + var10), (double)(var4 + var11));
    632            var2.addVertexWithUV((double)var6, (double)var7, (double)var9, (double)(0.0F + var10), (double)(var4 + var11));
    633            var2.addVertexWithUV((double)var6, (double)var8, (double)var9, (double)(0.0F + var10), (double)(0.0F + var11));
    634            var2.addVertexWithUV((double)var5, (double)var8, (double)var9, (double)(var4 + var10), (double)(0.0F + var11));
    635            var2.draw();
    636            GL11.glPopMatrix();
    637            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    638            GL11.glDisable(GL11.GL_BLEND);
    639        }
    640
    641        /**
    642         * Renders the fire on the screen for first person mode. Arg: partialTickTime
    643         */
    644        private void renderFireInFirstPerson(float par1)
    645        {
    646            Tessellator var2 = Tessellator.instance;
    647            GL11.glColor4f(1.0F, 1.0F, 1.0F, 0.9F);
    648            GL11.glEnable(GL11.GL_BLEND);
    649            GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    650            float var3 = 1.0F;
    651
    652            for (int var4 = 0; var4 < 2; ++var4)
    653            {
    654                GL11.glPushMatrix();
    655                int var5 = Block.fire.blockIndexInTexture + var4 * 16;
    656                int var6 = (var5 & 15) << 4;
    657                int var7 = var5 & 240;
    658                float var8 = (float)var6 / 256.0F;
    659                float var9 = ((float)var6 + 15.99F) / 256.0F;
    660                float var10 = (float)var7 / 256.0F;
    661                float var11 = ((float)var7 + 15.99F) / 256.0F;
    662                float var12 = (0.0F - var3) / 2.0F;
    663                float var13 = var12 + var3;
    664                float var14 = 0.0F - var3 / 2.0F;
    665                float var15 = var14 + var3;
    666                float var16 = -0.5F;
    667                GL11.glTranslatef((float)(-(var4 * 2 - 1)) * 0.24F, -0.3F, 0.0F);
    668                GL11.glRotatef((float)(var4 * 2 - 1) * 10.0F, 0.0F, 1.0F, 0.0F);
    669                var2.startDrawingQuads();
    670                var2.addVertexWithUV((double)var12, (double)var14, (double)var16, (double)var9, (double)var11);
    671                var2.addVertexWithUV((double)var13, (double)var14, (double)var16, (double)var8, (double)var11);
    672                var2.addVertexWithUV((double)var13, (double)var15, (double)var16, (double)var8, (double)var10);
    673                var2.addVertexWithUV((double)var12, (double)var15, (double)var16, (double)var9, (double)var10);
    674                var2.draw();
    675                GL11.glPopMatrix();
    676            }
    677
    678            GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    679            GL11.glDisable(GL11.GL_BLEND);
    680        }
    681
    682        public void updateEquippedItem()
    683        {
    684            this.prevEquippedProgress = this.equippedProgress;
    685            EntityClientPlayerMP var1 = this.mc.thePlayer;
    686            ItemStack var2 = var1.inventory.getCurrentItem();
    687            boolean var3 = this.equippedItemSlot == var1.inventory.currentItem && var2 == this.itemToRender;
    688
    689            if (this.itemToRender == null && var2 == null)
    690            {
    691                var3 = true;
    692            }
    693
    694            if (var2 != null && this.itemToRender != null && var2 != this.itemToRender && var2.itemID == this.itemToRender.itemID && var2.getItemDamage() == this.itemToRender.getItemDamage())
    695            {
    696                this.itemToRender = var2;
    697                var3 = true;
    698            }
    699
    700            float var4 = 0.4F;
    701            float var5 = var3 ? 1.0F : 0.0F;
    702            float var6 = var5 - this.equippedProgress;
    703
    704            if (var6 < -var4)
    705            {
    706                var6 = -var4;
    707            }
    708
    709            if (var6 > var4)
    710            {
    711                var6 = var4;
    712            }
    713
    714            this.equippedProgress += var6;
    715
    716            if (this.equippedProgress < 0.1F)
    717            {
    718                this.itemToRender = var2;
    719                this.equippedItemSlot = var1.inventory.currentItem;
    720            }
    721        }
    722
    723        public void func_78444_b()
    724        {
    725            this.equippedProgress = 0.0F;
    726        }
    727
    728        public void func_78445_c()
    729        {
    730            this.equippedProgress = 0.0F;
    731        }
    732    }