Advanced Modding - Damage Sources


I want to show you how to create damage sources to make new death messages or change the damage's behaviour.


2/10 - Quite Simple



Forge Version

This Tutorial was created with Forge for Minecraft 1.8. If anything doesn't work with other versions, please contact me!

Vanilla DamageSources

There are many damage sources defined in vanilla Minecraft. Here, I'll list them all to show you their differences.


Note that there are two types of damage sources:

  • Static Damage sources that are independend from a player or entity, like drowning damage.
  • Dynamic Damage sources that depend on a player, like PvP damage.

Damage Sources can have several properties, by default none of them is set:

Projectile Can be reduced with the Projectile Protection enchantment .setProjectile()
Explosion Can be reduced with the Blast Protection enchantment .setExplosion()
Bypasses Armor Is not reduced by Armor .setDamageBypassesArmor()
Allowed in Creative Mode self-explanatory .setDamageAllowedInCreativeMode()
Absolute Is not reduced by potion effects or enchantments, but by armor .setDamageIsAbsolute()
Fire Can be blocked with a Fire Resistance Potion .setFireDamage()
Difficulty Scaled Damage value is scaled by the difficulty * .setDifficultyScaled()
Magic Damage Does not hurt witches and does not trigger the thorns enchantment .setMagicDamage()
Thorns Marked to be Thorns Damage .setIsThornsDamage()


* Damage that is scaled by difficulty is modified the following way:

  • Peaceful: damage = 0
  • Easy: damage = original / 2 + 1
  • Normal: damage = original
  • Hard: damage = 3 * original / 2

Damage Source Properties
inFire Death Message: <Player> went up in flames
Fire Damage
Caused when a player stands in fire.

Death Message: <Player> was struck by lightning

Caused when a player is hit by a lightning bolt.



Death Message: <Player> burned to death

Bypasses Armor

Fire Damage

Caused when a player burns.



Death Message: <Player> tried to swim in lava

Fire Damage

Caused when a player is in lava **.



Death Message: <Player> suffocated in a wall

Bypasses Armor

Caused when a player is inside a block.



Death Message: <Player> drowned

Bypasses Armor

Caused when a player is below water and it's air level runs out.



Death Message: <Player> starved to death

Bypasses Armor


Caused when a player's food level runs out.



Death Message: <Player> was pricked to death

Caused when a player hits a cactus



Death Message: <Player> fell from a high place

Bypasses Armor

(Reduced by boots and featherfalling)

Caused when a player falls onto the ground.



Death Message: <Player> fell out of the world

Bypasses Armor

Allowed in Creative Mode

(Is not scaled down by any protection mechanism)

Caused when a player is below y=-64



Death Message: <Player> died

Bypasses Armor

Not used as a real damage, only used to update client-side health.



Death Message: <Player> was killed by magic

Bypasses Armor

Magic Damage

Caused when a player receives the instant damage or poison potion effect.



Death Message: <Player> withered away

Bypasses Armor

Caused by the wither potion effect.



Death Message: <Player> was squashed by a falling anvil

Caused when an anvil hits a player on the head.



Death Message: <Player> was squashed by a falling block

Caused when a block hits a player on the head.



Death Message: <Player> was slain by <Mob>


Caused when a player is hit by a mob.

DamageSource.causeMobDamage(EntityLivingBase mob)


Death Message: <Player> was slain by <OtherPlayer>


Caused when players hit each other.

DamageSource.causePlayerDamage(EntityPlayer player)


Death Message: <Player> was shot by <IndirectSource>


Caused when an arrow hits someone.

DamageSource.causeArrowDamage(EntityArrow arrow, Entity indirectSource)


Death Message: <Player> was fireballed by <IndirectSource>




Caused when a player gets hit by a fireball.

DamageSource.causeFireballDamage(EntityFireball fireball, Entity indirectSource)


Death Message: <Player> was pummeled by <IndirectSource>



Caused when a player gets hit by a snowball, an egg, an enderpearl or a fishing hook. However, they all cause no damage.

DamageSource.causeThrownDamage(Entity projectile, Entity indirectSource)


Death Message: <Player> was killed by <IndirectSource> using magic


Bypasses Armor


Caused when someone throws a potion of harming on someone else.

DamageSource.causeIndirectMagicDamage(Entity transmitter, Entity indirectSource)


Death Message: <Player> was killed trying to hurt <OtherPlayer>




Caused by the Thorns enchantment.

DamageSource.causeThornsDamage(Entity source)


Death Message: <Player> blew up


Difficulty Scaled


Caused by Explosions

DamageSource.setExplosionSource(Explosion explosion)


** If a player is in lava, he does not receive onFire damage simultaneously. If you have an armor that shields you about 100% it is better to stay in the lava than going outside where the onFire damage goes through your armor. However, you'll loose armor durability pretty fast while staying in the lava.

Custom DamageSources

Creating cutom damage sources is relatively easy, especially if you want to create static damage sources. For those, you only need to create a new damage source object and add the corresponding death message to you language file.
DamageSource electricDamage = new DamageSource("electric").setDamageBypassesArmor();
Language file:
death.attack.electric=%1$s was roasted by electric current.
death.attack.electric.player=%1$s was roasted by electric current while fighting %2$s.

