pub struct AttributeMap {
instances: Vec<Option<AttributeInstance>>,
to_update: DirtySet,
to_sync: DirtySet,
}Expand description
Per-entity container for attribute instances with dirty tracking
Indexed by attribute registry ID. Two dirty sets match vanilla’s design:
to_update: all dirty attributes, drained for server-side effectsto_sync: syncable dirty attributes, drained for network packets
Fields§
§instances: Vec<Option<AttributeInstance>>§to_update: DirtySet§to_sync: DirtySetImplementations§
Source§impl AttributeMap
impl AttributeMap
Sourcepub fn new_for_entity(entity_type: EntityTypeRef) -> Self
pub fn new_for_entity(entity_type: EntityTypeRef) -> Self
Creates an AttributeMap from an entity type’s default attributes
§Panics
Panics if generated entity default attributes reference an attribute that is missing from the generated vanilla registry.
Sourcepub fn has_attribute(&self, attribute: AttributeRef) -> bool
pub fn has_attribute(&self, attribute: AttributeRef) -> bool
Returns true if the entity has this attribute registered
Sourcepub fn get_value(&self, attribute: AttributeRef) -> Option<f64>
pub fn get_value(&self, attribute: AttributeRef) -> Option<f64>
Gets the calculated value of an attribute
Sourcepub fn required_value(&self, attribute: AttributeRef) -> f64
pub fn required_value(&self, attribute: AttributeRef) -> f64
Gets the calculated value of an attribute that must exist on this entity.
§Panics
Panics if the entity type was not constructed with the requested
attribute. Vanilla’s AttributeSupplier.getValue is a hard failure for
missing attributes; using this keeps required living attributes from
silently falling back to unrelated defaults.
Sourcepub fn get_base_value(&self, attribute: AttributeRef) -> Option<f64>
pub fn get_base_value(&self, attribute: AttributeRef) -> Option<f64>
Gets the base value of an attribute
Sourcepub fn get_instance(
&self,
attribute: AttributeRef,
) -> Option<&AttributeInstance>
pub fn get_instance( &self, attribute: AttributeRef, ) -> Option<&AttributeInstance>
Gets a reference to an attribute instance
Sourcepub(crate) fn to_vanilla_nbt(&self) -> NbtList
pub(crate) fn to_vanilla_nbt(&self) -> NbtList
Serializes the vanilla LivingEntity.attributes list.
Sourcepub fn has_modifier(
&self,
attribute: AttributeRef,
modifier_id: &Identifier,
) -> bool
pub fn has_modifier( &self, attribute: AttributeRef, modifier_id: &Identifier, ) -> bool
Returns whether an attribute has a modifier with the given ID.
Sourcepub fn set_base_value(&mut self, attribute: AttributeRef, value: f64)
pub fn set_base_value(&mut self, attribute: AttributeRef, value: f64)
Sets the base value of an attribute
Sourcepub fn add_modifier(
&mut self,
attribute: AttributeRef,
modifier: AttributeModifier,
persistent: bool,
) -> bool
pub fn add_modifier( &mut self, attribute: AttributeRef, modifier: AttributeModifier, persistent: bool, ) -> bool
Adds a modifier to an attribute. Returns false if the modifier ID already exists
Sourcepub fn set_modifier(
&mut self,
attribute: AttributeRef,
modifier: AttributeModifier,
persistent: bool,
)
pub fn set_modifier( &mut self, attribute: AttributeRef, modifier: AttributeModifier, persistent: bool, )
Adds or replaces a modifier on an attribute
Sourcepub fn remove_modifier(
&mut self,
attribute: AttributeRef,
modifier_id: &Identifier,
) -> bool
pub fn remove_modifier( &mut self, attribute: AttributeRef, modifier_id: &Identifier, ) -> bool
Removes a modifier from an attribute. Returns true if it existed
fn mark_dirty(&mut self, id: usize, attribute: AttributeRef)
Sourcepub fn has_dirty_updates(&self) -> bool
pub fn has_dirty_updates(&self) -> bool
Returns true if there are dirty attributes needing server-side effects
Sourcepub fn has_dirty_sync(&self) -> bool
pub fn has_dirty_sync(&self) -> bool
Returns true if there are syncable dirty attributes needing network send
Sourcepub fn drain_dirty_updates(&mut self) -> Vec<AttributeRef> ⓘ
pub fn drain_dirty_updates(&mut self) -> Vec<AttributeRef> ⓘ
Drains to_update and returns the dirty attribute refs
Sourcepub fn drain_dirty_sync(&mut self) -> Vec<AttributeSnapshot>
pub fn drain_dirty_sync(&mut self) -> Vec<AttributeSnapshot>
Drains to_sync and builds AttributeSnapshots for CUpdateAttributes
Sourcepub fn syncable_snapshots(&self) -> Vec<AttributeSnapshot>
pub fn syncable_snapshots(&self) -> Vec<AttributeSnapshot>
Returns snapshots for ALL syncable attributes (initial tracking sync)
Sourcepub fn remove_all_transient(&mut self)
pub fn remove_all_transient(&mut self)
Removes all transient modifiers (e.g. on respawn)
Auto Trait Implementations§
impl Freeze for AttributeMap
impl RefUnwindSafe for AttributeMap
impl Send for AttributeMap
impl Sync for AttributeMap
impl Unpin for AttributeMap
impl UnsafeUnpin for AttributeMap
impl UnwindSafe for AttributeMap
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
§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<>>