package client.renderer.entity;

import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL13;

import client.renderer.DefaultVertexFormats;
import client.renderer.GlState;
import client.renderer.RenderBuffer;
import client.renderer.Tessellator;
import common.entity.item.EntityXp;
import common.util.ExtMath;


public class RenderXpOrb extends Render<EntityXp>
{
    private static final String experienceOrbTextures = "textures/entity/experience_orb.png";

    public RenderXpOrb(RenderManager renderManagerIn)
    {
        super(renderManagerIn);
//        this.shadowSize = 0.15F;
//        this.shadowOpaque = 0.75F;
    }

    /**
     * Renders the desired {@code T} type Entity.
     */
    public void doRender(EntityXp entity, double x, double y, double z, float partialTicks)
    {
        GL11.glPushMatrix();
        GL11.glTranslatef((float)x, (float)y, (float)z);
        this.bindEntityTexture(entity);
        int i = entity.getXpValue();
        float f = (float)(i % 4 * 16 + 0) / 64.0F;
        float f1 = (float)(i % 4 * 16 + 16) / 64.0F;
        float f2 = (float)(i / 4 * 16 + 0) / 64.0F;
        float f3 = (float)(i / 4 * 16 + 16) / 64.0F;
        float f4 = 1.0F;
        float f5 = 0.5F;
        float f6 = 0.25F;
        int j = entity.getBrightnessForRender(partialTicks);
        int k = j % 65536;
        int l = j / 65536;
        GL13.glMultiTexCoord2f(GL13.GL_TEXTURE1, (float)k / 1.0F, (float)l / 1.0F);
        GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
        float f8 = 255.0F;
        float f9 = ((float)entity.xpColor + partialTicks) / 2.0F;
        l = (int)((ExtMath.sin(f9 + 0.0F) + 1.0F) * 0.5F * 255.0F);
        int i1 = 255;
        int j1 = (int)((ExtMath.sin(f9 + 4.1887903F) + 1.0F) * 0.1F * 255.0F);
        GL11.glRotatef(180.0F - this.renderManager.playerViewY, 0.0F, 1.0F, 0.0F);
        GL11.glRotatef(-this.renderManager.playerViewX, 1.0F, 0.0F, 0.0F);
        float f7 = 0.3F;
        GL11.glScalef(0.3F, 0.3F, 0.3F);
//        Tessellator tessellator = Tessellator.getInstance();
        RenderBuffer worldrenderer = Tessellator.getBuffer();
        worldrenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL);
        worldrenderer.pos((double)(0.0F - f5), (double)(0.0F - f6), 0.0D).tex((double)f, (double)f3).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex();
        worldrenderer.pos((double)(f4 - f5), (double)(0.0F - f6), 0.0D).tex((double)f1, (double)f3).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex();
        worldrenderer.pos((double)(f4 - f5), (double)(1.0F - f6), 0.0D).tex((double)f1, (double)f2).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex();
        worldrenderer.pos((double)(0.0F - f5), (double)(1.0F - f6), 0.0D).tex((double)f, (double)f2).color(l, 255, j1, 128).normal(0.0F, 1.0F, 0.0F).endVertex();
        Tessellator.draw();
        GlState.disableBlend();
        GlState.disableRescaleNormal();
        GL11.glPopMatrix();
        super.doRender(entity, x, y, z, partialTicks);
    }

    /**
     * Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
     */
    protected String getEntityTexture(EntityXp entity)
    {
        return experienceOrbTextures;
    }

//    protected boolean canRenderName(EntityXp entity)
//    {
//        return entity.hasCustomName() || super.canRenderName(entity);
//    }
    
    protected void renderLivingLabel(EntityXp entityIn, String str, double x, double y, double z, int maxDistance) {
    	super.renderLivingLabel(entityIn, str, x, y - 0.5, z, maxDistance);
    }
}
