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: boolWhether registration is still allowed
Implementations§
Source§impl DataComponentRegistry
impl DataComponentRegistry
pub fn new() -> Self
Sourcepub fn register<T>(
&mut self,
component: DataComponentType<T>,
expected_discriminant: ComponentDataDiscriminant,
)
pub fn register<T>( &mut self, component: DataComponentType<T>, expected_discriminant: ComponentDataDiscriminant, )
Registers a vanilla component type.
The component type T must implement the necessary serialization traits.
This creates the appropriate reader/writer functions automatically.
Sourcepub 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,
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.
Sourcepub fn register_dynamic(
&mut self,
key: Identifier,
expected_discriminant: ComponentDataDiscriminant,
network_reader: NetworkReader,
network_writer: NetworkWriter,
nbt_reader: NbtReader,
nbt_writer: NbtWriter,
) -> usize
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.
Sourcepub fn get_id<T>(&self, component: DataComponentType<T>) -> Option<usize>
pub fn get_id<T>(&self, component: DataComponentType<T>) -> Option<usize>
Gets the network ID for a component type.
Sourcepub fn get_key_by_id(&self, id: usize) -> Option<&Identifier>
pub fn get_key_by_id(&self, id: usize) -> Option<&Identifier>
Gets the component key by network ID.