    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.entity.Entity;
    007import net.minecraft.nbt.NBTTagCompound;
    008import net.minecraft.util.MathHelper;
    009import net.minecraft.world.World;
    010
    011@SideOnly(Side.CLIENT)
    012public class EntityFX extends Entity
    013{
    014    private int particleTextureIndex;
    015    protected float particleTextureJitterX;
    016    protected float particleTextureJitterY;
    017    protected int particleAge;
    018    protected int particleMaxAge;
    019    protected float particleScale;
    020    protected float particleGravity;
    021
    022    /** The red amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0. */
    023    protected float particleRed;
    024
    025    /**
    026     * The green amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0.
    027     */
    028    protected float particleGreen;
    029
    030    /**
    031     * The blue amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0.
    032     */
    033    protected float particleBlue;
    034
    035    /** Particle alpha */
    036    protected float particleAlpha;
    037    public static double interpPosX;
    038    public static double interpPosY;
    039    public static double interpPosZ;
    040
    041    protected EntityFX(World par1World, double par2, double par4, double par6)
    042    {
    043        super(par1World);
    044        this.particleAge = 0;
    045        this.particleMaxAge = 0;
    046        this.particleAlpha = 1.0F;
    047        this.setSize(0.2F, 0.2F);
    048        this.yOffset = this.height / 2.0F;
    049        this.setPosition(par2, par4, par6);
    050        this.lastTickPosX = par2;
    051        this.lastTickPosY = par4;
    052        this.lastTickPosZ = par6;
    053        this.particleRed = this.particleGreen = this.particleBlue = 1.0F;
    054        this.particleTextureJitterX = this.rand.nextFloat() * 3.0F;
    055        this.particleTextureJitterY = this.rand.nextFloat() * 3.0F;
    056        this.particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
    057        this.particleMaxAge = (int)(4.0F / (this.rand.nextFloat() * 0.9F + 0.1F));
    058        this.particleAge = 0;
    059    }
    060
    061    public EntityFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12)
    062    {
    063        this(par1World, par2, par4, par6);
    064        this.motionX = par8 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
    065        this.motionY = par10 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
    066        this.motionZ = par12 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
    067        float var14 = (float)(Math.random() + Math.random() + 1.0D) * 0.15F;
    068        float var15 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
    069        this.motionX = this.motionX / (double)var15 * (double)var14 * 0.4000000059604645D;
    070        this.motionY = this.motionY / (double)var15 * (double)var14 * 0.4000000059604645D + 0.10000000149011612D;
    071        this.motionZ = this.motionZ / (double)var15 * (double)var14 * 0.4000000059604645D;
    072    }
    073
    074    public EntityFX multiplyVelocity(float par1)
    075    {
    076        this.motionX *= (double)par1;
    077        this.motionY = (this.motionY - 0.10000000149011612D) * (double)par1 + 0.10000000149011612D;
    078        this.motionZ *= (double)par1;
    079        return this;
    080    }
    081
    082    public EntityFX multipleParticleScaleBy(float par1)
    083    {
    084        this.setSize(0.2F * par1, 0.2F * par1);
    085        this.particleScale *= par1;
    086        return this;
    087    }
    088
    089    public void setRBGColorF(float par1, float par2, float par3)
    090    {
    091        this.particleRed = par1;
    092        this.particleGreen = par2;
    093        this.particleBlue = par3;
    094    }
    095
    096    /**
    097     * Sets the particle alpha (float)
    098     */
    099    public void setAlphaF(float par1)
    100    {
    101        this.particleAlpha = par1;
    102    }
    103
    104    public float getRedColorF()
    105    {
    106        return this.particleRed;
    107    }
    108
    109    public float getGreenColorF()
    110    {
    111        return this.particleGreen;
    112    }
    113
    114    public float getBlueColorF()
    115    {
    116        return this.particleBlue;
    117    }
    118
    119    /**
    120     * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
    121     * prevent them from trampling crops
    122     */
    123    protected boolean canTriggerWalking()
    124    {
    125        return false;
    126    }
    127
    128    protected void entityInit() {}
    129
    130    /**
    131     * Called to update the entity's position/logic.
    132     */
    133    public void onUpdate()
    134    {
    135        this.prevPosX = this.posX;
    136        this.prevPosY = this.posY;
    137        this.prevPosZ = this.posZ;
    138
    139        if (this.particleAge++ >= this.particleMaxAge)
    140        {
    141            this.setDead();
    142        }
    143
    144        this.motionY -= 0.04D * (double)this.particleGravity;
    145        this.moveEntity(this.motionX, this.motionY, this.motionZ);
    146        this.motionX *= 0.9800000190734863D;
    147        this.motionY *= 0.9800000190734863D;
    148        this.motionZ *= 0.9800000190734863D;
    149
    150        if (this.onGround)
    151        {
    152            this.motionX *= 0.699999988079071D;
    153            this.motionZ *= 0.699999988079071D;
    154        }
    155    }
    156
    157    public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
    158    {
    159        float var8 = (float)(this.particleTextureIndex % 16) / 16.0F;
    160        float var9 = var8 + 0.0624375F;
    161        float var10 = (float)(this.particleTextureIndex / 16) / 16.0F;
    162        float var11 = var10 + 0.0624375F;
    163        float var12 = 0.1F * this.particleScale;
    164        float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX);
    165        float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY);
    166        float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ);
    167        float var16 = 1.0F;
    168        par1Tessellator.setColorRGBA_F(this.particleRed * var16, this.particleGreen * var16, this.particleBlue * var16, this.particleAlpha);
    169        par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 - par5 * var12 - par7 * var12), (double)var9, (double)var11);
    170        par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 - par5 * var12 + par7 * var12), (double)var9, (double)var10);
    171        par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 + par5 * var12 + par7 * var12), (double)var8, (double)var10);
    172        par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 + par5 * var12 - par7 * var12), (double)var8, (double)var11);
    173    }
    174
    175    public int getFXLayer()
    176    {
    177        return 0;
    178    }
    179
    180    /**
    181     * (abstract) Protected helper method to write subclass entity data to NBT.
    182     */
    183    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
    184
    185    /**
    186     * (abstract) Protected helper method to read subclass entity data from NBT.
    187     */
    188    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
    189
    190    /**
    191     * Public method to set private field particleTextureIndex.
    192     */
    193    public void setParticleTextureIndex(int par1)
    194    {
    195        this.particleTextureIndex = par1;
    196    }
    197
    198    public int getParticleTextureIndex()
    199    {
    200        return this.particleTextureIndex;
    201    }
    202
    203    /**
    204     * If returns false, the item will not inflict any damage against entities.
    205     */
    206    public boolean canAttackWithItem()
    207    {
    208        return false;
    209    }
    210
    211    public String toString()
    212    {
    213        return this.getClass().getSimpleName() + ", Pos (" + this.posX + "," + this.posY + "," + this.posZ + "), RGBA (" + this.particleRed + "," + this.particleGreen + "," + this.particleBlue + "," + this.particleAlpha + "), Age " + this.particleAge;
    214    }
    215}