pub struct DataComponentPatch {
pub(super) 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 + DowncastType>(
&mut self,
component: DataComponentType<T>,
value: T,
)
pub fn set<T: Component + DowncastType>( &mut self, component: DataComponentType<T>, value: T, )
Sets a component value in the patch.
pub(crate) fn set_component_data( &mut self, key: Identifier, data: ComponentData, )
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<T>(&mut self, component: DataComponentType<T>)
pub fn remove<T>(&mut self, component: DataComponentType<T>)
Marks a component as removed.
Sourcepub fn remove_raw(&mut self, key: Identifier) -> bool
pub fn remove_raw(&mut self, key: Identifier) -> bool
Marks a dynamically resolved 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 apply(&mut self, added: &Self)
pub fn apply(&mut self, added: &Self)
Applies another patch after this one, giving the added patch precedence.
pub(crate) fn sanitize_against(&mut self, prototype: &DataComponentMap)
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.
Source§impl DataComponentPatch
impl DataComponentPatch
Sourcepub(crate) fn compute_single_extracted_hash<T: HashComponent>(
key: &Identifier,
value: &T,
) -> i32
pub(crate) fn compute_single_extracted_hash<T: HashComponent>( key: &Identifier, value: &T, ) -> i32
Computes the persistent map hash for one build-time validated component without consulting the not-yet-published global registry.
Sourcepub fn compute_persistent_hash(&self) -> Result<i32>
pub fn compute_persistent_hash(&self) -> Result<i32>
Computes Vanilla’s HashOps value for the persistent patch codec.
Sourcepub fn iter_removed(&self) -> impl Iterator<Item = &Identifier>
pub fn iter_removed(&self) -> impl Iterator<Item = &Identifier>
Iterates over removed component keys.
fn encode_nbt(&self, validate: bool) -> (OwnedNbtTag, Vec<Error>)
Sourcepub fn try_to_nbt_tag_ref(&self) -> Result<OwnedNbtTag>
pub fn try_to_nbt_tag_ref(&self) -> Result<OwnedNbtTag>
Strictly encodes this component patch through its persistent codecs.
This is the equivalent of Vanilla encoding an untrusted stack through
ItemStack.CODEC before accepting it into server state.
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.
Save-time encoding mirrors Vanilla’s TagValueOutput: invalid fields
are reported and omitted from the partial result rather than aborting
the owner save.
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 EmbeddedNbtCodec for &DataComponentPatch
impl EmbeddedNbtCodec for &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§impl ReadFrom for DataComponentPatch
impl ReadFrom for DataComponentPatch
impl StructuralPartialEq for DataComponentPatch
Source§impl ToNbtTag for DataComponentPatch
impl ToNbtTag for DataComponentPatch
fn to_nbt_tag(self) -> OwnedNbtTag
fn to_optional_nbt_tag(self) -> Option<NbtTag>
Auto Trait Implementations§
impl !RefUnwindSafe for DataComponentPatch
impl !UnwindSafe for DataComponentPatch
impl Freeze for DataComponentPatch
impl Send for DataComponentPatch
impl Sync for DataComponentPatch
impl Unpin for DataComponentPatch
impl UnsafeUnpin for DataComponentPatch
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<>>