package net.minecraft.client.particle;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;

@SideOnly(Side.CLIENT)
public class EntityLargeExplodeFX extends EntityFX
{
	private static final ResourceLocation field_110127_a = new ResourceLocation("textures/entity/explosion.png");
	private int field_70581_a;
	private int field_70584_aq;
	private TextureManager theRenderEngine;
	private float field_70582_as;
	private static final String __OBFID = "CL_00000910";

	public EntityLargeExplodeFX(TextureManager par1TextureManager, World par2World, double par3, double par5, double par7, double par9, double par11, double par13)
	{
		super(par2World, par3, par5, par7, 0.0D, 0.0D, 0.0D);
		this.theRenderEngine = par1TextureManager;
		this.field_70584_aq = 6 + this.rand.nextInt(4);
		this.particleRed = this.particleGreen = this.particleBlue = this.rand.nextFloat() * 0.6F + 0.4F;
		this.field_70582_as = 1.0F - (float)par9 * 0.5F;
	}

	public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
	{
		int i = (int)(((float)this.field_70581_a + par2) * 15.0F / (float)this.field_70584_aq);

		if (i <= 15)
		{
			this.theRenderEngine.bindTexture(field_110127_a);
			float f6 = (float)(i % 4) / 4.0F;
			float f7 = f6 + 0.24975F;
			float f8 = (float)(i / 4) / 4.0F;
			float f9 = f8 + 0.24975F;
			float f10 = 2.0F * this.field_70582_as;
			float f11 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX);
			float f12 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY);
			float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ);
			GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
			GL11.glDisable(GL11.GL_LIGHTING);
			RenderHelper.disableStandardItemLighting();
			par1Tessellator.startDrawingQuads();
			par1Tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, 1.0F);
			par1Tessellator.setNormal(0.0F, 1.0F, 0.0F);
			par1Tessellator.setBrightness(240);
			par1Tessellator.addVertexWithUV((double)(f11 - par3 * f10 - par6 * f10), (double)(f12 - par4 * f10), (double)(f13 - par5 * f10 - par7 * f10), (double)f7, (double)f9);
			par1Tessellator.addVertexWithUV((double)(f11 - par3 * f10 + par6 * f10), (double)(f12 + par4 * f10), (double)(f13 - par5 * f10 + par7 * f10), (double)f7, (double)f8);
			par1Tessellator.addVertexWithUV((double)(f11 + par3 * f10 + par6 * f10), (double)(f12 + par4 * f10), (double)(f13 + par5 * f10 + par7 * f10), (double)f6, (double)f8);
			par1Tessellator.addVertexWithUV((double)(f11 + par3 * f10 - par6 * f10), (double)(f12 - par4 * f10), (double)(f13 + par5 * f10 - par7 * f10), (double)f6, (double)f9);
			par1Tessellator.draw();
			GL11.glPolygonOffset(0.0F, 0.0F);
			GL11.glEnable(GL11.GL_LIGHTING);
		}
	}

	public int getBrightnessForRender(float par1)
	{
		return 61680;
	}

	public void onUpdate()
	{
		this.prevPosX = this.posX;
		this.prevPosY = this.posY;
		this.prevPosZ = this.posZ;
		++this.field_70581_a;

		if (this.field_70581_a == this.field_70584_aq)
		{
			this.setDead();
		}
	}

	public int getFXLayer()
	{
		return 3;
	}
}