pub struct DamageSource {
pub damage_type: &'static DamageType,
causing_entity: Option<SharedEntity>,
direct_entity: Option<SharedEntity>,
source_position: Option<DVec3>,
}Expand description
Describes damage while retaining the exact direct and causing entity allocations.
Removal and respawn never rebind attribution. Store recent sources in
super::DamageHistory to avoid self/mutual ownership cycles.
Fields§
§damage_type: &'static DamageTypeThe damage type registry entry.
causing_entity: Option<SharedEntity>§direct_entity: Option<SharedEntity>§source_position: Option<DVec3>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 fn direct(damage_type: &'static DamageType, entity: SharedEntity) -> Self
pub fn direct(damage_type: &'static DamageType, entity: SharedEntity) -> Self
Damage delivered directly by its causing entity.
Sourcepub fn with_causing_entity(self, entity: SharedEntity) -> Self
pub fn with_causing_entity(self, entity: SharedEntity) -> Self
Adds the entity ultimately responsible for the damage.
Sourcepub fn with_direct_entity(self, entity: SharedEntity) -> Self
pub fn with_direct_entity(self, entity: SharedEntity) -> Self
Adds the direct entity that delivered the damage.
Sourcepub const fn causing_entity(&self) -> Option<&SharedEntity>
pub const fn causing_entity(&self) -> Option<&SharedEntity>
The original cause (e.g. a projectile’s shooter), retained after removal.
Sourcepub const fn direct_entity(&self) -> Option<&SharedEntity>
pub const fn direct_entity(&self) -> Option<&SharedEntity>
The original direct entity (e.g. the projectile), retained after removal.
Sourcepub fn source_position(&self) -> Option<DVec3>
pub fn source_position(&self) -> Option<DVec3>
The explicit source position, or the direct entity’s position when none was set. Distinct from the raw position sent in packets.
Sourcepub const fn source_position_raw(&self) -> Option<DVec3>
pub const fn source_position_raw(&self) -> Option<DVec3>
The explicit source position without the direct-entity fallback, used by the damage-event packet.
Sourcepub fn is_creative_player(&self) -> bool
pub fn is_creative_player(&self) -> bool
Whether the causing player has vanilla infinite-materials abilities.
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 fn is_direct(&self) -> bool
pub fn is_direct(&self) -> bool
Whether the damage was dealt directly by the causing entity rather than indirectly, e.g. by a thrown projectile.
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) -> bool
pub fn scales_with_difficulty(&self) -> bool
Whether this damage scales with difficulty for the retained causing entity.
Trait Implementations§
Source§impl Clone for DamageSource
impl Clone for DamageSource
Auto Trait Implementations§
impl !RefUnwindSafe for DamageSource
impl !UnwindSafe for DamageSource
impl Freeze for DamageSource
impl Send for DamageSource
impl Sync for DamageSource
impl Unpin for DamageSource
impl UnsafeUnpin 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<>>