package net.minecraft.client.renderer.entity;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

@SideOnly(Side.CLIENT)
public class RenderXPOrb extends Render
{
	private static final ResourceLocation experienceOrbTextures = new ResourceLocation("textures/entity/experience_orb.png");
	private static final String __OBFID = "CL_00000993";

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

	public void doRender(EntityXPOrb par1EntityXPOrb, double par2, double par4, double par6, float par8, float par9)
	{
		GL11.glPushMatrix();
		GL11.glTranslatef((float)par2, (float)par4, (float)par6);
		this.bindEntityTexture(par1EntityXPOrb);
		int i = par1EntityXPOrb.getTextureByXP();
		float f2 = (float)(i % 4 * 16 + 0) / 64.0F;
		float f3 = (float)(i % 4 * 16 + 16) / 64.0F;
		float f4 = (float)(i / 4 * 16 + 0) / 64.0F;
		float f5 = (float)(i / 4 * 16 + 16) / 64.0F;
		float f6 = 1.0F;
		float f7 = 0.5F;
		float f8 = 0.25F;
		int j = par1EntityXPOrb.getBrightnessForRender(par9);
		int k = j % 65536;
		int l = j / 65536;
		OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)k / 1.0F, (float)l / 1.0F);
		GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
		float f10 = 255.0F;
		float f11 = ((float)par1EntityXPOrb.xpColor + par9) / 2.0F;
		l = (int)((MathHelper.sin(f11 + 0.0F) + 1.0F) * 0.5F * f10);
		int i1 = (int)f10;
		int j1 = (int)((MathHelper.sin(f11 + 4.1887903F) + 1.0F) * 0.1F * f10);
		int k1 = l << 16 | i1 << 8 | j1;
		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 f9 = 0.3F;
		GL11.glScalef(f9, f9, f9);
		Tessellator tessellator = Tessellator.instance;
		tessellator.startDrawingQuads();
		tessellator.setColorRGBA_I(k1, 128);
		tessellator.setNormal(0.0F, 1.0F, 0.0F);
		tessellator.addVertexWithUV((double)(0.0F - f7), (double)(0.0F - f8), 0.0D, (double)f2, (double)f5);
		tessellator.addVertexWithUV((double)(f6 - f7), (double)(0.0F - f8), 0.0D, (double)f3, (double)f5);
		tessellator.addVertexWithUV((double)(f6 - f7), (double)(1.0F - f8), 0.0D, (double)f3, (double)f4);
		tessellator.addVertexWithUV((double)(0.0F - f7), (double)(1.0F - f8), 0.0D, (double)f2, (double)f4);
		tessellator.draw();
		GL11.glDisable(GL11.GL_BLEND);
		GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		GL11.glPopMatrix();
	}

	protected ResourceLocation getEntityTexture(EntityXPOrb par1EntityXPOrb)
	{
		return experienceOrbTextures;
	}

	protected ResourceLocation getEntityTexture(Entity par1Entity)
	{
		return this.getEntityTexture((EntityXPOrb)par1Entity);
	}

	public void doRender(Entity par1Entity, double par2, double par4, double par6, float par8, float par9)
	{
		this.doRender((EntityXPOrb)par1Entity, par2, par4, par6, par8, par9);
	}
}