DamageSource .java

net.minecraft.util.DamageSource (class): members: setDamageAllowedInCreativeMode, isDamageAllowedInCreativeMode, causeIndirectMagicDamage, drown, magic.

net.minecraft.utilclass283 linescommon8.7 KB

API Surface (30)

DamageSource causeMobDamage(EntityLivingBase mob)
DamageSource causePlayerDamage(EntityPlayer player)
DamageSource causeArrowDamage(EntityArrow arrow, Entity indirectEntityIn)
DamageSource causeFireballDamage(EntityFireball fireball, Entity indirectEntityIn)
DamageSource causeThrownDamage(Entity source, Entity indirectEntityIn)
DamageSource causeIndirectMagicDamage(Entity source, Entity indirectEntityIn)
DamageSource causeThornsDamage(Entity source)
DamageSource setExplosionSource(Explosion explosionIn)
boolean isProjectile()
DamageSource setProjectile()
boolean isExplosion()
DamageSource setExplosion()
boolean isUnblockable()
float getHungerDamage()
boolean canHarmInCreative()
boolean isDamageAbsolute()
Entity getSourceOfDamage()
Entity getEntity()
DamageSource setDamageBypassesArmor()
DamageSource setDamageAllowedInCreativeMode()
DamageSource setDamageIsAbsolute()
DamageSource setFireDamage()
IChatComponent getDeathMessage(EntityLivingBase entityLivingBaseIn)
boolean isFireDamage()
String getDamageType()
DamageSource setDifficultyScaled()
boolean isDifficultyScaled()
boolean isMagicDamage()
DamageSource setMagicDamage()
boolean isCreativePlayer()

Fields & Constants (25)

inFire
lightningBolt
onFire
lava
inWall
drown
starve
cactus
fall
outOfWorld
generic
magic
wither
anvil
fallingBlock
isUnblockable
isDamageAllowedInCreativeMode
damageIsAbsolute
hungerDamage
fireDamage
projectile
difficultyScaled
magicDamage
explosion

…and 1 more (see full source).

String literals (25)

"inFire"
"lightningBolt"
"onFire"
"lava"
"inWall"
"drown"
"starve"
"cactus"
"fall"
"outOfWorld"
"generic"
"magic"
"wither"
"anvil"
"fallingBlock"
"player"
"arrow"
"fireball"
"thrown"
"indirectMagic"
"thorns"
"explosion.player"
"explosion"
"death.attack."

Full Source

