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