pub struct DamageSource {
pub damage_type: &'static DamageType,
pub causing_entity_id: Option<i32>,
pub direct_entity_id: Option<i32>,
pub source_position: Option<DVec3>,
}Expand description
Describes how an entity was damaged.
Fields§
§damage_type: &'static DamageTypeThe damage type registry entry.
causing_entity_id: Option<i32>The entity ultimately responsible (e.g. the shooter for projectiles).
direct_entity_id: Option<i32>The entity that directly dealt the damage (e.g. the projectile itself).
source_position: Option<DVec3>Source position (for explosions, etc.).
Implementations§
Source§impl DamageSource
impl DamageSource
Sourcepub const fn environment(damage_type: &'static DamageType) -> Self
pub const fn environment(damage_type: &'static DamageType) -> Self
Environmental damage with no entity or position context (void, starvation, etc.).
Sourcepub const fn with_causing_entity(self, entity_id: i32) -> Self
pub const fn with_causing_entity(self, entity_id: i32) -> Self
Adds the entity ultimately responsible for the damage.
Sourcepub const fn with_direct_entity(self, entity_id: i32) -> Self
pub const fn with_direct_entity(self, entity_id: i32) -> Self
Adds the direct entity that delivered the damage.
Sourcepub const fn with_source_position(self, source_position: DVec3) -> Self
pub const fn with_source_position(self, source_position: DVec3) -> Self
Adds the vanilla source position used by damage events and knockback.
Sourcepub fn bypasses_invulnerability(&self) -> bool
pub fn bypasses_invulnerability(&self) -> bool
Whether this damage bypasses creative/spectator invulnerability.
Sourcepub fn is(&self, tag: &Identifier) -> bool
pub fn is(&self, tag: &Identifier) -> bool
Returns whether this damage type is in the given vanilla damage-type tag.
Sourcepub const fn bypasses_cooldown(&self) -> bool
pub const fn bypasses_cooldown(&self) -> bool
Whether this damage bypasses the invulnerability cooldown timer.
No vanilla damage types currently use this, but the logic exists in
LivingEntity.hurtServer().
TODO: use damage type tag query once supported
Sourcepub fn scales_with_difficulty(
&self,
causing_entity: Option<&dyn Entity>,
) -> bool
pub fn scales_with_difficulty( &self, causing_entity: Option<&dyn Entity>, ) -> bool
Whether this damage scales with world difficulty for the resolved causing entity.
causing_entity is None when the source has no cause or its stored entity ID no
longer resolves. Both cases fail Vanilla’s living non-player type check.
Trait Implementations§
Source§impl Clone for DamageSource
impl Clone for DamageSource
Source§fn clone(&self) -> DamageSource
fn clone(&self) -> DamageSource
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for DamageSource
impl RefUnwindSafe for DamageSource
impl Send for DamageSource
impl Sync for DamageSource
impl Unpin for DamageSource
impl UnsafeUnpin for DamageSource
impl UnwindSafe for DamageSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreArc<SyncMutex<>>