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