Skip to main content

DataComponentRegistry

Struct DataComponentRegistry 

Source
pub struct DataComponentRegistry {
    entries: Vec<ComponentEntryRef>,
    by_key: FxHashMap<Identifier, usize>,
    allows_registering: bool,
}
Expand description

Registry of all data component types.

Stores metadata about each component type including how to serialize/deserialize them for network and persistent storage.

Fields§

§entries: Vec<ComponentEntryRef>

Component entries indexed by network ID

§by_key: FxHashMap<Identifier, usize>

Map from component key to network ID

§allows_registering: bool

Whether registration is still allowed

Implementations§

Source§

impl DataComponentRegistry

Source

pub fn new() -> Self

Source

pub fn register<T>( &mut self, component: DataComponentType<T>, expected_discriminant: ComponentDataDiscriminant, )
where T: 'static + Component + WriteTo + ReadFrom + ToNbtTag + FromNbtTag,

Registers a vanilla component type.

The component type T must implement the necessary serialization traits. This creates the appropriate reader/writer functions automatically.

Source

pub fn register_custom_network<T>( &mut self, component: DataComponentType<T>, expected_discriminant: ComponentDataDiscriminant, network_reader: NetworkReader, network_writer: NetworkWriter, )
where T: 'static + Component + ToNbtTag + FromNbtTag,

Registers a component with custom network reader/writer functions.

Use this when the default WriteTo/ReadFrom implementations don’t match the network encoding (e.g., VarInt-encoded i32 components). NBT serialization still uses the type’s ToNbtTag/FromNbtTag impls.

Source

pub fn register_dynamic( &mut self, key: Identifier, expected_discriminant: ComponentDataDiscriminant, network_reader: NetworkReader, network_writer: NetworkWriter, nbt_reader: NbtReader, nbt_writer: NbtWriter, ) -> usize

Registers a dynamic/plugin component type.

Plugin components use the ComponentData::Other variant and handle their own serialization. The provided functions read/write raw bytes.

Source

pub fn get_id<T>(&self, component: DataComponentType<T>) -> Option<usize>

Gets the network ID for a component type.

Source

pub fn get_key_by_id(&self, id: usize) -> Option<&Identifier>

Gets the component key by network ID.

Trait Implementations§

Source§

impl Default for DataComponentRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl RegistryExt for DataComponentRegistry

Source§

type Entry = ComponentEntry

Source§

fn freeze(&mut self)

Source§

fn by_id(&self, id: usize) -> Option<&'static ComponentEntry>

Source§

fn by_key(&self, key: &Identifier) -> Option<&'static ComponentEntry>

Source§

fn id_from_key(&self, key: &Identifier) -> Option<usize>

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more