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 Summary
Modifier and TypeMethodDescriptionReturns the entity credited with the damage, ornullfor environmental damage.Returns the entity that dealt the hit directly, ornullfor environmental damage.booleanis(TagKey<DamageType> tag) Returnstrueif the damage type of this source is in a damage type tag.booleanisDirect()Returnstrueif the entity credited with the hit is the one that touched the victim, as for a melee hit.position()Returns the origin used to orient the hurt animation and the knockback, ornullto derive it fromdirectEntity().type()Returns the registry key of the damage type backing this source.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.EMPTYwhen there is none.withPosition(Location position) Returns a copy of this source whose hit comes fromposition.withWeapon(ItemStack weapon) Returns a copy of this source dealt withweapon.
-
Method Details
-
type
TypedKey<DamageType> 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
-
directEntity
-
position
Returns the origin used to orient the hurt animation and the knockback, ornullto derive it fromdirectEntity().- Returns:
- the origin used to orient the hurt animation and the knockback, or
nullto derive it fromdirectEntity() - 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.EMPTYwhen 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.EMPTYwhen there is none - Since:
- 0.1.0
-
is
Returnstrueif the damage type of this source is in a damage type tag.- Parameters:
tag- the tag, for instanceDamageTypeTagKeys.BYPASSES_ARMOR- Returns:
trueif the damage type of this source is in a damage type tag- Since:
- 0.1.0
-
isDirect
boolean isDirect()Returnstrueif the entity credited with the hit is the one that touched the victim, as for a melee hit.- Returns:
trueif the entity credited with the hit is the one that touched the victim, as for a melee hit- Since:
- 0.1.0
-
withPosition
Returns a copy of this source whose hit comes fromposition.- 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
Returns a copy of this source dealt withweapon.- Parameters:
weapon- the item the hit was dealt with,ItemStack.EMPTYfor none- Returns:
- a copy of this source dealt with
weapon - Since:
- 0.1.0
-