package net.minecraft.entity.projectile; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import java.util.Iterator; import java.util.List; import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MovingObjectPosition; import net.minecraft.world.World; public class EntityPotion extends EntityThrowable { /** The damage value of the thrown potion that this EntityPotion represents. */ private ItemStack potionDamage; private static final String __OBFID = "CL_00001727"; public EntityPotion(World p_i1788_1_) { super(p_i1788_1_); } public EntityPotion(World p_i1789_1_, EntityLivingBase p_i1789_2_, int p_i1789_3_) { this(p_i1789_1_, p_i1789_2_, new ItemStack(Items.potionitem, 1, p_i1789_3_)); } public EntityPotion(World p_i1790_1_, EntityLivingBase p_i1790_2_, ItemStack p_i1790_3_) { super(p_i1790_1_, p_i1790_2_); this.potionDamage = p_i1790_3_; } @SideOnly(Side.CLIENT) public EntityPotion(World p_i1791_1_, double p_i1791_2_, double p_i1791_4_, double p_i1791_6_, int p_i1791_8_) { this(p_i1791_1_, p_i1791_2_, p_i1791_4_, p_i1791_6_, new ItemStack(Items.potionitem, 1, p_i1791_8_)); } public EntityPotion(World p_i1792_1_, double p_i1792_2_, double p_i1792_4_, double p_i1792_6_, ItemStack p_i1792_8_) { super(p_i1792_1_, p_i1792_2_, p_i1792_4_, p_i1792_6_); this.potionDamage = p_i1792_8_; } /** * Gets the amount of gravity to apply to the thrown entity with each tick. */ protected float getGravityVelocity() { return 0.05F; } protected float func_70182_d() { return 0.5F; } protected float func_70183_g() { return -20.0F; } public void setPotionDamage(int p_82340_1_) { if (this.potionDamage == null) { this.potionDamage = new ItemStack(Items.potionitem, 1, 0); } this.potionDamage.setMetadata(p_82340_1_); } /** * Returns the damage value of the thrown potion that this EntityPotion represents. */ public int getPotionDamage() { if (this.potionDamage == null) { this.potionDamage = new ItemStack(Items.potionitem, 1, 0); } return this.potionDamage.getMetadata(); } /** * Called when this EntityThrowable hits a block or entity. */ protected void onImpact(MovingObjectPosition p_70184_1_) { if (!this.worldObj.isRemote) { List list = Items.potionitem.getEffects(this.potionDamage); if (list != null && !list.isEmpty()) { AxisAlignedBB axisalignedbb = this.boundingBox.expand(4.0D, 2.0D, 4.0D); List list1 = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb); if (list1 != null && !list1.isEmpty()) { Iterator iterator = list1.iterator(); while (iterator.hasNext()) { EntityLivingBase entitylivingbase = (EntityLivingBase)iterator.next(); double d0 = this.getDistanceSqToEntity(entitylivingbase); if (d0 < 16.0D) { double d1 = 1.0D - Math.sqrt(d0) / 4.0D; if (entitylivingbase == p_70184_1_.entityHit) { d1 = 1.0D; } Iterator iterator1 = list.iterator(); while (iterator1.hasNext()) { PotionEffect potioneffect = (PotionEffect)iterator1.next(); int i = potioneffect.getPotionID(); if (Potion.potionTypes[i].isInstant()) { Potion.potionTypes[i].affectEntity(this.getThrower(), entitylivingbase, potioneffect.getAmplifier(), d1); } else { int j = (int)(d1 * (double)potioneffect.getDuration() + 0.5D); if (j > 20) { entitylivingbase.addPotionEffect(new PotionEffect(i, j, potioneffect.getAmplifier())); } } } } } } } this.worldObj.playAuxSFX(2002, (int)Math.round(this.posX), (int)Math.round(this.posY), (int)Math.round(this.posZ), this.getPotionDamage()); this.setDead(); } } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound tagCompund) { super.readEntityFromNBT(tagCompund); if (tagCompund.hasKey("Potion", 10)) { this.potionDamage = ItemStack.loadItemStackFromNBT(tagCompund.getCompoundTag("Potion")); } else { this.setPotionDamage(tagCompund.getInteger("potionValue")); } if (this.potionDamage == null) { this.setDead(); } } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ public void writeEntityToNBT(NBTTagCompound tagCompound) { super.writeEntityToNBT(tagCompound); if (this.potionDamage != null) { tagCompound.setTag("Potion", this.potionDamage.writeToNBT(new NBTTagCompound())); } } }