    001package net.minecraft.client.particle;
    002
    003import cpw.mods.fml.relauncher.Side;
    004import cpw.mods.fml.relauncher.SideOnly;
    005import net.minecraft.block.BlockFluid;
    006import net.minecraft.block.material.Material;
    007import net.minecraft.util.MathHelper;
    008import net.minecraft.world.World;
    009
    010@SideOnly(Side.CLIENT)
    011public class EntityDropParticleFX extends EntityFX
    012{
    013    /** the material type for dropped items/blocks */
    014    private Material materialType;
    015
    016    /** The height of the current bob */
    017    private int bobTimer;
    018
    019    public EntityDropParticleFX(World par1World, double par2, double par4, double par6, Material par8Material)
    020    {
    021        super(par1World, par2, par4, par6, 0.0D, 0.0D, 0.0D);
    022        this.motionX = this.motionY = this.motionZ = 0.0D;
    023
    024        if (par8Material == Material.water)
    025        {
    026            this.particleRed = 0.0F;
    027            this.particleGreen = 0.0F;
    028            this.particleBlue = 1.0F;
    029        }
    030        else
    031        {
    032            this.particleRed = 1.0F;
    033            this.particleGreen = 0.0F;
    034            this.particleBlue = 0.0F;
    035        }
    036
    037        this.setParticleTextureIndex(113);
    038        this.setSize(0.01F, 0.01F);
    039        this.particleGravity = 0.06F;
    040        this.materialType = par8Material;
    041        this.bobTimer = 40;
    042        this.particleMaxAge = (int)(64.0D / (Math.random() * 0.8D + 0.2D));
    043        this.motionX = this.motionY = this.motionZ = 0.0D;
    044    }
    045
    046    public int getBrightnessForRender(float par1)
    047    {
    048        return this.materialType == Material.water ? super.getBrightnessForRender(par1) : 257;
    049    }
    050
    051    /**
    052     * Gets how bright this entity is.
    053     */
    054    public float getBrightness(float par1)
    055    {
    056        return this.materialType == Material.water ? super.getBrightness(par1) : 1.0F;
    057    }
    058
    059    /**
    060     * Called to update the entity's position/logic.
    061     */
    062    public void onUpdate()
    063    {
    064        this.prevPosX = this.posX;
    065        this.prevPosY = this.posY;
    066        this.prevPosZ = this.posZ;
    067
    068        if (this.materialType == Material.water)
    069        {
    070            this.particleRed = 0.2F;
    071            this.particleGreen = 0.3F;
    072            this.particleBlue = 1.0F;
    073        }
    074        else
    075        {
    076            this.particleRed = 1.0F;
    077            this.particleGreen = 16.0F / (float)(40 - this.bobTimer + 16);
    078            this.particleBlue = 4.0F / (float)(40 - this.bobTimer + 8);
    079        }
    080
    081        this.motionY -= (double)this.particleGravity;
    082
    083        if (this.bobTimer-- > 0)
    084        {
    085            this.motionX *= 0.02D;
    086            this.motionY *= 0.02D;
    087            this.motionZ *= 0.02D;
    088            this.setParticleTextureIndex(113);
    089        }
    090        else
    091        {
    092            this.setParticleTextureIndex(112);
    093        }
    094
    095        this.moveEntity(this.motionX, this.motionY, this.motionZ);
    096        this.motionX *= 0.9800000190734863D;
    097        this.motionY *= 0.9800000190734863D;
    098        this.motionZ *= 0.9800000190734863D;
    099
    100        if (this.particleMaxAge-- <= 0)
    101        {
    102            this.setDead();
    103        }
    104
    105        if (this.onGround)
    106        {
    107            if (this.materialType == Material.water)
    108            {
    109                this.setDead();
    110                this.worldObj.spawnParticle("splash", this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D);
    111            }
    112            else
    113            {
    114                this.setParticleTextureIndex(114);
    115            }
    116
    117            this.motionX *= 0.699999988079071D;
    118            this.motionZ *= 0.699999988079071D;
    119        }
    120
    121        Material material = this.worldObj.getBlockMaterial(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ));
    122
    123        if (material.isLiquid() || material.isSolid())
    124        {
    125            double d0 = (double)((float)(MathHelper.floor_double(this.posY) + 1) - BlockFluid.getFluidHeightPercent(this.worldObj.getBlockMetadata(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ))));
    126
    127            if (this.posY < d0)
    128            {
    129                this.setDead();
    130            }
    131        }
    132    }
    133}