    001package net.minecraft.client.renderer.entity;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.renderer.Tessellator;
    006import net.minecraft.entity.Entity;
    007import net.minecraft.entity.projectile.EntityPotion;
    008import net.minecraft.item.Item;
    009import net.minecraft.item.ItemPotion;
    010import net.minecraft.potion.PotionHelper;
    011import net.minecraft.util.Icon;
    012import org.lwjgl.opengl.GL11;
    013import org.lwjgl.opengl.GL12;
    014
    015@SideOnly(Side.CLIENT)
    016public class RenderSnowball extends Render
    017{
    018    private Item field_94151_a;
    019    private int field_94150_f;
    020
    021    /**
    022     * Have the icon index (in items.png) that will be used to render the image. Currently, eggs and snowballs uses this
    023     * classes.
    024     */
    025    private Icon itemIconIndex;
    026
    027    public RenderSnowball(Item par1, int par2)
    028    {
    029        this.field_94151_a = par1;
    030        this.field_94150_f = par2;
    031    }
    032
    033    public RenderSnowball(Item par1)
    034    {
    035        this(par1, 0);
    036    }
    037
    038    /**
    039     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
    040     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
    041     * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
    042     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
    043     */
    044    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    045    {
    046        if (this.itemIconIndex == null)
    047        {
    048            this.itemIconIndex = this.field_94151_a.getIconFromDamage(this.field_94150_f);
    049        }
    050
    051        GL11.glPushMatrix();
    052        GL11.glTranslatef((float)par2, (float)par4, (float)par6);
    053        GL11.glEnable(GL12.GL_RESCALE_NORMAL);
    054        GL11.glScalef(0.5F, 0.5F, 0.5F);
    055        this.loadTexture("/gui/items.png");
    056        Tessellator tessellator = Tessellator.instance;
    057
    058        if (this.itemIconIndex == ItemPotion.func_94589_d("potion_splash"))
    059        {
    060            int i = PotionHelper.func_77915_a(((EntityPotion)par1Entity).getPotionDamage(), false);
    061            float f2 = (float)(i >> 16 & 255) / 255.0F;
    062            float f3 = (float)(i >> 8 & 255) / 255.0F;
    063            float f4 = (float)(i & 255) / 255.0F;
    064            GL11.glColor3f(f2, f3, f4);
    065            GL11.glPushMatrix();
    066            this.func_77026_a(tessellator, ItemPotion.func_94589_d("potion_contents"));
    067            GL11.glPopMatrix();
    068            GL11.glColor3f(1.0F, 1.0F, 1.0F);
    069        }
    070
    071        this.func_77026_a(tessellator, this.itemIconIndex);
    072        GL11.glDisable(GL12.GL_RESCALE_NORMAL);
    073        GL11.glPopMatrix();
    074    }
    075
    076    private void func_77026_a(Tessellator par1Tessellator, Icon par2Icon)
    077    {
    078        float f = par2Icon.func_94209_e();
    079        float f1 = par2Icon.func_94212_f();
    080        float f2 = par2Icon.func_94206_g();
    081        float f3 = par2Icon.func_94210_h();
    082        float f4 = 1.0F;
    083        float f5 = 0.5F;
    084        float f6 = 0.25F;
    085        GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
    086        GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
    087        par1Tessellator.startDrawingQuads();
    088        par1Tessellator.setNormal(0.0F, 1.0F, 0.0F);
    089        par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(0.0F - f6), 0.0D, (double)f, (double)f3);
    090        par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(0.0F - f6), 0.0D, (double)f1, (double)f3);
    091        par1Tessellator.addVertexWithUV((double)(f4 - f5), (double)(f4 - f6), 0.0D, (double)f1, (double)f2);
    092        par1Tessellator.addVertexWithUV((double)(0.0F - f5), (double)(f4 - f6), 0.0D, (double)f, (double)f2);
    093        par1Tessellator.draw();
    094    }
    095}