Commands/damage

Apply damage to the specified entities.

Usage
This command is not to simply change entities health value. Instead, it directly calls the underlying logic in the game to simulate the situation of causing damage to the entity. So this command has many undefined behaviors.

The output text, result, and return value of damage command are not related to whether the health value is changed. In fact, they are undefined.

The  is not the final amount of reduced health value. The reduced health value is usually less than or greater than the  due to world difficulty, armors, status effects, or the target entity itself, etc.

When damaged, the entity may react accordingly, such as being knocked back, becoming angry, etc. The damager entity may also react in certain ways, such as the arrow's disappearing.

'''Undefined behaviors may be changed at any time without warning. When this happens, your addons or maps may cease to work. Use these undefined behaviors at your own risk.''' {{Collapse
 * title=Undefined behaviors
 * content=

Hardcoded reaction

 * Mobs
 * Knocked back.
 * Get into invulnerable cooldown period.
 * etc.


 * Balloon
 * Damaged with an source entity, the balloon swings.


 * Bat
 * When damaged, sleeping bat begins flying.


 * Ender crystal
 * Controlled by dragon fight system.


 * Enderman
 * Teleports away.


 * Guardian
 * While its spikes are extended, if the damager is a mob and the cause isn't, , or , it deals thorn damage on the damager.


 * Horse
 * Opens mouth.


 * Shulker
 * Teleport somewhere.


 * Squid
 * If source is entity, spawns ink particles.

Hardcoded behaviors
When is 0, entities are always considered successfully damaged. If not 0, only entities (except armor stand, npc, camera), boats, painting, leash knot, falling block and minecarts may be recognized as successfully damaged.

Some behaviors are data driven (e.g. ender crystal's explosion, fireball's rebounding). These data driven behaviors have no effect on damage command's output text, result, and return value. Only hardcoded behaviors can affect them.


 * Player
 * Players in creative mode cannot be damaged.


 * Agent
 * Hardcoded behavior: command can always kill the agent.
 * Side effect: Damage command with the cause of always removes the agent, regardless of whether  is 0 or not.


 * Armor Stand
 * Clicking the armor stand is not considered as hurting it.
 * Applying command on an armor stand cannot reduce its health value (except for  and  causes), and is never considered to have damaged it successfully. It also cannot be detected or controlled with behavior packs.
 * Double-punching an armor stand in Survival mode destroys it.
 * Running twice within 5 gameticks on an armor stand with the damager being a player in survival mode makes the armor stand drop its held items and destroy itself.
 * Punching an armor stand in creative mode removes it.
 * Running on an armor stand with the damager being a player in creative mode removes it.
 * Explosions can always destroy the armor stand. The command can always kill the armor stand.
 * commands with the cause of, , or makes the armor stand drop its held items and destroy itself.
 * Void damage can always kill the armor stand.
 * commands with the cause always remove the armor stand.
 * Armor stands are set on fire when in lava or fire.
 * commands with the cause sets the armor stand on fire and reduces its health value by 0.5.
 * Armor stands are damaged when on fire.
 * If cause is, and the armor stand is not in a lava or fire block, commands reduce its health value by 1.0.
 * If an arrow hit an armor stand, the armor stand will be destroyed and the arrow will also disappear.
 * Running commands on an armor stand with the source being an arrow causes the armor stand to be destroyed and the arrow disappeared.
 * If an trident hit an armor stand, the armor stand will be destroyed.
 * Running commands on an armor stand with the source being a trident causes the armor stand to be destroyed.
 * When a armor stand falls onto the ground, a landing sound is played.
 * Broadcasts landing sound when a armor stand is damaged with the cause.


 * Balloon
 * Hardcoded behavior: Clicking balloon isn't considered as hurting it.
 * Side effect: Running damage command on a balloon cannot reduce its health value, and is never considered to have successfully damaged it.
 * Hardcoded behavior: Projectile, fire, lava and magma can always destroy the balloon. kill command can always kill the balloon.
 * Side effect: Damage command with the cause of, , , , , or destroys the balloon.


 * Boat
 * Hardcoded behavior: Clicking boat is always considered as hurting it.
 * Side effect: Running damage command on a boat is always considered to have successfully damaged it. But it cannot be detected or controlled with behavior packs.
 * Hardcoded behavior: Boat uses Structural Integrity to control whether it should break or not, instead of health points. A boat has 40 points of Structural Integrity.
 * Damage command changes its Structural Integrity value, instead of its health value.
 * Hardcoded behavior: Unknown
 * Side effect: Applying damage command on a boat with the damager being an enderpearl, the boat's Structural Integrity is reduced, but isn't destroyed even if Structural Integrity becomes less than 0.
 * Hardcoded behavior: Clicking a boat in creative mode means removing it.
 * Side effect: Running damage command on a boat with the damager being a player in creative mode can remove the boat, regardless of whether is 0 or not.


 * End Crystal
 * Hardcoded behavior: Hurting an end crystal means make it exploding.
 * Side effect: Running damage command on an end crystal makes it exploding, regardless of whether is 0 or not, and is never considered to have successfully damaged it.


 * Ender Dragon
 * Hardcoded behavior: Ender dragon is immune to arrows when perching, and makes arrows on fire.
 * Side effect: Damage command with source being an arrow cannot hurt a perching dragon, but makes the arrow on fire. And isn't considered successfull.
 * Hardcoded behavior: Damage command with can't hurt an ender dragon and is considered unsuccessfull.
 * Hardcoded behavior: Only players can hurt ender dragon.
 * Side effect: Only with source being player, or cause being can hurt it and can be detected or controlled with behavior packs.
 * Hardcoded behavior: command can always kill the ender dragon.
 * Side effect: Damage command with the cause of always kills the ender dragon and is considered successful, regardless of whether  is 0 or not.


 * Enderman
 * Hardcoded behavior: Projectiles except potions cannot hurt enderman.
 * Side effect: If cause is and source is not a potion entity, damage command makes the enderman teleport away without hurt, and it cannot be detected or controlled with behavior packs. Only if the enderman has successfully teleported away, is it considered to have successfully damaged it.


 * Experience orb
 * Hardcoded behavior: Player can't hurt it.
 * Side effect: Running damage command on an exp orb can reduce its health value, but is never considered to have successfully damaged it, and cannot be detected or controlled with behavior packs.


 * Falling block
 * Hardcoded behavior: Unknown
 * Undefined behavior: Applying damage command on a falling block that is falling is always considered to have successfully damaged it, and cannot be detected or controlled with behavior packs.
 * Undefined behavior: Applying damage command on a falling block with the source being always destroys it, and drops item of the block that the falling block is in (instead of what block the falling block is).


 * Ghast
 * Hardcoded behavior: A fireball deals 1000 damage to a ghast if the fireball was rebounded by a player.
 * Side effect: Running damage command on a ghast with the damager is a fireball that has been hit by player, deals 1000 damage, regardless of what  is. And it cannot be detected or controlled with behavior packs.


 * Painting and leash knot
 * Hardcoded behavior: Hitting them can destroy them.
 * Side effect: Painting and lead knot are always destroyed when applying damage command on them, and drop item if the damager is not a player in creative mode. It is always considered to have successfully damaged it, regardless of whether is 0 or not. But it cannot be detected or controlled with behavior packs.


 * Item
 * Hardcoded behavior: Player can't hurt it.
 * Side effect: Applying damage command on an item can reduce its health value, but is never considered to have successfully damaged it, and cannot be detected or controlled with behavior packs.


 * Minecart
 * Hardcoded behavior: Clicking minecart is always considered as hurting it.
 * Side effect: Running damage command on a minecart is always considered to have successfully damaged it.
 * Hardcoded behavior: Minecart uses Structural Integrity to control whether it should break or not, instead health value. A minecart has 5 Structural Integrity.
 * Damage command changes its Structural Integrity value, instead of its health value.
 * Enderpearl can reduce minecart's Structural Integrity, but cannot make it destroyed.
 * Hardcoded behavior: Unknown
 * Side effect: Applying damage command on a minecart with the damager being an enderpearl, the minecart's Structural Integrity is reduced, but isn't destroyed even if Structural Integrity becomes less than 0.


 * TNT minecart
 * Damage command with cause being and source being an arrow that is on fire, or a small fire ball, or cause being  or, primes the tnt minecart and is considered successfull. But it is never considered to have successfully damaged it, and cannot be detected or controlled with behavior packs.
 * Otherwise, it behaviors as minecart.


 * NPC
 * Hardcoded behavior: NPC cannot be hurt.
 * Side effect: Using damage command on an NPC is never considered to have successfully damaged it, and cannot be detected or controlled with behavior packs.
 * Hardcoded behavior: only void, kill command, or world builder can remove it.
 * Side effect: If the cause being or, or the cause being  and the source being a world builder, damage command removes the NPC, otherwise does nothing.


 * Primed TNT
 * Hardcoded behavior: Tnt cannot be hurt.
 * Side effect: Using damage command on a TNT is never considered to have successfully damaged it.
 * Hardcoded behavior: command can always kill the tnt.
 * Side effect: Damage command with the cause of always kills the tnt, regardless of whether  is 0 or not.


 * Skulker
 * Hardcoded behavior: Shulker teleports if in lava or fire.
 * Side effect: Applying damage command on a shulker with cause being or  can't damage it and makes the shulker teleport away. It is considered unsuccessfull, and cannot be detected or controlled with behavior packs.
 * Hardcoded behavior: Projectile cannot hurt it when it is closed.
 * Side effect: Applying damage command on a closed shulker with cause being can't damage it. It is considered unsuccessfull, and cannot be detected or controlled with behavior packs.


 * Small fireball
 * Hardcoded behavior: Small fireball cannot be hit.
 * Side effect: Using damage command on a small fireball is never considered to have successfully damaged it and cannot be detected or controlled with behavior packs.


 * Trident
 * Hardcoded behavior: Trident cannot be hurt.
 * Side effect: Using damage command on a trident is never considered to have successfully damaged it.
 * Defined behavior: Trident cannot be affected by explosion.
 * Side effect: Using damage command on a trident with cause being or  cannot be detected or controlled with behavior packs.


 * Camera
 * Hardcoded behavior: Camera cannot be hurt.
 * Side effect: Using damage command on a camera is never considered to have successfully damaged it and cannot be detected or controlled with behavior packs.
 * Hardcoded behavior: Trident cannot be affected by explosion.
 * Side effect: Using damage command on a camera with source being a player removes it.


 * Wither skull
 * Hardcoded behavior: Wither skull cannot be hurt.
 * Side effect: Using damage command on a wither skull is never considered to have successfully damaged it.
 * Hardcoded behavior: Black wither skull cannot be hit.
 * Side effect: Using damage command on a black wither skull is never considered to have successfully damaged it and cannot be detected or controlled with behavior packs.


 * Wither
 * Hardcoded behavior: Drowning and fall cannot hurt the wither.
 * Side effect: If cause is or, damage command does nothing on the wither, and it is not considered to have successfully damaged it. It cannot be detected or controlled with behavior packs.
 * Hardcoded behavior: Wither cannot damage another wither.
 * Side effect: If cause is not and source is a wither, damage command does nothing on the wither, and it is not considered to have successfully damaged it. It cannot be detected or controlled with behavior packs.
 * Hardcoded behavior:
 * Side effect: If the wither is in spawning antimation, cause is, and source is a mob, damage command makes the source mob knockbacked.
 * Hardcoded behavior: When spawning, the wither can't be hurt by anything, except void.
 * Side effect: If the wither is spawing and source is not, damage command does nothing on the wither. And it is not considered to have successfully damaged it. It cannot be detected or controlled with behavior packs.
 * Hardcoded behavior: When dying, the wither can't be hurt.
 * Side effect: If the wither is dying, damage command does nothing on the wither. And it is not considered to have successfully damaged it. It cannot be detected or controlled with behavior packs.
 * Hardcoded behavior: When having "wither armor", wither is immune to arrows.
 * Side effect: If the wither is in "wither armor" state, damage command with the cause being and the source being an arrow does nothing on the wither. And it is not considered to have successfully damaged it. It cannot be detected or controlled with behavior packs.

}}

Arguments

 * Specifies the target(s) to damage.


 * Specifies the value of damage to deal to.
 * . And should be between 0 and 2147483647 (inclusive).


 * Specifies the type of the damage. Affects death messages for example.
 * All possible arguments are listed on the official add-on documentation.


 * Specifies the damager who dealt the damage. Should be one entity or player. Use limit argument to limit one player/entity only.

Example

 * Let villager named  to deal  damage to nearby iron golem(s):

History
Befehl/damage Comandos/damage 命令/damage