    001    package net.minecraft.potion;
    002
    003    import cpw.mods.fml.common.Side;
    004    import cpw.mods.fml.common.asm.SideOnly;
    005    import net.minecraft.entity.EntityLiving;
    006    import net.minecraft.entity.player.EntityPlayer;
    007    import net.minecraft.util.DamageSource;
    008    import net.minecraft.util.StringUtils;
    009
    010    public class Potion
    011    {
    012        /** The array of potion types. */
    013        public static final Potion[] potionTypes = new Potion[32];
    014        public static final Potion field_76423_b = null;
    015        public static final Potion moveSpeed = (new Potion(1, false, 8171462)).setPotionName("potion.moveSpeed").setIconIndex(0, 0);
    016        public static final Potion moveSlowdown = (new Potion(2, true, 5926017)).setPotionName("potion.moveSlowdown").setIconIndex(1, 0);
    017        public static final Potion digSpeed = (new Potion(3, false, 14270531)).setPotionName("potion.digSpeed").setIconIndex(2, 0).setEffectiveness(1.5D);
    018        public static final Potion digSlowdown = (new Potion(4, true, 4866583)).setPotionName("potion.digSlowDown").setIconIndex(3, 0);
    019        public static final Potion damageBoost = (new Potion(5, false, 9643043)).setPotionName("potion.damageBoost").setIconIndex(4, 0);
    020        public static final Potion heal = (new PotionHealth(6, false, 16262179)).setPotionName("potion.heal");
    021        public static final Potion harm = (new PotionHealth(7, true, 4393481)).setPotionName("potion.harm");
    022        public static final Potion jump = (new Potion(8, false, 7889559)).setPotionName("potion.jump").setIconIndex(2, 1);
    023        public static final Potion confusion = (new Potion(9, true, 5578058)).setPotionName("potion.confusion").setIconIndex(3, 1).setEffectiveness(0.25D);
    024
    025        /** The regeneration Potion object. */
    026        public static final Potion regeneration = (new Potion(10, false, 13458603)).setPotionName("potion.regeneration").setIconIndex(7, 0).setEffectiveness(0.25D);
    027        public static final Potion resistance = (new Potion(11, false, 10044730)).setPotionName("potion.resistance").setIconIndex(6, 1);
    028
    029        /** The fire resistance Potion object. */
    030        public static final Potion fireResistance = (new Potion(12, false, 14981690)).setPotionName("potion.fireResistance").setIconIndex(7, 1);
    031
    032        /** The water breathing Potion object. */
    033        public static final Potion waterBreathing = (new Potion(13, false, 3035801)).setPotionName("potion.waterBreathing").setIconIndex(0, 2);
    034
    035        /** The invisibility Potion object. */
    036        public static final Potion invisibility = (new Potion(14, false, 8356754)).setPotionName("potion.invisibility").setIconIndex(0, 1);
    037
    038        /** The blindness Potion object. */
    039        public static final Potion blindness = (new Potion(15, true, 2039587)).setPotionName("potion.blindness").setIconIndex(5, 1).setEffectiveness(0.25D);
    040
    041        /** The night vision Potion object. */
    042        public static final Potion nightVision = (new Potion(16, false, 2039713)).setPotionName("potion.nightVision").setIconIndex(4, 1);
    043
    044        /** The hunger Potion object. */
    045        public static final Potion hunger = (new Potion(17, true, 5797459)).setPotionName("potion.hunger").setIconIndex(1, 1);
    046
    047        /** The weakness Potion object. */
    048        public static final Potion weakness = (new Potion(18, true, 4738376)).setPotionName("potion.weakness").setIconIndex(5, 0);
    049
    050        /** The poison Potion object. */
    051        public static final Potion poison = (new Potion(19, true, 5149489)).setPotionName("potion.poison").setIconIndex(6, 0).setEffectiveness(0.25D);
    052
    053        /** The wither Potion object. */
    054        public static final Potion wither = (new Potion(20, true, 3484199)).setPotionName("potion.wither").setIconIndex(1, 2).setEffectiveness(0.25D);
    055        public static final Potion field_76434_w = null;
    056        public static final Potion field_76444_x = null;
    057        public static final Potion field_76443_y = null;
    058        public static final Potion field_76442_z = null;
    059        public static final Potion field_76409_A = null;
    060        public static final Potion field_76410_B = null;
    061        public static final Potion field_76411_C = null;
    062        public static final Potion field_76405_D = null;
    063        public static final Potion field_76406_E = null;
    064        public static final Potion field_76407_F = null;
    065        public static final Potion field_76408_G = null;
    066
    067        /** The Id of a Potion object. */
    068        public final int id;
    069
    070        /** The name of the Potion. */
    071        private String name = "";
    072
    073        /** The index for the icon displayed when the potion effect is active. */
    074        private int statusIconIndex = -1;
    075
    076        /**
    077         * This field indicated if the effect is 'bad' - negative - for the entity.
    078         */
    079        private final boolean isBadEffect;
    080        private double effectiveness;
    081        private boolean usable;
    082
    083        /** Is the color of the liquid for this potion. */
    084        private final int liquidColor;
    085
    086        protected Potion(int par1, boolean par2, int par3)
    087        {
    088            this.id = par1;
    089            potionTypes[par1] = this;
    090            this.isBadEffect = par2;
    091
    092            if (par2)
    093            {
    094                this.effectiveness = 0.5D;
    095            }
    096            else
    097            {
    098                this.effectiveness = 1.0D;
    099            }
    100
    101            this.liquidColor = par3;
    102        }
    103
    104        /**
    105         * Sets the index for the icon displayed in the player's inventory when the status is active.
    106         */
    107        protected Potion setIconIndex(int par1, int par2)
    108        {
    109            this.statusIconIndex = par1 + par2 * 8;
    110            return this;
    111        }
    112
    113        /**
    114         * returns the ID of the potion
    115         */
    116        public int getId()
    117        {
    118            return this.id;
    119        }
    120
    121        public void performEffect(EntityLiving par1EntityLiving, int par2)
    122        {
    123            if (this.id == regeneration.id)
    124            {
    125                if (par1EntityLiving.getHealth() < par1EntityLiving.getMaxHealth())
    126                {
    127                    par1EntityLiving.heal(1);
    128                }
    129            }
    130            else if (this.id == poison.id)
    131            {
    132                if (par1EntityLiving.getHealth() > 1)
    133                {
    134                    par1EntityLiving.attackEntityFrom(DamageSource.magic, 1);
    135                }
    136            }
    137            else if (this.id == wither.id)
    138            {
    139                par1EntityLiving.attackEntityFrom(DamageSource.wither, 1);
    140            }
    141            else if (this.id == hunger.id && par1EntityLiving instanceof EntityPlayer)
    142            {
    143                ((EntityPlayer)par1EntityLiving).addExhaustion(0.025F * (float)(par2 + 1));
    144            }
    145            else if ((this.id != heal.id || par1EntityLiving.isEntityUndead()) && (this.id != harm.id || !par1EntityLiving.isEntityUndead()))
    146            {
    147                if (this.id == harm.id && !par1EntityLiving.isEntityUndead() || this.id == heal.id && par1EntityLiving.isEntityUndead())
    148                {
    149                    par1EntityLiving.attackEntityFrom(DamageSource.magic, 6 << par2);
    150                }
    151            }
    152            else
    153            {
    154                par1EntityLiving.heal(6 << par2);
    155            }
    156        }
    157
    158        /**
    159         * Hits the provided entity with this potion's instant effect.
    160         */
    161        public void affectEntity(EntityLiving par1EntityLiving, EntityLiving par2EntityLiving, int par3, double par4)
    162        {
    163            int var6;
    164
    165            if ((this.id != heal.id || par2EntityLiving.isEntityUndead()) && (this.id != harm.id || !par2EntityLiving.isEntityUndead()))
    166            {
    167                if (this.id == harm.id && !par2EntityLiving.isEntityUndead() || this.id == heal.id && par2EntityLiving.isEntityUndead())
    168                {
    169                    var6 = (int)(par4 * (double)(6 << par3) + 0.5D);
    170
    171                    if (par1EntityLiving == null)
    172                    {
    173                        par2EntityLiving.attackEntityFrom(DamageSource.magic, var6);
    174                    }
    175                    else
    176                    {
    177                        par2EntityLiving.attackEntityFrom(DamageSource.causeIndirectMagicDamage(par2EntityLiving, par1EntityLiving), var6);
    178                    }
    179                }
    180            }
    181            else
    182            {
    183                var6 = (int)(par4 * (double)(6 << par3) + 0.5D);
    184                par2EntityLiving.heal(var6);
    185            }
    186        }
    187
    188        /**
    189         * Returns true if the potion has an instant effect instead of a continuous one (eg Harming)
    190         */
    191        public boolean isInstant()
    192        {
    193            return false;
    194        }
    195
    196        /**
    197         * checks if Potion effect is ready to be applied this tick.
    198         */
    199        public boolean isReady(int par1, int par2)
    200        {
    201            int var3;
    202
    203            if (this.id != regeneration.id && this.id != poison.id)
    204            {
    205                if (this.id == wither.id)
    206                {
    207                    var3 = 40 >> par2;
    208                    return var3 > 0 ? par1 % var3 == 0 : true;
    209                }
    210                else
    211                {
    212                    return this.id == hunger.id;
    213                }
    214            }
    215            else
    216            {
    217                var3 = 25 >> par2;
    218                return var3 > 0 ? par1 % var3 == 0 : true;
    219            }
    220        }
    221
    222        /**
    223         * Set the potion name.
    224         */
    225        public Potion setPotionName(String par1Str)
    226        {
    227            this.name = par1Str;
    228            return this;
    229        }
    230
    231        /**
    232         * returns the name of the potion
    233         */
    234        public String getName()
    235        {
    236            return this.name;
    237        }
    238
    239        protected Potion setEffectiveness(double par1)
    240        {
    241            this.effectiveness = par1;
    242            return this;
    243        }
    244
    245        @SideOnly(Side.CLIENT)
    246
    247        /**
    248         * Returns true if the potion has a associated status icon to display in then inventory when active.
    249         */
    250        public boolean hasStatusIcon()
    251        {
    252            return this.statusIconIndex >= 0;
    253        }
    254
    255        @SideOnly(Side.CLIENT)
    256
    257        /**
    258         * Returns the index for the icon to display when the potion is active.
    259         */
    260        public int getStatusIconIndex()
    261        {
    262            return this.statusIconIndex;
    263        }
    264
    265        @SideOnly(Side.CLIENT)
    266
    267        /**
    268         * This method returns true if the potion effect is bad - negative - for the entity.
    269         */
    270        public boolean isBadEffect()
    271        {
    272            return this.isBadEffect;
    273        }
    274
    275        @SideOnly(Side.CLIENT)
    276        public static String getDurationString(PotionEffect par0PotionEffect)
    277        {
    278            int var1 = par0PotionEffect.getDuration();
    279            return StringUtils.ticksToElapsedTime(var1);
    280        }
    281
    282        public double getEffectiveness()
    283        {
    284            return this.effectiveness;
    285        }
    286
    287        public boolean isUsable()
    288        {
    289            return this.usable;
    290        }
    291
    292        /**
    293         * Returns the color of the potion liquid.
    294         */
    295        public int getLiquidColor()
    296        {
    297            return this.liquidColor;
    298        }
    299    }