pub struct DataComponentPatch {
entries: FxHashMap<Identifier, ComponentPatchEntry>,
}Expand description
A patch representing modifications to a DataComponentMap.
Stores differences from a prototype:
- Components that are added or overridden (
Set) - Components that are explicitly removed (
Removed)
Fields§
§entries: FxHashMap<Identifier, ComponentPatchEntry>Implementations§
Source§impl DataComponentPatch
impl DataComponentPatch
pub fn new() -> Self
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub fn set<T: Component>(&mut self, component: DataComponentType<T>, value: T)
pub fn set<T: Component>(&mut self, component: DataComponentType<T>, value: T)
Sets a component value in the patch.
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, false if the data type
doesn’t match the registered component type (validation failed).
This prevents plugins from setting invalid types on vanilla components.
Sourcepub fn remove<T>(&mut self, component: DataComponentType<T>)
pub fn remove<T>(&mut self, component: DataComponentType<T>)
Marks a component as removed.
Sourcepub fn clear<T>(&mut self, component: DataComponentType<T>)
pub fn clear<T>(&mut self, component: DataComponentType<T>)
Clears any patch entry for a component.
Sourcepub fn get_entry(&self, key: &Identifier) -> Option<&ComponentPatchEntry>
pub fn get_entry(&self, key: &Identifier) -> Option<&ComponentPatchEntry>
Gets the patch entry for a key.
Sourcepub fn is_removed(&self, key: &Identifier) -> bool
pub fn is_removed(&self, key: &Identifier) -> bool
Checks if a component is marked as removed.
Sourcepub fn count_removed(&self) -> usize
pub fn count_removed(&self) -> usize
Counts removed entries.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&Identifier, &ComponentPatchEntry)>
pub fn iter(&self) -> impl Iterator<Item = (&Identifier, &ComponentPatchEntry)>
Iterates over all entries.
Sourcepub fn iter_removed(&self) -> impl Iterator<Item = &Identifier>
pub fn iter_removed(&self) -> impl Iterator<Item = &Identifier>
Iterates over removed component keys.
Sourcepub fn to_nbt_tag_ref(&self) -> OwnedNbtTag
pub fn to_nbt_tag_ref(&self) -> OwnedNbtTag
Converts this component patch to NBT without consuming it.
Source§impl DataComponentPatch
impl DataComponentPatch
Sourcepub fn read_delimited(data: &mut Cursor<&[u8]>) -> Result<Self>
pub fn read_delimited(data: &mut Cursor<&[u8]>) -> Result<Self>
Reads a patch where each component value is prefixed with a VarInt byte length.
Vanilla uses this for untrusted client packets (e.g., creative mode slot)
via DataComponentPatch.DELIMITED_STREAM_CODEC.
Trait Implementations§
Source§impl Clone for DataComponentPatch
impl Clone for DataComponentPatch
Source§fn clone(&self) -> DataComponentPatch
fn clone(&self) -> DataComponentPatch
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 DataComponentPatch
impl Debug for DataComponentPatch
Source§impl Default for DataComponentPatch
impl Default for DataComponentPatch
Source§fn default() -> DataComponentPatch
fn default() -> DataComponentPatch
Source§impl FromNbtTag for DataComponentPatch
impl FromNbtTag for DataComponentPatch
fn from_nbt_tag(tag: BorrowedNbtTag<'_, '_>) -> Option<Self>
fn from_optional_nbt_tag( tag: Option<NbtTag<'_, '_>>, ) -> Result<Option<Self>, DeserializeError>
Source§impl PartialEq for DataComponentPatch
impl PartialEq for DataComponentPatch
Source§fn eq(&self, other: &DataComponentPatch) -> bool
fn eq(&self, other: &DataComponentPatch) -> bool
self and other values to be equal, and is used by ==.