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