    001    package net.minecraft.src;
    002
    003    import java.util.Iterator;
    004    import java.util.List;
    005
    006    public class EntityPotion extends EntityThrowable
    007    {
    008        /**
    009         * The damage value of the thrown potion that this EntityPotion represents.
    010         */
    011        private int potionDamage;
    012
    013        public EntityPotion(World par1World)
    014        {
    015            super(par1World);
    016        }
    017
    018        public EntityPotion(World par1World, EntityLiving par2EntityLiving, int par3)
    019        {
    020            super(par1World, par2EntityLiving);
    021            this.potionDamage = par3;
    022        }
    023
    024        public EntityPotion(World par1World, double par2, double par4, double par6, int par8)
    025        {
    026            super(par1World, par2, par4, par6);
    027            this.potionDamage = par8;
    028        }
    029
    030        /**
    031         * Gets the amount of gravity to apply to the thrown entity with each tick.
    032         */
    033        protected float getGravityVelocity()
    034        {
    035            return 0.05F;
    036        }
    037
    038        protected float func_70182_d()
    039        {
    040            return 0.5F;
    041        }
    042
    043        protected float func_70183_g()
    044        {
    045            return -20.0F;
    046        }
    047
    048        /**
    049         * Returns the damage value of the thrown potion that this EntityPotion represents.
    050         */
    051        public int getPotionDamage()
    052        {
    053            return this.potionDamage;
    054        }
    055
    056        /**
    057         * Called when this EntityThrowable hits a block or entity.
    058         */
    059        protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
    060        {
    061            if (!this.worldObj.isRemote)
    062            {
    063                List var2 = Item.potion.getEffects(this.potionDamage);
    064
    065                if (var2 != null && !var2.isEmpty())
    066                {
    067                    AxisAlignedBB var3 = this.boundingBox.expand(4.0D, 2.0D, 4.0D);
    068                    List var4 = this.worldObj.getEntitiesWithinAABB(EntityLiving.class, var3);
    069
    070                    if (var4 != null && !var4.isEmpty())
    071                    {
    072                        Iterator var5 = var4.iterator();
    073
    074                        while (var5.hasNext())
    075                        {
    076                            EntityLiving var6 = (EntityLiving)var5.next();
    077                            double var7 = this.getDistanceSqToEntity(var6);
    078
    079                            if (var7 < 16.0D)
    080                            {
    081                                double var9 = 1.0D - Math.sqrt(var7) / 4.0D;
    082
    083                                if (var6 == par1MovingObjectPosition.entityHit)
    084                                {
    085                                    var9 = 1.0D;
    086                                }
    087
    088                                Iterator var11 = var2.iterator();
    089
    090                                while (var11.hasNext())
    091                                {
    092                                    PotionEffect var12 = (PotionEffect)var11.next();
    093                                    int var13 = var12.getPotionID();
    094
    095                                    if (Potion.potionTypes[var13].isInstant())
    096                                    {
    097                                        Potion.potionTypes[var13].affectEntity(this.thrower, var6, var12.getAmplifier(), var9);
    098                                    }
    099                                    else
    100                                    {
    101                                        int var14 = (int)(var9 * (double)var12.getDuration() + 0.5D);
    102
    103                                        if (var14 > 20)
    104                                        {
    105                                            var6.addPotionEffect(new PotionEffect(var13, var14, var12.getAmplifier()));
    106                                        }
    107                                    }
    108                                }
    109                            }
    110                        }
    111                    }
    112                }
    113
    114                this.worldObj.playAuxSFX(2002, (int)Math.round(this.posX), (int)Math.round(this.posY), (int)Math.round(this.posZ), this.potionDamage);
    115                this.setDead();
    116            }
    117        }
    118
    119        /**
    120         * (abstract) Protected helper method to read subclass entity data from NBT.
    121         */
    122        public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound)
    123        {
    124            super.readEntityFromNBT(par1NBTTagCompound);
    125            this.potionDamage = par1NBTTagCompound.getInteger("potionValue");
    126        }
    127
    128        /**
    129         * (abstract) Protected helper method to write subclass entity data to NBT.
    130         */
    131        public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound)
    132        {
    133            super.writeEntityToNBT(par1NBTTagCompound);
    134            par1NBTTagCompound.setInteger("potionValue", this.potionDamage);
    135        }
    136    }