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