001package net.minecraft.client.particle;
002
003import cpw.mods.fml.relauncher.Side;
004import cpw.mods.fml.relauncher.SideOnly;
005import net.minecraft.client.renderer.Tessellator;
006import net.minecraft.world.World;
007
008@SideOnly(Side.CLIENT)
009public class EntityPortalFX extends EntityFX
010{
011    private float portalParticleScale;
012    private double portalPosX;
013    private double portalPosY;
014    private double portalPosZ;
015
016    public EntityPortalFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12)
017    {
018        super(par1World, par2, par4, par6, par8, par10, par12);
019        this.motionX = par8;
020        this.motionY = par10;
021        this.motionZ = par12;
022        this.portalPosX = this.posX = par2;
023        this.portalPosY = this.posY = par4;
024        this.portalPosZ = this.posZ = par6;
025        float f = this.rand.nextFloat() * 0.6F + 0.4F;
026        this.portalParticleScale = this.particleScale = this.rand.nextFloat() * 0.2F + 0.5F;
027        this.particleRed = this.particleGreen = this.particleBlue = 1.0F * f;
028        this.particleGreen *= 0.3F;
029        this.particleRed *= 0.9F;
030        this.particleMaxAge = (int)(Math.random() * 10.0D) + 40;
031        this.noClip = true;
032        this.setParticleTextureIndex((int)(Math.random() * 8.0D));
033    }
034
035    public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
036    {
037        float f6 = ((float)this.particleAge + par2) / (float)this.particleMaxAge;
038        f6 = 1.0F - f6;
039        f6 *= f6;
040        f6 = 1.0F - f6;
041        this.particleScale = this.portalParticleScale * f6;
042        super.renderParticle(par1Tessellator, par2, par3, par4, par5, par6, par7);
043    }
044
045    public int getBrightnessForRender(float par1)
046    {
047        int i = super.getBrightnessForRender(par1);
048        float f1 = (float)this.particleAge / (float)this.particleMaxAge;
049        f1 *= f1;
050        f1 *= f1;
051        int j = i & 255;
052        int k = i >> 16 & 255;
053        k += (int)(f1 * 15.0F * 16.0F);
054
055        if (k > 240)
056        {
057            k = 240;
058        }
059
060        return j | k << 16;
061    }
062
063    /**
064     * Gets how bright this entity is.
065     */
066    public float getBrightness(float par1)
067    {
068        float f1 = super.getBrightness(par1);
069        float f2 = (float)this.particleAge / (float)this.particleMaxAge;
070        f2 = f2 * f2 * f2 * f2;
071        return f1 * (1.0F - f2) + f2;
072    }
073
074    /**
075     * Called to update the entity's position/logic.
076     */
077    public void onUpdate()
078    {
079        this.prevPosX = this.posX;
080        this.prevPosY = this.posY;
081        this.prevPosZ = this.posZ;
082        float f = (float)this.particleAge / (float)this.particleMaxAge;
083        float f1 = f;
084        f = -f + f * f * 2.0F;
085        f = 1.0F - f;
086        this.posX = this.portalPosX + this.motionX * (double)f;
087        this.posY = this.portalPosY + this.motionY * (double)f + (double)(1.0F - f1);
088        this.posZ = this.portalPosZ + this.motionZ * (double)f;
089
090        if (this.particleAge++ >= this.particleMaxAge)
091        {
092            this.setDead();
093        }
094    }
095}