    001package net.minecraft.client.particle;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.client.renderer.RenderEngine;
    006import net.minecraft.client.renderer.Tessellator;
    007import net.minecraft.entity.Entity;
    008import net.minecraft.nbt.NBTTagCompound;
    009import net.minecraft.util.Icon;
    010import net.minecraft.util.MathHelper;
    011import net.minecraft.world.World;
    012
    013@SideOnly(Side.CLIENT)
    014public class EntityFX extends Entity
    015{
    016    protected int field_94054_b;
    017    protected int field_94055_c;
    018    protected float particleTextureJitterX;
    019    protected float particleTextureJitterY;
    020    protected int particleAge;
    021    protected int particleMaxAge;
    022    protected float particleScale;
    023    protected float particleGravity;
    024
    025    /** The red amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0. */
    026    protected float particleRed;
    027
    028    /**
    029     * The green amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0.
    030     */
    031    protected float particleGreen;
    032
    033    /**
    034     * The blue amount of color. Used as a percentage, 1.0 = 255 and 0.0 = 0.
    035     */
    036    protected float particleBlue;
    037
    038    /** Particle alpha */
    039    protected float particleAlpha;
    040    protected Icon particleTextureIndex;
    041    public static double interpPosX;
    042    public static double interpPosY;
    043    public static double interpPosZ;
    044
    045    protected EntityFX(World par1World, double par2, double par4, double par6)
    046    {
    047        super(par1World);
    048        this.particleAge = 0;
    049        this.particleMaxAge = 0;
    050        this.particleAlpha = 1.0F;
    051        this.particleTextureIndex = null;
    052        this.setSize(0.2F, 0.2F);
    053        this.yOffset = this.height / 2.0F;
    054        this.setPosition(par2, par4, par6);
    055        this.lastTickPosX = par2;
    056        this.lastTickPosY = par4;
    057        this.lastTickPosZ = par6;
    058        this.particleRed = this.particleGreen = this.particleBlue = 1.0F;
    059        this.particleTextureJitterX = this.rand.nextFloat() * 3.0F;
    060        this.particleTextureJitterY = this.rand.nextFloat() * 3.0F;
    061        this.particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
    062        this.particleMaxAge = (int)(4.0F / (this.rand.nextFloat() * 0.9F + 0.1F));
    063        this.particleAge = 0;
    064    }
    065
    066    public EntityFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12)
    067    {
    068        this(par1World, par2, par4, par6);
    069        this.motionX = par8 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
    070        this.motionY = par10 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
    071        this.motionZ = par12 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
    072        float f = (float)(Math.random() + Math.random() + 1.0D) * 0.15F;
    073        float f1 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
    074        this.motionX = this.motionX / (double)f1 * (double)f * 0.4000000059604645D;
    075        this.motionY = this.motionY / (double)f1 * (double)f * 0.4000000059604645D + 0.10000000149011612D;
    076        this.motionZ = this.motionZ / (double)f1 * (double)f * 0.4000000059604645D;
    077    }
    078
    079    public EntityFX multiplyVelocity(float par1)
    080    {
    081        this.motionX *= (double)par1;
    082        this.motionY = (this.motionY - 0.10000000149011612D) * (double)par1 + 0.10000000149011612D;
    083        this.motionZ *= (double)par1;
    084        return this;
    085    }
    086
    087    public EntityFX multipleParticleScaleBy(float par1)
    088    {
    089        this.setSize(0.2F * par1, 0.2F * par1);
    090        this.particleScale *= par1;
    091        return this;
    092    }
    093
    094    public void setRBGColorF(float par1, float par2, float par3)
    095    {
    096        this.particleRed = par1;
    097        this.particleGreen = par2;
    098        this.particleBlue = par3;
    099    }
    100
    101    /**
    102     * Sets the particle alpha (float)
    103     */
    104    public void setAlphaF(float par1)
    105    {
    106        this.particleAlpha = par1;
    107    }
    108
    109    public float getRedColorF()
    110    {
    111        return this.particleRed;
    112    }
    113
    114    public float getGreenColorF()
    115    {
    116        return this.particleGreen;
    117    }
    118
    119    public float getBlueColorF()
    120    {
    121        return this.particleBlue;
    122    }
    123
    124    /**
    125     * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
    126     * prevent them from trampling crops
    127     */
    128    protected boolean canTriggerWalking()
    129    {
    130        return false;
    131    }
    132
    133    protected void entityInit() {}
    134
    135    /**
    136     * Called to update the entity's position/logic.
    137     */
    138    public void onUpdate()
    139    {
    140        this.prevPosX = this.posX;
    141        this.prevPosY = this.posY;
    142        this.prevPosZ = this.posZ;
    143
    144        if (this.particleAge++ >= this.particleMaxAge)
    145        {
    146            this.setDead();
    147        }
    148
    149        this.motionY -= 0.04D * (double)this.particleGravity;
    150        this.moveEntity(this.motionX, this.motionY, this.motionZ);
    151        this.motionX *= 0.9800000190734863D;
    152        this.motionY *= 0.9800000190734863D;
    153        this.motionZ *= 0.9800000190734863D;
    154
    155        if (this.onGround)
    156        {
    157            this.motionX *= 0.699999988079071D;
    158            this.motionZ *= 0.699999988079071D;
    159        }
    160    }
    161
    162    public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
    163    {
    164        float f6 = (float)this.field_94054_b / 16.0F;
    165        float f7 = f6 + 0.0624375F;
    166        float f8 = (float)this.field_94055_c / 16.0F;
    167        float f9 = f8 + 0.0624375F;
    168        float f10 = 0.1F * this.particleScale;
    169
    170        if (this.particleTextureIndex != null)
    171        {
    172            f6 = this.particleTextureIndex.func_94209_e();
    173            f7 = this.particleTextureIndex.func_94212_f();
    174            f8 = this.particleTextureIndex.func_94206_g();
    175            f9 = this.particleTextureIndex.func_94210_h();
    176        }
    177
    178        float f11 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX);
    179        float f12 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY);
    180        float f13 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ);
    181        float f14 = 1.0F;
    182        par1Tessellator.setColorRGBA_F(this.particleRed * f14, this.particleGreen * f14, this.particleBlue * f14, this.particleAlpha);
    183        par1Tessellator.addVertexWithUV((double)(f11 - par3 * f10 - par6 * f10), (double)(f12 - par4 * f10), (double)(f13 - par5 * f10 - par7 * f10), (double)f7, (double)f9);
    184        par1Tessellator.addVertexWithUV((double)(f11 - par3 * f10 + par6 * f10), (double)(f12 + par4 * f10), (double)(f13 - par5 * f10 + par7 * f10), (double)f7, (double)f8);
    185        par1Tessellator.addVertexWithUV((double)(f11 + par3 * f10 + par6 * f10), (double)(f12 + par4 * f10), (double)(f13 + par5 * f10 + par7 * f10), (double)f6, (double)f8);
    186        par1Tessellator.addVertexWithUV((double)(f11 + par3 * f10 - par6 * f10), (double)(f12 - par4 * f10), (double)(f13 + par5 * f10 - par7 * f10), (double)f6, (double)f9);
    187    }
    188
    189    public int getFXLayer()
    190    {
    191        return 0;
    192    }
    193
    194    /**
    195     * (abstract) Protected helper method to write subclass entity data to NBT.
    196     */
    197    public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
    198
    199    /**
    200     * (abstract) Protected helper method to read subclass entity data from NBT.
    201     */
    202    public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
    203
    204    public void func_94052_a(RenderEngine par1RenderEngine, Icon par2Icon)
    205    {
    206        if (this.getFXLayer() == 1)
    207        {
    208            this.particleTextureIndex = par2Icon;
    209        }
    210        else
    211        {
    212            if (this.getFXLayer() != 2)
    213            {
    214                throw new RuntimeException("Invalid call to Particle.setTex, use coordinate methods");
    215            }
    216
    217            this.particleTextureIndex = par2Icon;
    218        }
    219    }
    220
    221    /**
    222     * Public method to set private field particleTextureIndex.
    223     */
    224    public void setParticleTextureIndex(int par1)
    225    {
    226        if (this.getFXLayer() != 0)
    227        {
    228            throw new RuntimeException("Invalid call to Particle.setMiscTex");
    229        }
    230        else
    231        {
    232            this.field_94054_b = par1 % 16;
    233            this.field_94055_c = par1 / 16;
    234        }
    235    }
    236
    237    public void func_94053_h()
    238    {
    239        ++this.field_94054_b;
    240    }
    241
    242    /**
    243     * If returns false, the item will not inflict any damage against entities.
    244     */
    245    public boolean canAttackWithItem()
    246    {
    247        return false;
    248    }
    249
    250    public String toString()
    251    {
    252        return this.getClass().getSimpleName() + ", Pos (" + this.posX + "," + this.posY + "," + this.posZ + "), RGBA (" + this.particleRed + "," + this.particleGreen + "," + this.particleBlue + "," + this.particleAlpha + "), Age " + this.particleAge;
    253    }
    254}