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