pub struct DataComponentMap {
pub(super) map: FxHashMap<Identifier, ComponentData>,
}Expand description
Storage for component values.
Maps component keys to their values. Used on items to store their data components.
Fields§
§map: FxHashMap<Identifier, ComponentData>Implementations§
Source§impl DataComponentMap
impl DataComponentMap
pub fn new() -> Self
Sourcepub fn common_item_components() -> Self
pub fn common_item_components() -> Self
Creates a map with common item components pre-populated.
Sourcepub fn builder_set<T: Component + DowncastType>(
self,
component: DataComponentType<T>,
value: Option<T>,
) -> Self
pub fn builder_set<T: Component + DowncastType>( self, component: DataComponentType<T>, value: Option<T>, ) -> Self
Sets a component value (builder pattern).
Sourcepub fn set<T: Component + DowncastType>(
&mut self,
component: DataComponentType<T>,
value: Option<T>,
)
pub fn set<T: Component + DowncastType>( &mut self, component: DataComponentType<T>, value: Option<T>, )
Sets a component value, or removes it if None.
Sourcepub fn get<T: Component + DowncastType + Clone>(
&self,
component: DataComponentType<T>,
) -> Option<T>
pub fn get<T: Component + DowncastType + Clone>( &self, component: DataComponentType<T>, ) -> Option<T>
Gets a component value by type.
Sourcepub fn get_ref<T: Component + DowncastType>(
&self,
component: DataComponentType<T>,
) -> Option<&T>
pub fn get_ref<T: Component + DowncastType>( &self, component: DataComponentType<T>, ) -> Option<&T>
Gets a reference to a component value.
Sourcepub fn has<T>(&self, component: DataComponentType<T>) -> bool
pub fn has<T>(&self, component: DataComponentType<T>) -> bool
Checks if a component is present.
Sourcepub fn keys(&self) -> impl Iterator<Item = &Identifier>
pub fn keys(&self) -> impl Iterator<Item = &Identifier>
Iterates over component keys.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Identifier, &ComponentData)>
pub fn iter(&self) -> impl Iterator<Item = (&Identifier, &ComponentData)>
Iterates over component keys and their erased values.
Sourcepub fn get_raw(&self, key: &Identifier) -> Option<&ComponentData>
pub fn get_raw(&self, key: &Identifier) -> Option<&ComponentData>
Gets raw component data by key (for plugin use).
Sourcepub fn set_raw(&mut self, key: Identifier, data: ComponentData) -> bool
pub fn set_raw(&mut self, key: Identifier, data: ComponentData) -> bool
Sets raw component data (for plugin use).
Returns true if the data was set successfully, or false if the key is
unregistered or the data type does not match it.
This prevents plugins from setting invalid types on vanilla components.
Sourcepub fn remove(&mut self, key: &Identifier) -> Option<ComponentData>
pub fn remove(&mut self, key: &Identifier) -> Option<ComponentData>
Removes a component by key.
Source§impl DataComponentMap
impl DataComponentMap
fn as_patch(&self) -> DataComponentPatch
Sourcepub fn try_to_nbt_tag_ref(&self) -> Result<OwnedNbtTag>
pub fn try_to_nbt_tag_ref(&self) -> Result<OwnedNbtTag>
Strictly encodes this component map through its persistent codecs.
Sourcepub fn to_nbt_tag_ref(&self) -> OwnedNbtTag
pub fn to_nbt_tag_ref(&self) -> OwnedNbtTag
Encodes this component map while reporting and omitting invalid values.
Trait Implementations§
Source§impl Clone for DataComponentMap
impl Clone for DataComponentMap
Source§fn clone(&self) -> DataComponentMap
fn clone(&self) -> DataComponentMap
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DataComponentMap
impl Debug for DataComponentMap
Source§impl Default for DataComponentMap
impl Default for DataComponentMap
Source§impl FromNbtTag for DataComponentMap
impl FromNbtTag for DataComponentMap
fn from_nbt_tag(tag: BorrowedNbtTag<'_, '_>) -> Option<Self>
fn from_optional_nbt_tag( tag: Option<NbtTag<'_, '_>>, ) -> Result<Option<Self>, DeserializeError>
Auto Trait Implementations§
impl !RefUnwindSafe for DataComponentMap
impl !UnwindSafe for DataComponentMap
impl Freeze for DataComponentMap
impl Send for DataComponentMap
impl Sync for DataComponentMap
impl Unpin for DataComponentMap
impl UnsafeUnpin for DataComponentMap
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<>>