When an entity dies in Hytale, the DeathComponent is attached to it carrying the cause of death, the death message, item loss data, and respawn control. Your death screen, kill feed, item recovery system, and custom respawn logic all depend on reading this component correctly.
Testing death and respawn is critical because getDeathCause() returns a DamageCause index, not the DamageCause object itself. If you read it wrong, your kill feed shows “Unknown” for every death. Automated tests catch this before your players do.
Death assertions require entities with stat components (EntityStatMap, DeathComponent). Always use spawnNPC with a valid role name - empty entities created with ctx.createEntity() lack the required components.
Complete Example Suite
DeathComponent API
The DeathComponent is the ECS component Hytale attaches to dead entities. Key methods:
| Method | Returns | Description |
|---|
getDeathCause() | death cause info | The damage cause that killed the entity |
getDeathMessage() | String | The death message for the kill feed |
setDeathMessage(String) | void | Override the death message |
isShowDeathMenu() | boolean | Whether to show the death/respawn UI |
setShowDeathMenu(boolean) | void | Control death menu visibility |
getItemsLostOnDeath() | items | Items the entity drops on death |
setItemsLostOnDeath(...) | void | Override dropped items |
getDeathItemLoss() | DeathItemLoss | Item loss configuration |
respawn() | void | Static method to trigger respawn |
DeathItemLoss API
DeathItemLoss controls what items a player loses when they die:
| Method | Returns | Description |
|---|
getLossMode() | loss mode | How items are lost (all, percentage, none) |
getItemsLost() | items | Which items are marked for loss |
getAmountLossPercentage() | float | Percentage of stack amounts lost |
getDurabilityLossPercentage() | float | Percentage of durability lost |
noLossMode() | DeathItemLoss | Static factory for zero item loss |
DamageSystems Pipeline
Use DamageSystems.executeDamage() instead of manually subtracting health. The damage pipeline runs resistances, triggers events, and processes death correctly:
DamageModule.get() - returns the singleton
DamageModule.getGatherDamageGroup() - first stage, collects damage sources
DamageModule.getFilterDamageGroup() - second stage, applies resistances
DamageModule.getInspectDamageGroup() - final stage, logs and triggers events
Isolation Recommendation
Death tests mutate entity state heavily. Use IsolationStrategy.DEDICATED_WORLD:
Next Steps