The second death message appears, when the player has been attacked by a player in the last few seconds before his death.

The cryptic symbols (%1$s) are formatter symbols. Those are used to insert an object into the String. To learn more about those formatters, go to the Java documentation for the Formatter class.

To make it simple, everything you need to remember is this single formatter: %<n>$s

<n> is a number, which represents the number of the argument passed to the String.format method.

For instance, %1$s is equal to the result of the toString() method of the first argument.

Custom dynamic DamageSources

There are two different types of dynamic DamageSources: direct and indirect.

Direct DamageSources are used if a player or mob directly attacks another player or mob.

Indirect DamageSources are used if there is a transmitter entity, like an arrow or a fireball.

To create a dynamic Damage Source, you should create a new class for it first. (There is also the possibility to use the vanilla classes, but they are relatively useless if it comes to more complicated attacks.
public class EntityDamageSourceElectric extends EntityDamageSourceIndirect {


Your class can either extend EntityDamageSource or EntityDamageSourceIndirect. I'll use indirect here, because if you understood this, you can do the other one as well.

First things first, we need a Constructor:
public EntityDamageSourceElectric(String name, Entity transmitter, Entity indirectSource) {
    super(name, transmitter, indirectSource);

I've renamed the paramters so that it becomes clear what they do.

The first one is the name, this can be any String.

The second one is the transmitter entity. This entity can be an arrow or anything else. It must not be null.

The last argument is the original source of damage, for instance the player that shot the arrow. This object can be null, so the methods need to respect that.

Be careful, in the following part the method names might get confusing because they do really not tell what they do.

We're now going to override the method getDeathMessage:
public IChatComponent getDeathMessage(EntityLivingBase target) {

Here, we're returning the correct death message based on the data we have: The target of the attack, the source of the attack and the transmitter.

First we're getting checking if the indirect source is null. If so, we're the name of the transmitter as the source.

Here is where the confusing method names start:

getEntity() returns the indirect source of damage and

getSourceOfDamage() returns the transmitter. (For direct damage sources, getSourceOfDamage() returns the direct source)
public IChatComponent getDeathMessage(EntityLivingBase target) {
    String s = "death.attack." + this.damageType;
    IChatComponent source = getEntity() == null ? getSourceOfDamage().getDisplayName() : getEntity.getDisplayName();

Now we have the name of the indirect damage source as a ChatComponent.

The next step (which is optional and of course modifyable) is to check if the attack has taken place with a special, named Item.

Therfore, we're using this code:
public IChatComponent getDeathMessage(EntityLivingBase target) {
    String s = "death.attack." + this.damageType;
    IChatComponent source = getEntity() == null ? getSourceOfDamage().getDisplayName() : getEntity.getDisplayName();
    ItemStack stack = (getEntity() != null && getEntity() instanceof EntityLivingBase) ? ((EntityLivingBase)getEntity()).getHeldItem() : null;
    String s1 = s + ".item";

Now we've collected the necessary information to return the correct message.
public IChatComponent getDeathMessage(EntityLivingBase target) {
    String s = "death.attack." + this.damageType;
    IChatComponent source = getEntity() == null ? getSourceOfDamage().getDisplayName() : getEntity.getDisplayName();
    ItemStack stack = (getEntity() != null && getEntity() instanceof EntityLivingBase) ? ((EntityLivingBase)getEntity()).getHeldItem() : null;
    String s1 = s + ".item";

    return stack != null && stack.hasDisplayName() && StatCollector.canTranslate(s1) ? 
            new ChatComponentTranslation(s1, target.getDisplayName(), source, stack.getChatComponent()) :
            new ChatComponentTranslation(s, target.getDisplayName(), source);

These lines return the "advanced" damage type with the Item if the attacker has a named item in his hand.

Otherwise, the basic type is returned. The arguments for the ChatComponentTranslation objects after the String are the objects that can be filled in with the formatter codes. We now need a method to easily generate a damage source if we need it:
public static EntityDamageSourceElectric causeElectricDamage(Entity source, Entity transmitter) {
    return new EntityDamageSourceElectric("electric.entity", transmitter, source);

Last thing to do is to add the language parts to the language file:

Language File:
death.attack.electric.entity=%1$s was roasted by %2$s using electric current.
death.attack.electric.entity.item=%1$s was roasted by %2$s using electric current produced by %3$s.

You can (should?) extend the getDeathMessage method even further, for instance to add a special death message when no indirect source is available. Or you add a special message if the item is a good item added by your mod, even if its not named.

You can get really creative here...

Damaging an Entity using the custom Damage Source

To damage an entity you just need to call

entity.attackEntityFrom(DamageSource source, float damage)

Recommended tutorials to continue with

Advanced Modding:

  • Potion Effects

Comments and Questions:

If you want to report modding problems, please make sure to include the code in a pastebin link or something else! Don't just write "It doesn't work", otherwise your post will be deleted. For more complicated problems, please use the troubleshooter form.