package net.minecraft.src;

import net.lax1dude.eaglercraft.TextureLocation;
import net.lax1dude.eaglercraft.adapter.Tessellator;
import net.lax1dude.eaglercraft.EaglerAdapter;
import org.lwjgl.opengl.GL12;

public class RenderXPOrb extends Render
{
    private static final TextureLocation experienceOrbTextures = new TextureLocation("textures/entity/experience_orb.png");

    public RenderXPOrb()
    {
        this.shadowSize = 0.15F;
        this.shadowOpaque = 0.75F;
    }

    /**
     * Renders the XP Orb.
     */
    public void renderTheXPOrb(EntityXPOrb par1EntityXPOrb, double par2, double par4, double par6, float par8, float par9)
    {
        EaglerAdapter.glPushMatrix();
        EaglerAdapter.glTranslatef((float)par2, (float)par4, (float)par6);
        this.bindEntityTexture(par1EntityXPOrb);
        int var10 = par1EntityXPOrb.getTextureByXP();
        float var11 = (float)(var10 % 4 * 16 + 0) / 64.0F;
        float var12 = (float)(var10 % 4 * 16 + 16) / 64.0F;
        float var13 = (float)(var10 / 4 * 16 + 0) / 64.0F;
        float var14 = (float)(var10 / 4 * 16 + 16) / 64.0F;
        float var15 = 1.0F;
        float var16 = 0.5F;
        float var17 = 0.25F;
        int var18 = par1EntityXPOrb.getBrightnessForRender(par9);
        int var19 = var18 % 65536;
        int var20 = var18 / 65536;
        OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)var19 / 1.0F, (float)var20 / 1.0F);
        EaglerAdapter.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        float var26 = 255.0F;
        float var27 = ((float)par1EntityXPOrb.xpColor + par9) / 2.0F;
        var20 = (int)((MathHelper.sin(var27 + 0.0F) + 1.0F) * 0.5F * var26);
        int var21 = (int)var26;
        int var22 = (int)((MathHelper.sin(var27 + 4.1887903F) + 1.0F) * 0.1F * var26);
        int var23 = var20 << 16 | var21 << 8 | var22;
        EaglerAdapter.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        EaglerAdapter.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        float var24 = 0.3F;
        EaglerAdapter.glScalef(var24, var24, var24);
        Tessellator var25 = Tessellator.instance;
        var25.startDrawingQuads();
        var25.setColorRGBA_I(var23, 128);
        var25.setNormal(0.0F, 1.0F, 0.0F);
        var25.addVertexWithUV((double)(0.0F - var16), (double)(0.0F - var17), 0.0D, (double)var11, (double)var14);
        var25.addVertexWithUV((double)(var15 - var16), (double)(0.0F - var17), 0.0D, (double)var12, (double)var14);
        var25.addVertexWithUV((double)(var15 - var16), (double)(1.0F - var17), 0.0D, (double)var12, (double)var13);
        var25.addVertexWithUV((double)(0.0F - var16), (double)(1.0F - var17), 0.0D, (double)var11, (double)var13);
        var25.draw();
        EaglerAdapter.glDisable(EaglerAdapter.GL_BLEND);
        EaglerAdapter.glDisable(GL12.GL_RESCALE_NORMAL);
        EaglerAdapter.glPopMatrix();
    }

    protected TextureLocation getExperienceOrbTextures(EntityXPOrb par1EntityXPOrb)
    {
        return experienceOrbTextures;
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected TextureLocation getEntityTexture(Entity par1Entity)
    {
        return this.getExperienceOrbTextures((EntityXPOrb)par1Entity);
    }

    /**
     * Actually renders the given argument. This is a synthetic bridge method, always casting down its argument and then
     * handing it off to a worker function which does the actual work. In all probabilty, the class Render is generic
     * (Render<T extends Entity) and this method has signature public void doRender(T entity, double d, double d1,
     * double d2, float f, float f1). But JAD is pre 1.5 so doesn't do that.
     */
    public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
    {
        this.renderTheXPOrb((EntityXPOrb)par1Entity, par2, par4, par6, par8, par9);
    }
}
