diff options
Diffstat (limited to 'azalea-client/src/received_registries.rs')
| -rw-r--r-- | azalea-client/src/received_registries.rs | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/azalea-client/src/received_registries.rs b/azalea-client/src/received_registries.rs index 845527ae..024f5222 100644 --- a/azalea-client/src/received_registries.rs +++ b/azalea-client/src/received_registries.rs @@ -1,7 +1,28 @@ -use azalea_protocol::packets::game::clientbound_login_packet::registry::RegistryRoot; -use bevy_ecs::component::Component; -use derive_more::Deref; +use std::collections::HashMap; -/// The registries that the server sent us on login. -#[derive(Clone, Debug, Component, Deref)] -pub struct ReceivedRegistries(pub RegistryRoot); +use azalea_core::ResourceLocation; +use azalea_nbt::Nbt; +use azalea_protocol::packets::configuration::clientbound_registry_data_packet::registry::{ + DimensionTypeElement, RegistryType, +}; +use bevy_ecs::prelude::*; +use serde::de::DeserializeOwned; + +/// The registries that were sent to us during the configuration state. +#[derive(Default, Component, Clone)] +pub struct ReceivedRegistries { + pub registries: HashMap<ResourceLocation, Nbt>, +} + +impl ReceivedRegistries { + fn get<T: DeserializeOwned>(&self, name: &ResourceLocation) -> Option<T> { + let nbt = self.registries.get(name)?; + serde_json::from_value(serde_json::to_value(nbt).ok()?).ok() + } + + /// Get the dimension type registry, or `None` if it doesn't exist. You + /// should do some type of error handling if this returns `None`. + pub fn dimension_type(&self) -> Option<RegistryType<DimensionTypeElement>> { + self.get(&ResourceLocation::new("minecraft:dimension_type")) + } +} |
