    001    package net.minecraft.src;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import java.util.Random;
    006    import net.minecraft.client.Minecraft;
    007    import net.minecraftforge.client.ForgeHooksClient;
    008
    009    import org.lwjgl.opengl.GL11;
    010    import org.lwjgl.opengl.GL12;
    011
    012    @SideOnly(Side.CLIENT)
    013    public class RenderItem extends Render
    014    {
    015        private RenderBlocks renderBlocks = new RenderBlocks();
    016
    017        /** The RNG used in RenderItem (for bobbing itemstacks on the ground) */
    018        private Random random = new Random();
    019        public boolean field_77024_a = true;
    020
    021        /** Defines the zLevel of rendering of item on GUI. */
    022        public float zLevel = 0.0F;
    023        public static boolean field_82407_g = false;
    024
    025        public RenderItem()
    026        {
    027            this.shadowSize = 0.15F;
    028            this.shadowOpaque = 0.75F;
    029        }
    030
    031        /**
    032         * Renders the item
    033         */
    034        public void doRenderItem(EntityItem par1EntityItem, double par2, double par4, double par6, float par8, float par9)
    035        {
    036            this.random.setSeed(187L);
    037            ItemStack var10 = par1EntityItem.item;
    038
    039            if (var10.getItem() != null)
    040            {
    041                GL11.glPushMatrix();
    042                float var11 = MathHelper.sin(((float)par1EntityItem.age + par9) / 10.0F + par1EntityItem.hoverStart) * 0.1F + 0.1F;
    043                float var12 = (((float)par1EntityItem.age + par9) / 20.0F + par1EntityItem.hoverStart) * (180F / (float)Math.PI);
    044                byte var13 = 1;
    045
    046                if (par1EntityItem.item.stackSize > 1)
    047                {
    048                    var13 = 2;
    049                }
    050
    051                if (par1EntityItem.item.stackSize > 5)
    052                {
    053                    var13 = 3;
    054                }
    055
    056                if (par1EntityItem.item.stackSize > 20)
    057                {
    058                    var13 = 4;
    059                }
    060
    061                GL11.glTranslatef((float)par2, (float)par4 + var11, (float)par6);
    062                GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    063                int var16;
    064                float var19;
    065                float var20;
    066                float var24;
    067
    068                if (ForgeHooksClient.renderEntityItem(par1EntityItem, var10, var11, var12, random, renderManager.renderEngine, renderBlocks))
    069                {
    070                    ;
    071                }
    072                else if (var10.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.blocksList[var10.itemID].getRenderType()))
    073                {
    074                    GL11.glRotatef(var12, 0.0F, 1.0F, 0.0F);
    075
    076                    if (field_82407_g)
    077                    {
    078                        GL11.glScalef(1.25F, 1.25F, 1.25F);
    079                        GL11.glTranslatef(0.0F, 0.05F, 0.0F);
    080                        GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
    081                    }
    082
    083                    this.loadTexture(Block.blocksList[var10.itemID].getTextureFile());
    084                    float var22 = 0.25F;
    085                    var16 = Block.blocksList[var10.itemID].getRenderType();
    086
    087                    if (var16 == 1 || var16 == 19 || var16 == 12 || var16 == 2)
    088                    {
    089                        var22 = 0.5F;
    090                    }
    091
    092                    GL11.glScalef(var22, var22, var22);
    093
    094                    for (int var23 = 0; var23 < var13; ++var23)
    095                    {
    096                        GL11.glPushMatrix();
    097
    098                        if (var23 > 0)
    099                        {
    100                            var24 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var22;
    101                            var19 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var22;
    102                            var20 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var22;
    103                            GL11.glTranslatef(var24, var19, var20);
    104                        }
    105
    106                        var24 = 1.0F;
    107                        this.renderBlocks.renderBlockAsItem(Block.blocksList[var10.itemID], var10.getItemDamage(), var24);
    108                        GL11.glPopMatrix();
    109                    }
    110                }
    111                else
    112                {
    113                    int var15;
    114                    float var17;
    115
    116                    if (var10.getItem().requiresMultipleRenderPasses())
    117                    {
    118                        if (field_82407_g)
    119                        {
    120                            GL11.glScalef(0.5128205F, 0.5128205F, 0.5128205F);
    121                            GL11.glTranslatef(0.0F, -0.05F, 0.0F);
    122                            GL11.glDisable(GL11.GL_LIGHTING);
    123                        }
    124                        else
    125                        {
    126                            GL11.glScalef(0.5F, 0.5F, 0.5F);
    127                        }
    128
    129                        this.loadTexture(Item.itemsList[var10.itemID].getTextureFile());
    130
    131                        for (var15 = 0; var15 < var10.getItem().getRenderPasses(var10.getItemDamage()); ++var15)
    132                        {
    133                            this.random.setSeed(187L); //Fixes Vanilla bug where layers would not render aligns properly.
    134                            var16 = var10.getItem().getIconFromItemStackForMultiplePasses(var10, var15);
    135                            var17 = 1.0F;
    136
    137                            if (this.field_77024_a)
    138                            {
    139                                int var18 = Item.itemsList[var10.itemID].getColorFromItemStack(var10, var15);
    140                                var19 = (float)(var18 >> 16 & 255) / 255.0F;
    141                                var20 = (float)(var18 >> 8 & 255) / 255.0F;
    142                                float var21 = (float)(var18 & 255) / 255.0F;
    143                                GL11.glColor4f(var19 * var17, var20 * var17, var21 * var17, 1.0F);
    144                            }
    145
    146                            this.func_77020_a(var16, var13);
    147                        }
    148                    }
    149                    else
    150                    {
    151                        if (field_82407_g)
    152                        {
    153                            GL11.glScalef(0.5128205F, 0.5128205F, 0.5128205F);
    154                            GL11.glTranslatef(0.0F, -0.05F, 0.0F);
    155                            GL11.glDisable(GL11.GL_LIGHTING);
    156                        }
    157                        else
    158                        {
    159                            GL11.glScalef(0.5F, 0.5F, 0.5F);
    160                        }
    161
    162                        var15 = var10.getIconIndex();
    163
    164                        this.loadTexture(var10.getItem().getTextureFile());
    165
    166                        if (this.field_77024_a)
    167                        {
    168                            var16 = Item.itemsList[var10.itemID].getColorFromItemStack(var10, 0);
    169                            var17 = (float)(var16 >> 16 & 255) / 255.0F;
    170                            var24 = (float)(var16 >> 8 & 255) / 255.0F;
    171                            var19 = (float)(var16 & 255) / 255.0F;
    172                            var20 = 1.0F;
    173                            GL11.glColor4f(var17 * var20, var24 * var20, var19 * var20, 1.0F);
    174                        }
    175
    176                        this.func_77020_a(var15, var13);
    177                    }
    178                }
    179
    180                GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    181                GL11.glPopMatrix();
    182            }
    183        }
    184
    185        private void func_77020_a(int par1, int par2)
    186        {
    187            Tessellator var3 = Tessellator.instance;
    188            float var4 = (float)(par1 % 16 * 16 + 0) / 256.0F;
    189            float var5 = (float)(par1 % 16 * 16 + 16) / 256.0F;
    190            float var6 = (float)(par1 / 16 * 16 + 0) / 256.0F;
    191            float var7 = (float)(par1 / 16 * 16 + 16) / 256.0F;
    192            float var8 = 1.0F;
    193            float var9 = 0.5F;
    194            float var10 = 0.25F;
    195
    196            for (int var11 = 0; var11 < par2; ++var11)
    197            {
    198                GL11.glPushMatrix();
    199
    200                if (var11 > 0)
    201                {
    202                    float var12 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
    203                    float var13 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
    204                    float var14 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F;
    205                    GL11.glTranslatef(var12, var13, var14);
    206                }
    207
    208                GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
    209                var3.startDrawingQuads();
    210                var3.setNormal(0.0F, 1.0F, 0.0F);
    211                var3.addVertexWithUV((double)(0.0F - var9), (double)(0.0F - var10), 0.0D, (double)var4, (double)var7);
    212                var3.addVertexWithUV((double)(var8 - var9), (double)(0.0F - var10), 0.0D, (double)var5, (double)var7);
    213                var3.addVertexWithUV((double)(var8 - var9), (double)(1.0F - var10), 0.0D, (double)var5, (double)var6);
    214                var3.addVertexWithUV((double)(0.0F - var9), (double)(1.0F - var10), 0.0D, (double)var4, (double)var6);
    215                var3.draw();
    216                GL11.glPopMatrix();
    217            }
    218        }
    219
    220        /**
    221         * Renders the item's icon or block into the UI at the specified position.
    222         */
    223        public void renderItemIntoGUI(FontRenderer par1FontRenderer, RenderEngine par2RenderEngine, ItemStack par3ItemStack, int par4, int par5)
    224        {
    225            int var6 = par3ItemStack.itemID;
    226            int var7 = par3ItemStack.getItemDamage();
    227            int var8 = par3ItemStack.getIconIndex();
    228            int var10;
    229            float var12;
    230            float var13;
    231            float var16;
    232
    233            if (par3ItemStack.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.blocksList[par3ItemStack.itemID].getRenderType()))
    234            {
    235                Block var15 = Block.blocksList[var6];
    236                par2RenderEngine.bindTexture(par2RenderEngine.getTexture(var15.getTextureFile()));
    237                GL11.glPushMatrix();
    238                GL11.glTranslatef((float)(par4 - 2), (float)(par5 + 3), -3.0F + this.zLevel);
    239                GL11.glScalef(10.0F, 10.0F, 10.0F);
    240                GL11.glTranslatef(1.0F, 0.5F, 1.0F);
    241                GL11.glScalef(1.0F, 1.0F, -1.0F);
    242                GL11.glRotatef(210.0F, 1.0F, 0.0F, 0.0F);
    243                GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
    244                var10 = Item.itemsList[var6].getColorFromItemStack(par3ItemStack, 0);
    245                var16 = (float)(var10 >> 16 & 255) / 255.0F;
    246                var12 = (float)(var10 >> 8 & 255) / 255.0F;
    247                var13 = (float)(var10 & 255) / 255.0F;
    248
    249                if (this.field_77024_a)
    250                {
    251                    GL11.glColor4f(var16, var12, var13, 1.0F);
    252                }
    253
    254                GL11.glRotatef(-90.0F, 0.0F, 1.0F, 0.0F);
    255                this.renderBlocks.useInventoryTint = this.field_77024_a;
    256                this.renderBlocks.renderBlockAsItem(var15, var7, 1.0F);
    257                this.renderBlocks.useInventoryTint = true;
    258                GL11.glPopMatrix();
    259            }
    260            else
    261            {
    262                int var9;
    263
    264                if (Item.itemsList[var6].requiresMultipleRenderPasses())
    265                {
    266                    GL11.glDisable(GL11.GL_LIGHTING);
    267                    par2RenderEngine.bindTexture(par2RenderEngine.getTexture(Item.itemsList[var6].getTextureFile()));
    268
    269                    for (var9 = 0; var9 < Item.itemsList[var6].getRenderPasses(var7); ++var9)
    270                    {
    271                        var10 = Item.itemsList[var6].getIconFromItemStackForMultiplePasses(par3ItemStack, var9);
    272                        int var11 = Item.itemsList[var6].getColorFromItemStack(par3ItemStack, var9);
    273                        var12 = (float)(var11 >> 16 & 255) / 255.0F;
    274                        var13 = (float)(var11 >> 8 & 255) / 255.0F;
    275                        float var14 = (float)(var11 & 255) / 255.0F;
    276
    277                        if (this.field_77024_a)
    278                        {
    279                            GL11.glColor4f(var12, var13, var14, 1.0F);
    280                        }
    281
    282                        this.renderTexturedQuad(par4, par5, var10 % 16 * 16, var10 / 16 * 16, 16, 16);
    283                    }
    284
    285                    GL11.glEnable(GL11.GL_LIGHTING);
    286                }
    287                else if (var8 >= 0)
    288                {
    289                    GL11.glDisable(GL11.GL_LIGHTING);
    290
    291                    par2RenderEngine.bindTexture(par2RenderEngine.getTexture(par3ItemStack.getItem().getTextureFile()));
    292
    293                    var9 = Item.itemsList[var6].getColorFromItemStack(par3ItemStack, 0);
    294                    float var17 = (float)(var9 >> 16 & 255) / 255.0F;
    295                    var16 = (float)(var9 >> 8 & 255) / 255.0F;
    296                    var12 = (float)(var9 & 255) / 255.0F;
    297
    298                    if (this.field_77024_a)
    299                    {
    300                        GL11.glColor4f(var17, var16, var12, 1.0F);
    301                    }
    302
    303                    this.renderTexturedQuad(par4, par5, var8 % 16 * 16, var8 / 16 * 16, 16, 16);
    304                    GL11.glEnable(GL11.GL_LIGHTING);
    305                }
    306            }
    307
    308            GL11.glEnable(GL11.GL_CULL_FACE);
    309        }
    310
    311        /**
    312         * Render the item's icon or block into the GUI, including the glint effect.
    313         */
    314        public void renderItemAndEffectIntoGUI(FontRenderer par1FontRenderer, RenderEngine par2RenderEngine, ItemStack par3ItemStack, int par4, int par5)
    315        {
    316            if (par3ItemStack != null)
    317            {
    318                if (!ForgeHooksClient.renderInventoryItem(renderBlocks, par2RenderEngine, par3ItemStack, field_77024_a, zLevel, (float)par4, (float)par5))
    319                {
    320                    this.renderItemIntoGUI(par1FontRenderer, par2RenderEngine, par3ItemStack, par4, par5);
    321                }
    322
    323                if (par3ItemStack != null && par3ItemStack.hasEffect())
    324                {
    325                    GL11.glDepthFunc(GL11.GL_GREATER);
    326                    GL11.glDisable(GL11.GL_LIGHTING);
    327                    GL11.glDepthMask(false);
    328                    par2RenderEngine.bindTexture(par2RenderEngine.getTexture("%blur%/misc/glint.png"));
    329                    this.zLevel -= 50.0F;
    330                    GL11.glEnable(GL11.GL_BLEND);
    331                    GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_DST_COLOR);
    332                    GL11.glColor4f(0.5F, 0.25F, 0.8F, 1.0F);
    333                    this.func_77018_a(par4 * 431278612 + par5 * 32178161, par4 - 2, par5 - 2, 20, 20);
    334                    GL11.glDisable(GL11.GL_BLEND);
    335                    GL11.glDepthMask(true);
    336                    this.zLevel += 50.0F;
    337                    GL11.glEnable(GL11.GL_LIGHTING);
    338                    GL11.glDepthFunc(GL11.GL_LEQUAL);
    339                }
    340            }
    341        }
    342
    343        private void func_77018_a(int par1, int par2, int par3, int par4, int par5)
    344        {
    345            for (int var6 = 0; var6 < 2; ++var6)
    346            {
    347                if (var6 == 0)
    348                {
    349                    GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
    350                }
    351
    352                if (var6 == 1)
    353                {
    354                    GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
    355                }
    356
    357                float var7 = 0.00390625F;
    358                float var8 = 0.00390625F;
    359                float var9 = (float)(Minecraft.getSystemTime() % (long)(3000 + var6 * 1873)) / (3000.0F + (float)(var6 * 1873)) * 256.0F;
    360                float var10 = 0.0F;
    361                Tessellator var11 = Tessellator.instance;
    362                float var12 = 4.0F;
    363
    364                if (var6 == 1)
    365                {
    366                    var12 = -1.0F;
    367                }
    368
    369                var11.startDrawingQuads();
    370                var11.addVertexWithUV((double)(par2 + 0), (double)(par3 + par5), (double)this.zLevel, (double)((var9 + (float)par5 * var12) * var7), (double)((var10 + (float)par5) * var8));
    371                var11.addVertexWithUV((double)(par2 + par4), (double)(par3 + par5), (double)this.zLevel, (double)((var9 + (float)par4 + (float)par5 * var12) * var7), (double)((var10 + (float)par5) * var8));
    372                var11.addVertexWithUV((double)(par2 + par4), (double)(par3 + 0), (double)this.zLevel, (double)((var9 + (float)par4) * var7), (double)((var10 + 0.0F) * var8));
    373                var11.addVertexWithUV((double)(par2 + 0), (double)(par3 + 0), (double)this.zLevel, (double)((var9 + 0.0F) * var7), (double)((var10 + 0.0F) * var8));
    374                var11.draw();
    375            }
    376        }
    377
    378        /**
    379         * Renders the item's overlay information. Examples being stack count or damage on top of the item's image at the
    380         * specified position.
    381         */
    382        public void renderItemOverlayIntoGUI(FontRenderer par1FontRenderer, RenderEngine par2RenderEngine, ItemStack par3ItemStack, int par4, int par5)
    383        {
    384            if (par3ItemStack != null)
    385            {
    386                if (par3ItemStack.stackSize > 1)
    387                {
    388                    String var6 = "" + par3ItemStack.stackSize;
    389                    GL11.glDisable(GL11.GL_LIGHTING);
    390                    GL11.glDisable(GL11.GL_DEPTH_TEST);
    391                    par1FontRenderer.drawStringWithShadow(var6, par4 + 19 - 2 - par1FontRenderer.getStringWidth(var6), par5 + 6 + 3, 16777215);
    392                    GL11.glEnable(GL11.GL_LIGHTING);
    393                    GL11.glEnable(GL11.GL_DEPTH_TEST);
    394                }
    395
    396                if (par3ItemStack.isItemDamaged())
    397                {
    398                    int var11 = (int)Math.round(13.0D - (double)par3ItemStack.getItemDamageForDisplay() * 13.0D / (double)par3ItemStack.getMaxDamage());
    399                    int var7 = (int)Math.round(255.0D - (double)par3ItemStack.getItemDamageForDisplay() * 255.0D / (double)par3ItemStack.getMaxDamage());
    400                    GL11.glDisable(GL11.GL_LIGHTING);
    401                    GL11.glDisable(GL11.GL_DEPTH_TEST);
    402                    GL11.glDisable(GL11.GL_TEXTURE_2D);
    403                    Tessellator var8 = Tessellator.instance;
    404                    int var9 = 255 - var7 << 16 | var7 << 8;
    405                    int var10 = (255 - var7) / 4 << 16 | 16128;
    406                    this.renderQuad(var8, par4 + 2, par5 + 13, 13, 2, 0);
    407                    this.renderQuad(var8, par4 + 2, par5 + 13, 12, 1, var10);
    408                    this.renderQuad(var8, par4 + 2, par5 + 13, var11, 1, var9);
    409                    GL11.glEnable(GL11.GL_TEXTURE_2D);
    410                    GL11.glEnable(GL11.GL_LIGHTING);
    411                    GL11.glEnable(GL11.GL_DEPTH_TEST);
    412                    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    413                }
    414            }
    415        }
    416
    417        /**
    418         * Adds a quad to the tesselator at the specified position with the set width and height and color.  Args:
    419         * tessellator, x, y, width, height, color
    420         */
    421        private void renderQuad(Tessellator par1Tessellator, int par2, int par3, int par4, int par5, int par6)
    422        {
    423            par1Tessellator.startDrawingQuads();
    424            par1Tessellator.setColorOpaque_I(par6);
    425            par1Tessellator.addVertex((double)(par2 + 0), (double)(par3 + 0), 0.0D);
    426            par1Tessellator.addVertex((double)(par2 + 0), (double)(par3 + par5), 0.0D);
    427            par1Tessellator.addVertex((double)(par2 + par4), (double)(par3 + par5), 0.0D);
    428            par1Tessellator.addVertex((double)(par2 + par4), (double)(par3 + 0), 0.0D);
    429            par1Tessellator.draw();
    430        }
    431
    432        /**
    433         * Adds a textured quad to the tesselator at the specified position with the specified texture coords, width and
    434         * height.  Args: x, y, u, v, width, height
    435         */
    436        public void renderTexturedQuad(int par1, int par2, int par3, int par4, int par5, int par6)
    437        {
    438            float var7 = 0.00390625F;
    439            float var8 = 0.00390625F;
    440            Tessellator var9 = Tessellator.instance;
    441            var9.startDrawingQuads();
    442            var9.addVertexWithUV((double)(par1 + 0), (double)(par2 + par6), (double)this.zLevel, (double)((float)(par3 + 0) * var7), (double)((float)(par4 + par6) * var8));
    443            var9.addVertexWithUV((double)(par1 + par5), (double)(par2 + par6), (double)this.zLevel, (double)((float)(par3 + par5) * var7), (double)((float)(par4 + par6) * var8));
    444            var9.addVertexWithUV((double)(par1 + par5), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + par5) * var7), (double)((float)(par4 + 0) * var8));
    445            var9.addVertexWithUV((double)(par1 + 0), (double)(par2 + 0), (double)this.zLevel, (double)((float)(par3 + 0) * var7), (double)((float)(par4 + 0) * var8));
    446            var9.draw();
    447        }
    448
    449        /**
    450         * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    451         * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    452         * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    453         * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    454         */
    455        public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    456        {
    457            this.doRenderItem((EntityItem)par1Entity, par2, par4, par6, par8, par9);
    458        }
    459    }