Interface DamageSource


public interface DamageSource
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.

Sources are immutable and created by the server: get them from CombatService.sources().

Since:
0.1.0
See Also:
  • Method Details

    • type

      Returns the registry key of the damage type backing this source.
      Returns:
      the registry key of the damage type backing this source
      Since:
      0.1.0
    • causingEntity

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

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

      @Nullable Location position()
      Returns the origin used to orient the hurt animation and the knockback, or null to derive it from directEntity().
      Returns:
      the origin used to orient the hurt animation and the knockback, or null to derive it from directEntity()
      Since:
      0.1.0
    • weapon

      ItemStack weapon()
      Returns the item the hit was dealt with: the weapon of a melee hit, the bow or crossbow that shot an arrow, the thrown trident; ItemStack.EMPTY when there is none.
      Returns:
      the item the hit was dealt with: the weapon of a melee hit, the bow or crossbow that shot an arrow, the thrown trident; ItemStack.EMPTY when there is none
      Since:
      0.1.0
    • is

      boolean is(TagKey<DamageType> tag)
      Returns true if the damage type of this source is in a damage type tag.
      Parameters:
      tag - the tag, for instance DamageTypeTagKeys.BYPASSES_ARMOR
      Returns:
      true if the damage type of this source is in a damage type tag
      Since:
      0.1.0
    • isDirect

      boolean isDirect()
      Returns true if the entity credited with the hit is the one that touched the victim, as for a melee hit.
      Returns:
      true if the entity credited with the hit is the one that touched the victim, as for a melee hit
      Since:
      0.1.0
    • withPosition

      DamageSource withPosition(Location position)
      Returns a copy of this source whose hit comes from position.
      Parameters:
      position - the point the damage comes from, used for the hurt animation and the knockback
      Returns:
      a copy of this source whose hit comes from position
      Since:
      0.1.0
    • withWeapon

      DamageSource withWeapon(ItemStack weapon)
      Returns a copy of this source dealt with weapon.
      Parameters:
      weapon - the item the hit was dealt with, ItemStack.EMPTY for none
      Returns:
      a copy of this source dealt with weapon
      Since:
      0.1.0