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