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 /**
082 * Returns true if the damage is projectile based.
083 */
084 public boolean isProjectile()
085 {
086 return this.projectile;
087 }
088
089 /**
090 * Define the damage type as projectile based.
091 */
092 public DamageSource setProjectile()
093 {
094 this.projectile = true;
095 return this;
096 }
097
098 public boolean isUnblockable()
099 {
100 return this.isUnblockable;
101 }
102
103 /**
104 * How much satiate(food) is consumed by this DamageSource
105 */
106 public float getHungerDamage()
107 {
108 return this.hungerDamage;
109 }
110
111 public boolean canHarmInCreative()
112 {
113 return this.isDamageAllowedInCreativeMode;
114 }
115
116 protected DamageSource(String par1Str)
117 {
118 this.damageType = par1Str;
119 }
120
121 public Entity getSourceOfDamage()
122 {
123 return this.getEntity();
124 }
125
126 public Entity getEntity()
127 {
128 return null;
129 }
130
131 protected DamageSource setDamageBypassesArmor()
132 {
133 this.isUnblockable = true;
134 this.hungerDamage = 0.0F;
135 return this;
136 }
137
138 protected DamageSource setDamageAllowedInCreativeMode()
139 {
140 this.isDamageAllowedInCreativeMode = true;
141 return this;
142 }
143
144 /**
145 * Define the damage type as fire based.
146 */
147 protected DamageSource setFireDamage()
148 {
149 this.fireDamage = true;
150 return this;
151 }
152
153 /**
154 * Returns the message to be displayed on player death.
155 */
156 public String getDeathMessage(EntityPlayer par1EntityPlayer)
157 {
158 return StatCollector.translateToLocalFormatted("death." + this.damageType, new Object[] {par1EntityPlayer.username});
159 }
160
161 /**
162 * Returns true if the damage is fire based.
163 */
164 public boolean isFireDamage()
165 {
166 return this.fireDamage;
167 }
168
169 /**
170 * Return the name of damage type.
171 */
172 public String getDamageType()
173 {
174 return this.damageType;
175 }
176
177 public DamageSource func_76351_m()
178 {
179 this.field_76381_t = true;
180 return this;
181 }
182
183 public boolean func_76350_n()
184 {
185 return this.field_76381_t;
186 }
187
188 /**
189 * Returns true if the damage is magic based.
190 */
191 public boolean isMagicDamage()
192 {
193 return this.magicDamage;
194 }
195
196 /**
197 * Define the damage type as magic based.
198 */
199 public DamageSource setMagicDamage()
200 {
201 this.magicDamage = true;
202 return this;
203 }
204 }