package net.minecraft.client.renderer.entity;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.client.model.ModelEnderman;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;

@SideOnly(Side.CLIENT)
public class RenderEnderman extends RenderLiving
{
	private static final ResourceLocation endermanEyesTexture = new ResourceLocation("textures/entity/enderman/enderman_eyes.png");
	private static final ResourceLocation endermanTextures = new ResourceLocation("textures/entity/enderman/enderman.png");
	private ModelEnderman endermanModel;
	private Random rnd = new Random();
	private static final String __OBFID = "CL_00000989";

	public RenderEnderman()
	{
		super(new ModelEnderman(), 0.5F);
		this.endermanModel = (ModelEnderman)super.mainModel;
		this.setRenderPassModel(this.endermanModel);
	}

	public void doRender(EntityEnderman par1EntityEnderman, double par2, double par4, double par6, float par8, float par9)
	{
		this.endermanModel.isCarrying = par1EntityEnderman.func_146080_bZ().getMaterial() != Material.air;
		this.endermanModel.isAttacking = par1EntityEnderman.isScreaming();

		if (par1EntityEnderman.isScreaming())
		{
			double d3 = 0.02D;
			par2 += this.rnd.nextGaussian() * d3;
			par6 += this.rnd.nextGaussian() * d3;
		}

		super.doRender((EntityLiving)par1EntityEnderman, par2, par4, par6, par8, par9);
	}

	protected ResourceLocation getEntityTexture(EntityEnderman par1EntityEnderman)
	{
		return endermanTextures;
	}

	protected void renderEquippedItems(EntityEnderman par1EntityEnderman, float par2)
	{
		super.renderEquippedItems(par1EntityEnderman, par2);

		if (par1EntityEnderman.func_146080_bZ().getMaterial() != Material.air)
		{
			GL11.glEnable(GL12.GL_RESCALE_NORMAL);
			GL11.glPushMatrix();
			float f1 = 0.5F;
			GL11.glTranslatef(0.0F, 0.6875F, -0.75F);
			f1 *= 1.0F;
			GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
			GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
			GL11.glScalef(-f1, -f1, f1);
			int i = par1EntityEnderman.getBrightnessForRender(par2);
			int j = i % 65536;
			int k = i / 65536;
			OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F);
			GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
			this.bindTexture(TextureMap.locationBlocksTexture);
			this.field_147909_c.renderBlockAsItem(par1EntityEnderman.func_146080_bZ(), par1EntityEnderman.getCarryingData(), 1.0F);
			GL11.glPopMatrix();
			GL11.glDisable(GL12.GL_RESCALE_NORMAL);
		}
	}

	protected int shouldRenderPass(EntityEnderman par1EntityEnderman, int par2, float par3)
	{
		if (par2 != 0)
		{
			return -1;
		}
		else
		{
			this.bindTexture(endermanEyesTexture);
			float f1 = 1.0F;
			GL11.glEnable(GL11.GL_BLEND);
			GL11.glDisable(GL11.GL_ALPHA_TEST);
			GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
			GL11.glDisable(GL11.GL_LIGHTING);

			if (par1EntityEnderman.isInvisible())
			{
				GL11.glDepthMask(false);
			}
			else
			{
				GL11.glDepthMask(true);
			}

			char c0 = 61680;
			int j = c0 % 65536;
			int k = c0 / 65536;
			OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)j / 1.0F, (float)k / 1.0F);
			GL11.glEnable(GL11.GL_LIGHTING);
			GL11.glColor4f(1.0F, 1.0F, 1.0F, f1);
			return 1;
		}
	}

	public void doRender(EntityLiving par1EntityLiving, double par2, double par4, double par6, float par8, float par9)
	{
		this.doRender((EntityEnderman)par1EntityLiving, par2, par4, par6, par8, par9);
	}

	protected int shouldRenderPass(EntityLivingBase par1EntityLivingBase, int par2, float par3)
	{
		return this.shouldRenderPass((EntityEnderman)par1EntityLivingBase, par2, par3);
	}

	protected void renderEquippedItems(EntityLivingBase par1EntityLivingBase, float par2)
	{
		this.renderEquippedItems((EntityEnderman)par1EntityLivingBase, par2);
	}

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

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

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