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 will cease to work. Use these undefined behaviors at your own risk.''' <!--

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 dragton fight system.


 * Enderman
 * Teleports away.


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


 * Horse
 * Opens mouth.


 * Shulker
 * Teleport somewhere.


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

Hardcoded behaviors
Target entity can be any entity types, but only living entities, painting, leash knot, camera, boats, and minecarts can be recognized as successfully damaged.

Player in creative mode can't be damaged.

And when is 0, mobs are considered successfully damaged.


 * Agent
 * Defined 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
 * Defined behavior: Clicking armor stand isn't considered as hurting it.
 * Side effect: Applying damage command on an armor stand can't reduce its health value (except and  cause, see below for detail), and is never considered to have successfully damaged it. And it cannot be detected or controlled with behavior packs.
 * Defined behavior: Double-clicking an armor stand in Survival mode means destroying it.
 * Side effect: Quickly (within 5 gameticks) running damage command twice on an armor stand with the damager being a player in survival mode makes the armor stand drop its held items and destroyed.
 * Defined behavior: Clicking an armor stand in creative mode means removing it.
 * Side effect: Running damage command on an armor stand with the damager being a player in creative mode removes it.
 * Defined behavior: Explosion can always destroy the armor stand. command can always kill the armor stand.
 * Side effect: Damage command with the cause of, , or makes the armor stand drop its held items and removed.
 * Defined behavior: Void can always kill the armor stand.
 * Side effect: Damage command with the cause always removes the armor stand.
 * Defined behavior: Armor stand become on fire when in lava or fire.
 * Side effect: Damage command with the cause makes the armor stand on fire and reduces its health value by 0.5.
 * Defined behavior: Armor stand is damaged when on fire.
 * Side effect: If cause is, and the armor stand is not in lava or fire block, damage command reduces its health value by 1.0
 * Defined behavior: An arrow hit an armor stand, the armor stand is destroyed and the arrow is also disappeared.
 * Side effect: Running damage command on an armor stand with the source being an arrow, the armor stand is destroyed and the arrow is disapeared.
 * Defined behavior: A trident hit an armor stand, the armor stand is destroyed.
 * Side effect: Running damage command on an armor stand with the source being a trident, the armor stand is destroyed.
 * Defined behavior: When falling onto the ground, the landing sound is played.
 * Side effect: Broadcasts landing sound when damaging with cause.


 * Balloon
 * Defined 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.
 * Defined 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
 * Defined 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.
 * Defined behavior: Boat uses Structural Integrity to control whether it should break or not, instead of health value. A boat has 40 Structural Integrity.
 * Damage command changes its Structural Integrity value, instead of its health value.
 * Defined 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.
 * Defined 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
 * Defined 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
 * Undefined behavior: Unlike most mobs, damage command with amount being 0 is not considered to have successfully damaged an ender dragon.
 * Defined 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.
 * Defined behavior: Damage command with can't hurt an ender dragon and is considered unsuccessfull.
 * Defined 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.
 * Defined 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.

//:If is Projectile but not potion entity, teleport without hurt. not successful. it cannot be detected or controlled with behavior packs.
 * Enderman


 * Experience orb
 * Defined 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
 * Defined 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 is piston always destroys it, and drops item of the block that the falling block is in (instead of what block the falling block is).


 * Ghast
 * Defined 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
 * Defined 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
 * Defined 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
 * Defined 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.
 * Defined 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.
 * Defined 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.

never successfull, cannot be detected or controlled with behavior packs only void, suicide, or entity_attack from a world builder remove it, otherwise does nothing.
 * NPC


 * Primed TNT
 * Defined behavior: Tnt cannot be hurt.
 * Side effect: Using damage command on a TNT is never considered to have successfully damaged it.
 * Defined 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
 * Defined 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.
 * Defined 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 fire ball
 * Defined behavior: Small fire ball cannot be hit.
 * Side effect: Using damage command on a small fire ball is never considered to have successfully damaged it and cannot be detected or controlled with behavior packs.


 * Trident
 * Defined 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
 * Defined 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.
 * Defined behavior: Trident cannot be affected by explosion.
 * Side effect: Using damage command on a camera with source being a player removes it.


 * Wither skull
 * Defined behavior: Wither skull cannot be hurt.
 * Side effect: Using damage command on a wither skull is never considered to have successfully damaged it
 * Defined 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.

-->

Arguments

 * Specifies the target(s) to damage.


 * Specifies the value of damage to deal to.
 * . And must 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.

Examples

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

History
Comandos/damage 命令/damage