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)
      Creates a source for damage radiating from a point, such as an explosion.
      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
      Returns:
      the source
      Since:
      0.1.0
    • playerAttack

      public static DamageSource playerAttack(Player attacker)
      Returns a source for damage dealt by a player melee hit.
      Parameters:
      attacker - the attacking player
      Returns:
      a source for damage dealt by a player melee hit
      Since:
      0.1.0
    • mobAttack

      public static DamageSource mobAttack(@Nullable Entity attacker)
      Returns a source for damage dealt by a mob melee hit.
      Parameters:
      attacker - the attacking mob, or null
      Returns:
      a source for damage dealt by a mob melee hit
      Since:
      0.1.0
    • fall

      public static DamageSource fall()
      Returns a source for damage dealt by falling.
      Returns:
      a source for damage dealt by falling
      Since:
      0.1.0
    • drown

      public static DamageSource drown()
      Returns a source for damage dealt by drowning.
      Returns:
      a source for damage dealt by drowning
      Since:
      0.1.0
    • lava

      public static DamageSource lava()
      Returns a source for damage dealt by standing in lava.
      Returns:
      a source for damage dealt by standing in lava
      Since:
      0.1.0
    • inFire

      public static DamageSource inFire()
      Returns a source for damage dealt by standing in fire.
      Returns:
      a source for damage dealt by standing in fire
      Since:
      0.1.0
    • onFire

      public static DamageSource onFire()
      Returns a source for damage dealt by burning.
      Returns:
      a source for damage dealt by burning
      Since:
      0.1.0
    • cactus

      public static DamageSource cactus()
      Returns a source for damage dealt by touching a cactus.
      Returns:
      a source for damage dealt by touching a cactus
      Since:
      0.1.0
    • starve

      public static DamageSource starve()
      Returns a source for damage dealt by starving.
      Returns:
      a source for damage dealt by starving
      Since:
      0.1.0
    • outOfWorld

      public static DamageSource outOfWorld()
      Returns a source for damage dealt by falling out of the world.
      Returns:
      a source for damage dealt by falling out of the world
      Since:
      0.1.0
    • generic

      public static DamageSource generic()
      Returns a source for damage dealt by an unspecified cause.
      Returns:
      a source for damage dealt by an unspecified cause
      Since:
      0.1.0
    • 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