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