    001    package net.minecraft.src;
    002
    003    public class DamageSource
    004    {
    005        public static DamageSource inFire = (new DamageSource("inFire")).setFireDamage();
    006        public static DamageSource onFire = (new DamageSource("onFire")).setDamageBypassesArmor().setFireDamage();
    007        public static DamageSource lava = (new DamageSource("lava")).setFireDamage();
    008        public static DamageSource inWall = (new DamageSource("inWall")).setDamageBypassesArmor();
    009        public static DamageSource drown = (new DamageSource("drown")).setDamageBypassesArmor();
    010        public static DamageSource starve = (new DamageSource("starve")).setDamageBypassesArmor();
    011        public static DamageSource cactus = new DamageSource("cactus");
    012        public static DamageSource fall = (new DamageSource("fall")).setDamageBypassesArmor();
    013        public static DamageSource outOfWorld = (new DamageSource("outOfWorld")).setDamageBypassesArmor().setDamageAllowedInCreativeMode();
    014        public static DamageSource generic = (new DamageSource("generic")).setDamageBypassesArmor();
    015        public static DamageSource explosion = (new DamageSource("explosion")).func_76351_m();
    016        public static DamageSource field_76375_l = new DamageSource("explosion");
    017        public static DamageSource magic = (new DamageSource("magic")).setDamageBypassesArmor();
    018
    019        /** This kind of damage can be blocked or not. */
    020        private boolean isUnblockable = false;
    021        private boolean isDamageAllowedInCreativeMode = false;
    022        private float hungerDamage = 0.3F;
    023
    024        /** This kind of damage is based on fire or not. */
    025        private boolean fireDamage;
    026
    027        /** This kind of damage is based on a projectile or not. */
    028        private boolean projectile;
    029        private boolean field_76381_t;
    030        public String damageType;
    031
    032        public static DamageSource causeMobDamage(EntityLiving par0EntityLiving)
    033        {
    034            return new EntityDamageSource("mob", par0EntityLiving);
    035        }
    036
    037        /**
    038         * returns an EntityDamageSource of type player
    039         */
    040        public static DamageSource causePlayerDamage(EntityPlayer par0EntityPlayer)
    041        {
    042            return new EntityDamageSource("player", par0EntityPlayer);
    043        }
    044
    045        /**
    046         * returns EntityDamageSourceIndirect of an arrow
    047         */
    048        public static DamageSource causeArrowDamage(EntityArrow par0EntityArrow, Entity par1Entity)
    049        {
    050            return (new EntityDamageSourceIndirect("arrow", par0EntityArrow, par1Entity)).setProjectile();
    051        }
    052
    053        /**
    054         * returns EntityDamageSourceIndirect of a fireball
    055         */
    056        public static DamageSource causeFireballDamage(EntityFireball par0EntityFireball, Entity par1Entity)
    057        {
    058            return par1Entity == null ? (new EntityDamageSourceIndirect("onFire", par0EntityFireball, par0EntityFireball)).setFireDamage().setProjectile() : (new EntityDamageSourceIndirect("fireball", par0EntityFireball, par1Entity)).setFireDamage().setProjectile();
    059        }
    060
    061        public static DamageSource causeThrownDamage(Entity par0Entity, Entity par1Entity)
    062        {
    063            return (new EntityDamageSourceIndirect("thrown", par0Entity, par1Entity)).setProjectile();
    064        }
    065
    066        public static DamageSource causeIndirectMagicDamage(Entity par0Entity, Entity par1Entity)
    067        {
    068            return (new EntityDamageSourceIndirect("indirectMagic", par0Entity, par1Entity)).setDamageBypassesArmor();
    069        }
    070
    071        /**
    072         * Returns true if the damage is projectile based.
    073         */
    074        public boolean isProjectile()
    075        {
    076            return this.projectile;
    077        }
    078
    079        /**
    080         * Define the damage type as projectile based.
    081         */
    082        public DamageSource setProjectile()
    083        {
    084            this.projectile = true;
    085            return this;
    086        }
    087
    088        public boolean isUnblockable()
    089        {
    090            return this.isUnblockable;
    091        }
    092
    093        /**
    094         * How much satiate(food) is consumed by this DamageSource
    095         */
    096        public float getHungerDamage()
    097        {
    098            return this.hungerDamage;
    099        }
    100
    101        public boolean canHarmInCreative()
    102        {
    103            return this.isDamageAllowedInCreativeMode;
    104        }
    105
    106        protected DamageSource(String par1Str)
    107        {
    108            this.damageType = par1Str;
    109        }
    110
    111        public Entity getSourceOfDamage()
    112        {
    113            return this.getEntity();
    114        }
    115
    116        public Entity getEntity()
    117        {
    118            return null;
    119        }
    120
    121        protected DamageSource setDamageBypassesArmor()
    122        {
    123            this.isUnblockable = true;
    124            this.hungerDamage = 0.0F;
    125            return this;
    126        }
    127
    128        protected DamageSource setDamageAllowedInCreativeMode()
    129        {
    130            this.isDamageAllowedInCreativeMode = true;
    131            return this;
    132        }
    133
    134        /**
    135         * Define the damage type as fire based.
    136         */
    137        protected DamageSource setFireDamage()
    138        {
    139            this.fireDamage = true;
    140            return this;
    141        }
    142
    143        /**
    144         * Returns the message to be displayed on player death.
    145         */
    146        public String getDeathMessage(EntityPlayer par1EntityPlayer)
    147        {
    148            return StatCollector.translateToLocalFormatted("death." + this.damageType, new Object[] {par1EntityPlayer.username});
    149        }
    150
    151        /**
    152         * Returns true if the damage is fire based.
    153         */
    154        public boolean fireDamage()
    155        {
    156            return this.fireDamage;
    157        }
    158
    159        /**
    160         * Return the name of damage type.
    161         */
    162        public String getDamageType()
    163        {
    164            return this.damageType;
    165        }
    166
    167        public DamageSource func_76351_m()
    168        {
    169            this.field_76381_t = true;
    170            return this;
    171        }
    172
    173        public boolean func_76350_n()
    174        {
    175            return this.field_76381_t;
    176        }
    177    }