Class DamageSource

java.lang.Object
fr.fidorial.combat.DamageSource

public final class DamageSource extends Object
Describes where a hit came from.

A source carries the minecraft:damage_type used by the client to pick the death message and the screen tint, plus the entities involved. causingEntity() is the entity credited with the kill (the shooter), while directEntity() is what actually touched the victim (the arrow). For a melee hit both are the same entity.

Since:
0.1.0
  • Method Details

    • of

      public static DamageSource of(TypedKey<DamageType> type)
      Parameters:
      type - the minecraft:damage_type to report to the client
      Returns:
      an environmental source with no entity attached
      Since:
      0.1.0
    • of

      public static DamageSource of(TypedKey<DamageType> type, @Nullable Entity source)
      Parameters:
      type - the minecraft:damage_type to report to the client
      source - the entity responsible for the hit
      Since:
      0.1.0
    • of

      public static DamageSource of(TypedKey<DamageType> type, @Nullable Entity causing, @Nullable Entity direct)
      Parameters:
      type - the minecraft:damage_type to report to the client
      causing - the entity credited with the kill, typically the shooter
      direct - the entity that physically hit the victim, typically the projectile
      Since:
      0.1.0
    • at

      public static DamageSource at(TypedKey<DamageType> type, Location position)
      Parameters:
      type - the minecraft:damage_type to report to the client
      position - the point the damage radiated from, used by the client for the hit direction
      Since:
      0.1.0
    • playerAttack

      public static DamageSource playerAttack(Player attacker)
    • mobAttack

      public static DamageSource mobAttack(@Nullable Entity attacker)
    • fall

      public static DamageSource fall()
    • drown

      public static DamageSource drown()
    • lava

      public static DamageSource lava()
    • inFire

      public static DamageSource inFire()
    • onFire

      public static DamageSource onFire()
    • cactus

      public static DamageSource cactus()
    • starve

      public static DamageSource starve()
    • outOfWorld

      public static DamageSource outOfWorld()
    • generic

      public static DamageSource generic()
    • type

      public TypedKey<DamageType> type()
      Returns:
      the registry key of the damage type backing this source
    • causingEntity

      public @Nullable Entity causingEntity()
      Returns:
      the entity credited with the damage, or null for environmental damage
    • directEntity

      public @Nullable Entity directEntity()
      Returns:
      the entity that dealt the hit directly, or null for environmental damage
    • position

      public @Nullable Location position()
      Returns:
      the origin used to orient the hurt animation, or null to derive it from directEntity()
    • bypassesArmor

      public boolean bypassesArmor()
      Returns:
      true when armour points do not reduce this damage
    • bypassesInvulnerability

      public boolean bypassesInvulnerability()
      Returns:
      true when this damage ignores both invulnerability frames and creative mode
    • isFire

      public boolean isFire()
      Returns:
      true when this damage counts as fire for resistances and effects
    • isProjectile

      public boolean isProjectile()
      Returns:
      true when the hit came from a projectile
    • noKnockback

      public boolean noKnockback()
      Returns:
      true when this damage must never push the victim around
    • withPosition

      public DamageSource withPosition(Location position)
      Returns:
      the source with position attached, used to orient the hurt animation
    • toString

      public String toString()
      Overrides:
      toString in class Object