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