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