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 public static double interpPosX;
030 public static double interpPosY;
031 public static double interpPosZ;
032
033 public EntityFX(World par1World, double par2, double par4, double par6, double par8, double par10, double par12)
034 {
035 super(par1World);
036 this.setSize(0.2F, 0.2F);
037 this.yOffset = this.height / 2.0F;
038 this.setPosition(par2, par4, par6);
039 this.particleRed = this.particleGreen = this.particleBlue = 1.0F;
040 this.motionX = par8 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
041 this.motionY = par10 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
042 this.motionZ = par12 + (double)((float)(Math.random() * 2.0D - 1.0D) * 0.4F);
043 float var14 = (float)(Math.random() + Math.random() + 1.0D) * 0.15F;
044 float var15 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionY * this.motionY + this.motionZ * this.motionZ);
045 this.motionX = this.motionX / (double)var15 * (double)var14 * 0.4000000059604645D;
046 this.motionY = this.motionY / (double)var15 * (double)var14 * 0.4000000059604645D + 0.10000000149011612D;
047 this.motionZ = this.motionZ / (double)var15 * (double)var14 * 0.4000000059604645D;
048 this.particleTextureJitterX = this.rand.nextFloat() * 3.0F;
049 this.particleTextureJitterY = this.rand.nextFloat() * 3.0F;
050 this.particleScale = (this.rand.nextFloat() * 0.5F + 0.5F) * 2.0F;
051 this.particleMaxAge = (int)(4.0F / (this.rand.nextFloat() * 0.9F + 0.1F));
052 this.particleAge = 0;
053 }
054
055 public EntityFX multiplyVelocity(float par1)
056 {
057 this.motionX *= (double)par1;
058 this.motionY = (this.motionY - 0.10000000149011612D) * (double)par1 + 0.10000000149011612D;
059 this.motionZ *= (double)par1;
060 return this;
061 }
062
063 public EntityFX multipleParticleScaleBy(float par1)
064 {
065 this.setSize(0.2F * par1, 0.2F * par1);
066 this.particleScale *= par1;
067 return this;
068 }
069
070 public void setRBGColorF(float par1, float par2, float par3)
071 {
072 this.particleRed = par1;
073 this.particleGreen = par2;
074 this.particleBlue = par3;
075 }
076
077 public float getRedColorF()
078 {
079 return this.particleRed;
080 }
081
082 public float getGreenColorF()
083 {
084 return this.particleGreen;
085 }
086
087 public float getBlueColorF()
088 {
089 return this.particleBlue;
090 }
091
092 /**
093 * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to
094 * prevent them from trampling crops
095 */
096 protected boolean canTriggerWalking()
097 {
098 return false;
099 }
100
101 protected void entityInit() {}
102
103 /**
104 * Called to update the entity's position/logic.
105 */
106 public void onUpdate()
107 {
108 this.prevPosX = this.posX;
109 this.prevPosY = this.posY;
110 this.prevPosZ = this.posZ;
111
112 if (this.particleAge++ >= this.particleMaxAge)
113 {
114 this.setDead();
115 }
116
117 this.motionY -= 0.04D * (double)this.particleGravity;
118 this.moveEntity(this.motionX, this.motionY, this.motionZ);
119 this.motionX *= 0.9800000190734863D;
120 this.motionY *= 0.9800000190734863D;
121 this.motionZ *= 0.9800000190734863D;
122
123 if (this.onGround)
124 {
125 this.motionX *= 0.699999988079071D;
126 this.motionZ *= 0.699999988079071D;
127 }
128 }
129
130 public void renderParticle(Tessellator par1Tessellator, float par2, float par3, float par4, float par5, float par6, float par7)
131 {
132 float var8 = (float)(this.particleTextureIndex % 16) / 16.0F;
133 float var9 = var8 + 0.0624375F;
134 float var10 = (float)(this.particleTextureIndex / 16) / 16.0F;
135 float var11 = var10 + 0.0624375F;
136 float var12 = 0.1F * this.particleScale;
137 float var13 = (float)(this.prevPosX + (this.posX - this.prevPosX) * (double)par2 - interpPosX);
138 float var14 = (float)(this.prevPosY + (this.posY - this.prevPosY) * (double)par2 - interpPosY);
139 float var15 = (float)(this.prevPosZ + (this.posZ - this.prevPosZ) * (double)par2 - interpPosZ);
140 float var16 = 1.0F;
141 par1Tessellator.setColorOpaque_F(this.particleRed * var16, this.particleGreen * var16, this.particleBlue * var16);
142 par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 - par5 * var12 - par7 * var12), (double)var9, (double)var11);
143 par1Tessellator.addVertexWithUV((double)(var13 - par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 - par5 * var12 + par7 * var12), (double)var9, (double)var10);
144 par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 + par6 * var12), (double)(var14 + par4 * var12), (double)(var15 + par5 * var12 + par7 * var12), (double)var8, (double)var10);
145 par1Tessellator.addVertexWithUV((double)(var13 + par3 * var12 - par6 * var12), (double)(var14 - par4 * var12), (double)(var15 + par5 * var12 - par7 * var12), (double)var8, (double)var11);
146 }
147
148 public int getFXLayer()
149 {
150 return 0;
151 }
152
153 /**
154 * (abstract) Protected helper method to write subclass entity data to NBT.
155 */
156 public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) {}
157
158 /**
159 * (abstract) Protected helper method to read subclass entity data from NBT.
160 */
161 public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) {}
162
163 /**
164 * Public method to set private field particleTextureIndex.
165 */
166 public void setParticleTextureIndex(int par1)
167 {
168 this.particleTextureIndex = par1;
169 }
170
171 public int getParticleTextureIndex()
172 {
173 return this.particleTextureIndex;
174 }
175
176 /**
177 * If returns false, the item will not inflict any damage against entities.
178 */
179 public boolean canAttackWithItem()
180 {
181 return false;
182 }
183 }