DamageSource.java283 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.util;
2
3
import net.minecraft.entity.Entity;
4
import net.minecraft.entity.EntityLivingBase;
5
import net.minecraft.entity.player.EntityPlayer;
6
import net.minecraft.entity.projectile.EntityArrow;
7
import net.minecraft.entity.projectile.EntityFireball;
8
import net.minecraft.world.Explosion;
9
10
public class DamageSource
11
{
12
    public static DamageSource inFire = (new DamageSource("inFire")).setFireDamage();
13
    public static DamageSource lightningBolt = new DamageSource("lightningBolt");
14
    public static DamageSource onFire = (new DamageSource("onFire")).setDamageBypassesArmor().setFireDamage();
15
    public static DamageSource lava = (new DamageSource("lava")).setFireDamage();
16
    public static DamageSource inWall = (new DamageSource("inWall")).setDamageBypassesArmor();
17
    public static DamageSource drown = (new DamageSource("drown")).setDamageBypassesArmor();
18
    public static DamageSource starve = (new DamageSource("starve")).setDamageBypassesArmor().setDamageIsAbsolute();
19
    public static DamageSource cactus = new DamageSource("cactus");
20
    public static DamageSource fall = (new DamageSource("fall")).setDamageBypassesArmor();
21
    public static DamageSource outOfWorld = (new DamageSource("outOfWorld")).setDamageBypassesArmor().setDamageAllowedInCreativeMode();
22
    public static DamageSource generic = (new DamageSource("generic")).setDamageBypassesArmor();
23
    public static DamageSource magic = (new DamageSource("magic")).setDamageBypassesArmor().setMagicDamage();
24
    public static DamageSource wither = (new DamageSource("wither")).setDamageBypassesArmor();
25
    public static DamageSource anvil = new DamageSource("anvil");
26
    public static DamageSource fallingBlock = new DamageSource("fallingBlock");
27
28
    /** This kind of damage can be blocked or not. */
29
    private boolean isUnblockable;
30
    private boolean isDamageAllowedInCreativeMode;
31
32
    /**
33
     * Whether or not the damage ignores modification by potion effects or enchantments.
34
     */
35
    private boolean damageIsAbsolute;
36
    private float hungerDamage = 0.3F;
37
38
    /** This kind of damage is based on fire or not. */
39
    private boolean fireDamage;
40
41
    /** This kind of damage is based on a projectile or not. */
42
    private boolean projectile;
43
44
    /**
45
     * Whether this damage source will have its damage amount scaled based on the current difficulty.
46
     */
47
    private boolean difficultyScaled;
48
49
    /** Whether the damage is magic based. */
50
    private boolean magicDamage;
51
    private boolean explosion;
52
    public String damageType;
53
54
    public static DamageSource causeMobDamage(EntityLivingBase mob)
55
    {
56
        return new EntityDamageSource("mob", mob);
57
    }
58
59
    /**
60
     * returns an EntityDamageSource of type player
61
     */
62
    public static DamageSource causePlayerDamage(EntityPlayer player)
63
    {
64
        return new EntityDamageSource("player", player);
65
    }
66
67
    /**
68
     * returns EntityDamageSourceIndirect of an arrow
69
     *  
70
     * @param indirectEntityIn The entity that shoot the arrow
71
     */
72
    public static DamageSource causeArrowDamage(EntityArrow arrow, Entity indirectEntityIn)
73
    {
74
        return (new EntityDamageSourceIndirect("arrow", arrow, indirectEntityIn)).setProjectile();
75
    }
76
77
    /**
78
     * returns EntityDamageSourceIndirect of a fireball
79
     *  
80
     * @param indirectEntityIn The entity that shoot the fireball
81
     */
82
    public static DamageSource causeFireballDamage(EntityFireball fireball, Entity indirectEntityIn)
83
    {
84
        return indirectEntityIn == null ? (new EntityDamageSourceIndirect("onFire", fireball, fireball)).setFireDamage().setProjectile() : (new EntityDamageSourceIndirect("fireball", fireball, indirectEntityIn)).setFireDamage().setProjectile();
85
    }
86
87
    public static DamageSource causeThrownDamage(Entity source, Entity indirectEntityIn)
88
    {
89
        return (new EntityDamageSourceIndirect("thrown", source, indirectEntityIn)).setProjectile();
90
    }
91
92
    public static DamageSource causeIndirectMagicDamage(Entity source, Entity indirectEntityIn)
93
    {
94
        return (new EntityDamageSourceIndirect("indirectMagic", source, indirectEntityIn)).setDamageBypassesArmor().setMagicDamage();
95
    }
96
97
    /**
98
     * Returns the EntityDamageSource of the Thorns enchantment
99
     *  
100
     * @param source The Entity that wears the armor with thorn
101
     */
102
    public static DamageSource causeThornsDamage(Entity source)
103
    {
104
        return (new EntityDamageSource("thorns", source)).setIsThornsDamage().setMagicDamage();
105
    }
106
107
    public static DamageSource setExplosionSource(Explosion explosionIn)
108
    {
109
        return explosionIn != null && explosionIn.getExplosivePlacedBy() != null ? (new EntityDamageSource("explosion.player", explosionIn.getExplosivePlacedBy())).setDifficultyScaled().setExplosion() : (new DamageSource("explosion")).setDifficultyScaled().setExplosion();
110
    }
111
112
    /**
113
     * Returns true if the damage is projectile based.
114
     */
115
    public boolean isProjectile()
116
    {
117
        return this.projectile;
118
    }
119
120
    /**
121
     * Define the damage type as projectile based.
122
     */
123
    public DamageSource setProjectile()
124
    {
125
        this.projectile = true;
126
        return this;
127
    }
128
129
    public boolean isExplosion()
130
    {
131
        return this.explosion;
132
    }
133
134
    public DamageSource setExplosion()
135
    {
136
        this.explosion = true;
137
        return this;
138
    }
139
140
    public boolean isUnblockable()
141
    {
142
        return this.isUnblockable;
143
    }
144
145
    /**
146
     * How much satiate(food) is consumed by this DamageSource
147
     */
148
    public float getHungerDamage()
149
    {
150
        return this.hungerDamage;
151
    }
152
153
    public boolean canHarmInCreative()
154
    {
155
        return this.isDamageAllowedInCreativeMode;
156
    }
157
158
    /**
159
     * Whether or not the damage ignores modification by potion effects or enchantments.
160
     */
161
    public boolean isDamageAbsolute()
162
    {
163
        return this.damageIsAbsolute;
164
    }
165
166
    protected DamageSource(String damageTypeIn)
167
    {
168
        this.damageType = damageTypeIn;
169
    }
170
171
    public Entity getSourceOfDamage()
172
    {
173
        return this.getEntity();
174
    }
175
176
    public Entity getEntity()
177
    {
178
        return null;
179
    }
180
181
    protected DamageSource setDamageBypassesArmor()
182
    {
183
        this.isUnblockable = true;
184
        this.hungerDamage = 0.0F;
185
        return this;
186
    }
187
188
    protected DamageSource setDamageAllowedInCreativeMode()
189
    {
190
        this.isDamageAllowedInCreativeMode = true;
191
        return this;
192
    }
193
194
    /**
195
     * Sets a value indicating whether the damage is absolute (ignores modification by potion effects or enchantments),
196
     * and also clears out hunger damage.
197
     */
198
    protected DamageSource setDamageIsAbsolute()
199
    {
200
        this.damageIsAbsolute = true;
201
        this.hungerDamage = 0.0F;
202
        return this;
203
    }
204
205
    /**
206
     * Define the damage type as fire based.
207
     */
208
    protected DamageSource setFireDamage()
209
    {
210
        this.fireDamage = true;
211
        return this;
212
    }
213
214
    /**
215
     * Gets the death message that is displayed when the player dies
216
     *  
217
     * @param entityLivingBaseIn The EntityLivingBase that died
218
     */
219
    public IChatComponent getDeathMessage(EntityLivingBase entityLivingBaseIn)
220
    {
221
        EntityLivingBase entitylivingbase = entityLivingBaseIn.getAttackingEntity();
222
        String s = "death.attack." + this.damageType;
223
        String s1 = s + ".player";
224
        return entitylivingbase != null && StatCollector.canTranslate(s1) ? new ChatComponentTranslation(s1, new Object[] {entityLivingBaseIn.getDisplayName(), entitylivingbase.getDisplayName()}): new ChatComponentTranslation(s, new Object[] {entityLivingBaseIn.getDisplayName()});
225
    }
226
227
    /**
228
     * Returns true if the damage is fire based.
229
     */
230
    public boolean isFireDamage()
231
    {
232
        return this.fireDamage;
233
    }
234
235
    /**
236
     * Return the name of damage type.
237
     */
238
    public String getDamageType()
239
    {
240
        return this.damageType;
241
    }
242
243
    /**
244
     * Set whether this damage source will have its damage amount scaled based on the current difficulty.
245
     */
246
    public DamageSource setDifficultyScaled()
247
    {
248
        this.difficultyScaled = true;
249
        return this;
250
    }
251
252
    /**
253
     * Return whether this damage source will have its damage amount scaled based on the current difficulty.
254
     */
255
    public boolean isDifficultyScaled()
256
    {
257
        return this.difficultyScaled;
258
    }
259
260
    /**
261
     * Returns true if the damage is magic based.
262
     */
263
    public boolean isMagicDamage()
264
    {
265
        return this.magicDamage;
266
    }
267
268
    /**
269
     * Define the damage type as magic based.
270
     */
271
    public DamageSource setMagicDamage()
272
    {
273
        this.magicDamage = true;
274
        return this;
275
    }
276
277
    public boolean isCreativePlayer()
278
    {
279
        Entity entity = this.getEntity();
280
        return entity instanceof EntityPlayer && ((EntityPlayer)entity).capabilities.isCreativeMode;
281
    }
282
}
283

Deobfuscated MCP 1.8.9 source of DamageSource from Marcelektro/MavenMCP-1.8.9 (net/minecraft/util/DamageSource.java), stored verbatim.