Handle damage, death and respawn
Use this page when your plugin needs to deal damage, cancel a hit or react to its result. Players and mobs share the damage queue; player death messages and respawn policy have separate replacement hooks.
Queue a hit in the right phase
Section titled “Queue a hit in the right phase”To deal damage, append DamageRequest::new(target, hit, writer, tick, sequence) to PendingHits in the target’s dimension. DamagePlugin has two chains in FixedUpdate, each with a filter before application and a report afterward:
| Requests ready at this point | DamageSet variants in order | When and in what order hits apply |
|---|---|---|
Client packet attacks and command hits queued in FixedPreUpdate |
PacketCollect, PacketFilter, PacketApply, PacketReport |
after TickSet::ClientInput, before TickSet::Simulate, in queue order; packet attacks preserve arrival order |
| Hits queued after the early batch, including motion hits | Collect, Filter, Apply, Report |
in TickSet::WorldWrite, after MotionPass, sorted by target EntityUuid, WriterKey, write tick, sequence and original queue index |
The later batch uses the entity UUID, not a network id or the order in which worker threads finish. Packet attacks apply after all packets of the tick have been handled, so a packet attack can change a mob’s motion through knockback in the same tick. Hits applied before simulation have their hurt and damage cooldown counters advanced in that tick; post-motion hits first advance on the next tick.12
The vanilla /damage and /kill effects enqueue hits for players and mobs in FixedPreUpdate. DamageSet::PacketApply applies them before simulation in queue order, so the command reply is not a notification that health already changed. /damage builds its reply from the kernel’s preview; read Damaged or Died in DamageSet::PacketReport for the applied result.3
Filter hits and read results
Section titled “Filter hits and read results”To cancel or change packet attacks and command hits queued before simulation, put your system in DamageSet::PacketFilter. DamageSet::Filter handles the later, post-motion batch and does not intercept those packet attacks. Both hooks edit requests with requests_mut() or remove them with retain().
Read Damaged and Died in the matching report set. Accepted hits produce Damaged, and a death also produces Died; both players and mobs use the same damage kernel.
Read health and defence
Section titled “Read health and defence”PlayerVitalsPlugin, installed by VanillaEntityAttributesPlugin, gives players the same Vitals, HitRecord and Defence components as mobs. Vitals owns current health, absorption and the hurt, cooldown and death counters; maximum health comes from attributes. The persisted registry saves the health state. Food remains in PlayerFileState until hunger has its own owner. Creative and spectator players reject hits unless the damage type bypasses invulnerability.3
The built-in player path currently fills only game-mode invulnerability in Defence. It does not populate player armour, toughness or resistance from attributes, equipment or effects. Mob defence includes armour, toughness and fire or fall immunities derived from attributes and entity data. A hit that lowers a resting mob’s health is replicated even when the mob does not move. The kernel can calculate resistance, but no effect system fills it on the server yet.1
Handle a player’s death
Section titled “Handle a player’s death”The player’s client receives health and food updates. Viewers receive health changes and the dying pose; the dying player receives the kill packet. At login, the death-screen flag follows immediate_respawn; later rule changes are not sent yet. At death time 20, HiddenPlayer removes the player from other clients, while its Bevy entity, connection and own view remain. Inventory describes drops.
DeathMessage { player, text } supplies the death-screen text. VanillaDeathMessagesPlugin writes it in PlayerDeathSet::Describe and broadcasts it in Announce, after the engine sends the kill packet in Notify. Vanilla text follows show_death_messages; turning it off also leaves the kill packet’s text empty. To supply your own text, disable that plugin and write DeathMessage in Describe. Without a writer, the death-screen text is empty.4
Respawn through a request
Section titled “Respawn through a request”The engine restores a dead player only after a RespawnRequest:
pub struct RespawnRequest { pub player: Entity, pub dimension: Entity, pub transform: Transform,}crates/mcrs_minecraft_engine_damage/src/respawn_request.rs:6-10
dimension is the host’s entity id for the target dimension. VanillaRespawnPlugin turns the client’s respawn command into this request at the adjusted world spawn. Disable that plugin and write requests in the player’s world to choose another policy. The engine restores vitals and food, sends the respawn and position packets, and shows the player to viewers again. A request for another dimension starts a dimension change.
The vanilla policy currently treats bed and anchor spawn points as missing. Its surface search ignores the world border and caps the radius at 15. Respawn does not yet reset every effect, pose, motion, item cooldown or attribute modifier, or resend all inventory and experience state. Hunger simulation and environmental hit sources remain separate work.3 Baseline melee attacks run, and an attacked player receives its own knockback velocity, but sweep and critical hits, attack sounds and exhaustion remain unfinished.2
Next: Keep a player component across restarts and moves.
Footnotes
Section titled “Footnotes”-
Works#1078 Adds the sorted damage step, filter and report sets, mob defence and health replication for resting mobs. ↩ ↩2
-
Works#1106 Adds baseline melee attacks, the pre-motion damage filter and arrival-order tests; Parity with vanilla describes the remaining validation work. ↩ ↩2
-
Works#1082 Adds player vitals, death packets and replaceable respawn requests, with incomplete resets and spawn-point rules. ↩ ↩2 ↩3
Sources and verification
Verified: 26.4-snapshot-7, 1cf84286c, 2026-11-30
- crates/mcrs_minecraft_damage/src/vitals.rs
- crates/mcrs_minecraft_damage/src/defence.rs
- crates/mcrs_minecraft_damage/src/hurt.rs
- crates/mcrs_minecraft_engine_damage/src/damage_request.rs
- crates/mcrs_minecraft_engine_damage/src/pending_hits.rs
- crates/mcrs_minecraft_engine_damage/src/damage_plugin.rs
- crates/mcrs_minecraft_engine_damage/src/apply_hits.rs
- crates/mcrs_minecraft_engine_damage/src/tick_vitals.rs
- crates/mcrs_minecraft_engine_damage/src/respawn_request.rs
- crates/mcrs_minecraft_engine_damage/tests/it/hit_order.rs
- crates/mcrs_minecraft_engine_damage/tests/it/vitals.rs
- crates/mcrs_minecraft_engine_player_vitals/src/player_vitals_plugin.rs
- crates/mcrs_minecraft_engine_player_vitals/src/player_invulnerability.rs
- crates/mcrs_minecraft_engine_player_vitals/src/send_health.rs
- crates/mcrs_minecraft_engine_player_vitals/src/signal_hits.rs
- crates/mcrs_minecraft_engine_player_vitals/src/send_kill.rs
- crates/mcrs_minecraft_engine_player_vitals/src/hide_dead_players.rs
- crates/mcrs_minecraft_engine_player_vitals/src/respawn_players.rs
- crates/mcrs_minecraft_engine_player_vitals/src/death_message.rs
- crates/mcrs_minecraft_engine_player_vitals/src/player_death_set.rs
- crates/mcrs_minecraft_engine_player_vitals/tests/it/saved_health.rs
- crates/mcrs_minecraft_engine_player/src/persistence.rs
- crates/mcrs_minecraft_engine_player/src/player_state.rs
- crates/mcrs_minecraft_engine_player/src/max_health.rs
- crates/mcrs_minecraft_engine_player/src/consume_inbound_player_spawn.rs
- crates/mcrs_minecraft_engine_player/src/publish_player_tiles.rs
- crates/mcrs_minecraft_engine_player/src/publish_pose.rs
- crates/mcrs_minecraft_engine_mob_attributes/src/mob_defence.rs
- crates/mcrs_minecraft_engine_entity_motion_replication/src/mob_news.rs
- crates/mcrs_minecraft_engine_entity_motion_replication/src/publish_motion.rs
- crates/mcrs_minecraft_vanilla_respawn/src/request_respawns.rs
- crates/mcrs_minecraft_vanilla_respawn/src/spawn_site.rs
- crates/mcrs_minecraft_vanilla_death/src/death_messages_plugin.rs
- crates/mcrs_minecraft_vanilla_death/src/describe_player_deaths.rs
- crates/mcrs_minecraft_vanilla_death/src/announce_deaths.rs
- crates/mcrs_minecraft_vanilla_player_attack/src/player_attack_plugin.rs
- crates/mcrs_minecraft_vanilla_player_attack/src/attack_packet.rs
- crates/mcrs_minecraft_vanilla_player_attack/src/attack_amount.rs
- crates/mcrs_minecraft_vanilla_player_attack/src/knock_back.rs
- crates/mcrs_minecraft_command_engine/src/plugin.rs
- crates/mcrs_minecraft_command_engine/src/executor.rs
- crates/mcrs_minecraft_command_vanilla/src/mob_hit.rs
- crates/mcrs_minecraft_command_vanilla/src/damage.rs
- crates/mcrs_minecraft_command_vanilla/src/kill.rs
- crates/mcrs_minecraft_server/src/lib.rs
- crates/mcrs_minecraft_server/tests/it/player_attack.rs
- crates/mcrs_minecraft_server/tests/it/respawn.rs
- crates/mcrs_minecraft_server/tests/it/death_messages.rs
- PR #1078
- PR #1082
- PR #1084
- PR #1106
Related open issues: