    001    package net.minecraft.src;
    002
    003    import java.util.ArrayList;
    004    import java.util.List;
    005
    006    public class PotionEffect
    007    {
    008        /** ID value of the potion this effect matches. */
    009        private int potionID;
    010
    011        /** The duration of the potion effect */
    012        private int duration;
    013
    014        /** The amplifier of the potion effect */
    015        private int amplifier;
    016        private boolean field_82723_d;
    017        private boolean field_82724_e;
    018
    019        /** List of ItemStack that can cure the potion effect **/
    020        private List<ItemStack> curativeItems;
    021
    022        public PotionEffect(int par1, int par2)
    023        {
    024            this(par1, par2, 0);
    025        }
    026
    027        public PotionEffect(int par1, int par2, int par3)
    028        {
    029            this(par1, par2, par3, false);
    030        }
    031
    032        public PotionEffect(int par1, int par2, int par3, boolean par4)
    033        {
    034            this.potionID = par1;
    035            this.duration = par2;
    036            this.amplifier = par3;
    037            this.field_82724_e = par4;
    038            this.curativeItems = new ArrayList<ItemStack>();
    039            this.curativeItems.add(new ItemStack(Item.bucketMilk));
    040        }
    041
    042        public PotionEffect(PotionEffect par1PotionEffect)
    043        {
    044            this.potionID = par1PotionEffect.potionID;
    045            this.duration = par1PotionEffect.duration;
    046            this.amplifier = par1PotionEffect.amplifier;
    047            this.curativeItems = par1PotionEffect.getCurativeItems();
    048        }
    049
    050        /**
    051         * merges the input PotionEffect into this one if this.amplifier <= tomerge.amplifier. The duration in the supplied
    052         * potion effect is assumed to be greater.
    053         */
    054        public void combine(PotionEffect par1PotionEffect)
    055        {
    056            if (this.potionID != par1PotionEffect.potionID)
    057            {
    058                System.err.println("This method should only be called for matching effects!");
    059            }
    060
    061            if (par1PotionEffect.amplifier > this.amplifier)
    062            {
    063                this.amplifier = par1PotionEffect.amplifier;
    064                this.duration = par1PotionEffect.duration;
    065            }
    066            else if (par1PotionEffect.amplifier == this.amplifier && this.duration < par1PotionEffect.duration)
    067            {
    068                this.duration = par1PotionEffect.duration;
    069            }
    070            else if (!par1PotionEffect.field_82724_e && this.field_82724_e)
    071            {
    072                this.field_82724_e = par1PotionEffect.field_82724_e;
    073            }
    074        }
    075
    076        /**
    077         * Retrieve the ID of the potion this effect matches.
    078         */
    079        public int getPotionID()
    080        {
    081            return this.potionID;
    082        }
    083
    084        public int getDuration()
    085        {
    086            return this.duration;
    087        }
    088
    089        public int getAmplifier()
    090        {
    091            return this.amplifier;
    092        }
    093
    094        /***
    095         * Returns a list of curative items for the potion effect
    096         * @return The list (ItemStack) of curative items for the potion effect
    097         */
    098        public List<ItemStack> getCurativeItems()
    099        {
    100            return this.curativeItems;
    101        }
    102
    103        /***
    104         * Checks the given ItemStack to see if it is in the list of curative items for the potion effect
    105         * @param stack The ItemStack being checked against the list of curative items for the potion effect
    106         * @return true if the given ItemStack is in the list of curative items for the potion effect, false otherwise
    107         */
    108        public boolean isCurativeItem(ItemStack stack)
    109        {
    110            boolean found = false;
    111            for (ItemStack curativeItem : this.curativeItems)
    112            {
    113                if (curativeItem.isItemEqual(stack))
    114                {
    115                    found = true;
    116                }
    117            }
    118
    119            return found;
    120        }
    121
    122        /***
    123         * Sets the array of curative items for the potion effect
    124         * @param curativeItems The list of ItemStacks being set to the potion effect
    125         */
    126        public void setCurativeItems(List<ItemStack> curativeItems)
    127        {
    128            this.curativeItems = curativeItems;
    129        }
    130
    131        /***
    132         * Adds the given stack to list of curative items for the potion effect
    133         * @param stack The ItemStack being added to the curative item list
    134         */
    135        public void addCurativeItem(ItemStack stack)
    136        {
    137            boolean found = false;
    138            for (ItemStack curativeItem : this.curativeItems)
    139            {
    140                if (curativeItem.isItemEqual(stack))
    141                {
    142                    found = true;
    143                }
    144            }
    145            if (!found)
    146            {
    147                this.curativeItems.add(stack);
    148            }
    149        }
    150
    151        public void func_82721_a(boolean par1)
    152        {
    153            this.field_82723_d = par1;
    154        }
    155
    156        public boolean func_82720_e()
    157        {
    158            return this.field_82724_e;
    159        }
    160
    161        public boolean onUpdate(EntityLiving par1EntityLiving)
    162        {
    163            if (this.duration > 0)
    164            {
    165                if (Potion.potionTypes[this.potionID].isReady(this.duration, this.amplifier))
    166                {
    167                    this.performEffect(par1EntityLiving);
    168                }
    169
    170                this.deincrementDuration();
    171            }
    172
    173            return this.duration > 0;
    174        }
    175
    176        private int deincrementDuration()
    177        {
    178            return --this.duration;
    179        }
    180
    181        public void performEffect(EntityLiving par1EntityLiving)
    182        {
    183            if (this.duration > 0)
    184            {
    185                Potion.potionTypes[this.potionID].performEffect(par1EntityLiving, this.amplifier);
    186            }
    187        }
    188
    189        public String getEffectName()
    190        {
    191            return Potion.potionTypes[this.potionID].getName();
    192        }
    193
    194        public int hashCode()
    195        {
    196            return this.potionID;
    197        }
    198
    199        public String toString()
    200        {
    201            String var1 = "";
    202
    203            if (this.getAmplifier() > 0)
    204            {
    205                var1 = this.getEffectName() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration();
    206            }
    207            else
    208            {
    209                var1 = this.getEffectName() + ", Duration: " + this.getDuration();
    210            }
    211
    212            if (this.field_82723_d)
    213            {
    214                var1 = var1 + ", Splash: true";
    215            }
    216
    217            return Potion.potionTypes[this.potionID].isUsable() ? "(" + var1 + ")" : var1;
    218        }
    219
    220        public boolean equals(Object par1Obj)
    221        {
    222            if (!(par1Obj instanceof PotionEffect))
    223            {
    224                return false;
    225            }
    226            else
    227            {
    228                PotionEffect var2 = (PotionEffect)par1Obj;
    229                return this.potionID == var2.potionID && this.amplifier == var2.amplifier && this.duration == var2.duration && this.field_82723_d == var2.field_82723_d && this.field_82724_e == var2.field_82724_e;
    230            }
    231        }
    232
    233        public NBTTagCompound func_82719_a(NBTTagCompound par1NBTTagCompound)
    234        {
    235            par1NBTTagCompound.setByte("Id", (byte)this.getPotionID());
    236            par1NBTTagCompound.setByte("Amplifier", (byte)this.getAmplifier());
    237            par1NBTTagCompound.setInteger("Duration", this.getDuration());
    238            par1NBTTagCompound.setBoolean("Ambient", this.func_82720_e());
    239            return par1NBTTagCompound;
    240        }
    241
    242        public static PotionEffect func_82722_b(NBTTagCompound par0NBTTagCompound)
    243        {
    244            byte var1 = par0NBTTagCompound.getByte("Id");
    245            byte var2 = par0NBTTagCompound.getByte("Amplifier");
    246            int var3 = par0NBTTagCompound.getInteger("Duration");
    247            boolean var4 = par0NBTTagCompound.getBoolean("Ambient");
    248            return new PotionEffect(var1, var3, var2, var4);
    249        }
    250    }