package net.minecraft.client.renderer.entity;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.model.ModelWither;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.boss.BossStatus;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;

@SideOnly(Side.CLIENT)
public class RenderWither extends RenderLiving
{
	private static final ResourceLocation invulnerableWitherTextures = new ResourceLocation("textures/entity/wither/wither_invulnerable.png");
	private static final ResourceLocation witherTextures = new ResourceLocation("textures/entity/wither/wither.png");
	private int field_82419_a;
	private static final String __OBFID = "CL_00001034";

	public RenderWither()
	{
		super(new ModelWither(), 1.0F);
		this.field_82419_a = ((ModelWither)this.mainModel).func_82903_a();
	}

	public void doRender(EntityWither par1EntityWither, double par2, double par4, double par6, float par8, float par9)
	{
		BossStatus.setBossStatus(par1EntityWither, true);
		int i = ((ModelWither)this.mainModel).func_82903_a();

		if (i != this.field_82419_a)
		{
			this.field_82419_a = i;
			this.mainModel = new ModelWither();
		}

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

	protected ResourceLocation getEntityTexture(EntityWither par1EntityWither)
	{
		int i = par1EntityWither.func_82212_n();
		return i > 0 && (i > 80 || i / 5 % 2 != 1) ? invulnerableWitherTextures : witherTextures;
	}

	protected void preRenderCallback(EntityWither par1EntityWither, float par2)
	{
		int i = par1EntityWither.func_82212_n();

		if (i > 0)
		{
			float f1 = 2.0F - ((float)i - par2) / 220.0F * 0.5F;
			GL11.glScalef(f1, f1, f1);
		}
		else
		{
			GL11.glScalef(2.0F, 2.0F, 2.0F);
		}
	}

	protected int shouldRenderPass(EntityWither par1EntityWither, int par2, float par3)
	{
		if (par1EntityWither.isArmored())
		{
			if (par1EntityWither.isInvisible())
			{
				GL11.glDepthMask(false);
			}
			else
			{
				GL11.glDepthMask(true);
			}

			if (par2 == 1)
			{
				float f1 = (float)par1EntityWither.ticksExisted + par3;
				this.bindTexture(invulnerableWitherTextures);
				GL11.glMatrixMode(GL11.GL_TEXTURE);
				GL11.glLoadIdentity();
				float f2 = MathHelper.cos(f1 * 0.02F) * 3.0F;
				float f3 = f1 * 0.01F;
				GL11.glTranslatef(f2, f3, 0.0F);
				this.setRenderPassModel(this.mainModel);
				GL11.glMatrixMode(GL11.GL_MODELVIEW);
				GL11.glEnable(GL11.GL_BLEND);
				float f4 = 0.5F;
				GL11.glColor4f(f4, f4, f4, 1.0F);
				GL11.glDisable(GL11.GL_LIGHTING);
				GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
				GL11.glTranslatef(0.0F, -0.01F, 0.0F);
				GL11.glScalef(1.1F, 1.1F, 1.1F);
				return 1;
			}

			if (par2 == 2)
			{
				GL11.glMatrixMode(GL11.GL_TEXTURE);
				GL11.glLoadIdentity();
				GL11.glMatrixMode(GL11.GL_MODELVIEW);
				GL11.glEnable(GL11.GL_LIGHTING);
				GL11.glDisable(GL11.GL_BLEND);
			}
		}

		return -1;
	}

	protected int inheritRenderPass(EntityWither par1EntityWither, int par2, float par3)
	{
		return -1;
	}

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

	protected void preRenderCallback(EntityLivingBase par1EntityLivingBase, float par2)
	{
		this.preRenderCallback((EntityWither)par1EntityLivingBase, par2);
	}

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

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

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

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

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