Class DamageSystems

java.lang.Object
com.hypixel.hytale.server.core.modules.entity.damage.DamageSystems

public class DamageSystems extends Object
Systems for handling and processing damage to entities.

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:

  1. 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().

  2. 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 Damage to 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().

  3. 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.

  4. 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 Damage to 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.

  • Field Details

  • 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 - The ComponentAccessor<EntityStore> for component access.
      damage - The Damage entry 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 - The CommandBuffer<EntityStore> for component access.
      damage - The Damage entry 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 - The CommandBuffer<EntityStore> for component access.
      damage - The Damage entry to be queued.