001    package net.minecraft.src;
002    
003    public class PotionEffect
004    {
005        /** ID value of the potion this effect matches. */
006        private int potionID;
007    
008        /** The duration of the potion effect */
009        private int duration;
010    
011        /** The amplifier of the potion effect */
012        private int amplifier;
013    
014        public PotionEffect(int par1, int par2, int par3)
015        {
016            this.potionID = par1;
017            this.duration = par2;
018            this.amplifier = par3;
019        }
020    
021        public PotionEffect(PotionEffect par1PotionEffect)
022        {
023            this.potionID = par1PotionEffect.potionID;
024            this.duration = par1PotionEffect.duration;
025            this.amplifier = par1PotionEffect.amplifier;
026        }
027    
028        /**
029         * merges the input PotionEffect into this one if this.amplifier <= tomerge.amplifier. The duration in the supplied
030         * potion effect is assumed to be greater.
031         */
032        public void combine(PotionEffect par1PotionEffect)
033        {
034            if (this.potionID != par1PotionEffect.potionID)
035            {
036                System.err.println("This method should only be called for matching effects!");
037            }
038    
039            if (par1PotionEffect.amplifier > this.amplifier)
040            {
041                this.amplifier = par1PotionEffect.amplifier;
042                this.duration = par1PotionEffect.duration;
043            }
044            else if (par1PotionEffect.amplifier == this.amplifier && this.duration < par1PotionEffect.duration)
045            {
046                this.duration = par1PotionEffect.duration;
047            }
048        }
049    
050        /**
051         * Retrieve the ID of the potion this effect matches.
052         */
053        public int getPotionID()
054        {
055            return this.potionID;
056        }
057    
058        public int getDuration()
059        {
060            return this.duration;
061        }
062    
063        public int getAmplifier()
064        {
065            return this.amplifier;
066        }
067    
068        public boolean onUpdate(EntityLiving par1EntityLiving)
069        {
070            if (this.duration > 0)
071            {
072                if (Potion.potionTypes[this.potionID].isReady(this.duration, this.amplifier))
073                {
074                    this.performEffect(par1EntityLiving);
075                }
076    
077                this.deincrementDuration();
078            }
079    
080            return this.duration > 0;
081        }
082    
083        private int deincrementDuration()
084        {
085            return --this.duration;
086        }
087    
088        public void performEffect(EntityLiving par1EntityLiving)
089        {
090            if (this.duration > 0)
091            {
092                Potion.potionTypes[this.potionID].performEffect(par1EntityLiving, this.amplifier);
093            }
094        }
095    
096        public String getEffectName()
097        {
098            return Potion.potionTypes[this.potionID].getName();
099        }
100    
101        public int hashCode()
102        {
103            return this.potionID;
104        }
105    
106        public String toString()
107        {
108            String var1 = "";
109    
110            if (this.getAmplifier() > 0)
111            {
112                var1 = this.getEffectName() + " x " + (this.getAmplifier() + 1) + ", Duration: " + this.getDuration();
113            }
114            else
115            {
116                var1 = this.getEffectName() + ", Duration: " + this.getDuration();
117            }
118    
119            return Potion.potionTypes[this.potionID].isUsable() ? "(" + var1 + ")" : var1;
120        }
121    
122        public boolean equals(Object par1Obj)
123        {
124            if (!(par1Obj instanceof PotionEffect))
125            {
126                return false;
127            }
128            else
129            {
130                PotionEffect var2 = (PotionEffect)par1Obj;
131                return this.potionID == var2.potionID && this.amplifier == var2.amplifier && this.duration == var2.duration;
132            }
133        }
134    }