Class DamageSystems
Damage is handled by systems queuing up damage events (attaching any metadata they need at the time) and then other systems processing that data either by cancelling it, modifying it or just inspecting it before finally it is applied to the entity.
In order for this to work predictably the process is split up into phases. The phases are as followed:
- Gather Phase
This phase is where any system that wishes to deal damage should be. Systems here should only submit damage events (using methods such as
executeDamage(int, ArchetypeChunk, CommandBuffer, Damage).Systems within this phase should set their group to
DamageModule.getGatherDamageGroup(). - Filter Phase
This phase is where any system that wishes to modify or cancel damage should be. Systems here should query damage events via the damage parameter and use the setters on
Damageto change the result.At this point systems must not submit any new damage events otherwise they could be skipped by other filter systems that have already run.
Whilst systems here may inspect the current state of the entries to use for any calculations they need they must not consider these results final as they may be modified/cancelled later.
Systems within this phase should set their group to
DamageModule.getFilterDamageGroup(). - Application phase
This phase is internal and should not be added to. This phase takes all the remaining damage events and applies them to the entity.
If you need to inspect the entity after the damage then you can depend on the system
DamageSystems.ApplyDamage. - Inspect Phase
This phase is where any system that wishes to act on damage events (without modification) should be. Systems here should query damage events via the damage parameter and use the getters on
Damageto view the result.The damage will not have been applied to the entity yet but is final and will not change at this point. Systems in this phase must not change anything to do with damage at this point as other systems may not see the changes made at this point.
Systems within this phase should set their group to
DamageModule.getInspectDamageGroup().
Once done the damage events will be cleared ready for the next tick.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAn entity ticking system that handles the final step of damage processing.static classAn entity ticking system that plays any effects for damage withDamage.IMPACT_PARTICLES.static classAn entity ticking system that plays any effects for damage withDamage.IMPACT_SOUND_EFFECT.static classDeprecated.Move to modifiersstatic classDeprecated.Move to modifiersstatic classA delayed entity system that tracks the block material and fluid at each entity's breathing height.static classA system that handles applying damage to an entity if the entity has run out of oxygen.static classstatic classstatic classstatic classstatic classAn entity ticking system that handles applying fall damage to NPC entities.static classWe have both FallDamagePlayers and FallDamageNPCs because player movement is client authoritative so we need to handle things differently and use the input queue.static classA DamageEventSystem that cancels damage for NPCs when the GameplayConfig dictates sostatic classA DamageEventSystem that cancels damage for players when the GameplayConfig dictates sostatic classAn entity ticking system that cancels damage events on unkillable entities.static classDeprecated.This is a hack to modify knockback on NPCs/players before the physics rework unifies bothstatic classAn entity ticking system that handles displaying the hit animations to damaged entities.static classA ref change system that reprocesses an entity's breathing state when anInvulnerablecomponent is added, set, or removed.static classA delayed entity system that handles applying out of world damage to entities that are below the world.static classA damage event system that handles damage filtering for player entities.static classAn entity ticking system that handles displaying hit indicators upon damage dealt to a player entity.static classAn entity ticking system that updatesDamageDataComponentwith the last combat time for any entities involved in combat.static classstatic classDeprecated.Move to modifiersstatic classAn entity ticking system that keeps track of the last time that damage was received.static classstatic classDeprecated.Move to modifiers -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexecuteDamage(int index, ArchetypeChunk<EntityStore> chunk, CommandBuffer<EntityStore> commandBuffer, Damage damage) Called to queue the given damage entry onto the given entity.static voidexecuteDamage(Ref<EntityStore> ref, CommandBuffer<EntityStore> commandBuffer, Damage damage) Called to queue the given damage entry onto the given entity.static voidexecuteDamage(Ref<EntityStore> ref, ComponentAccessor<EntityStore> componentAccessor, Damage damage) Called to queue the given damage entry onto the given entity.
-
Field Details
-
DEFAULT_DAMAGE_DELAY
public static final float DEFAULT_DAMAGE_DELAY- See Also:
-
-
Constructor Details
-
DamageSystems
public DamageSystems()
-
-
Method Details
-
executeDamage
public static void executeDamage(@Nonnull Ref<EntityStore> ref, @Nonnull ComponentAccessor<EntityStore> componentAccessor, @Nonnull Damage damage) Called to queue the given damage entry onto the given entity.- Parameters:
ref- The entity reference of the entity to queue the damage for.componentAccessor- TheComponentAccessor<EntityStore>for component access.damage- TheDamageentry to be queued.
-
executeDamage
public static void executeDamage(int index, @Nonnull ArchetypeChunk<EntityStore> chunk, @Nonnull CommandBuffer<EntityStore> commandBuffer, @Nonnull Damage damage) Called to queue the given damage entry onto the given entity.- Parameters:
index- The index of the entity to queue the damage for.chunk- The archetype chunk that the entity is associated with.commandBuffer- TheCommandBuffer<EntityStore>for component access.damage- TheDamageentry to be queued.
-
executeDamage
public static void executeDamage(@Nonnull Ref<EntityStore> ref, @Nonnull CommandBuffer<EntityStore> commandBuffer, @Nonnull Damage damage) Called to queue the given damage entry onto the given entity.- Parameters:
ref- The entity reference of the entity to queue the damage for.commandBuffer- TheCommandBuffer<EntityStore>for component access.damage- TheDamageentry to be queued.
-