diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2025-02-21 13:43:56 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-21 13:43:56 -0600 |
| commit | 833f306e8b8faddd232b5c736b2134ed08adcb6c (patch) | |
| tree | 08a59009f3118d5c56891d6c4fb6a0293aa9e6fc /azalea-core/src | |
| parent | 63b1036a96c45b0fefc6ca2501f1cc479acc95de (diff) | |
| download | azalea-drasl-833f306e8b8faddd232b5c736b2134ed08adcb6c.tar.xz | |
Fix errors on switching dimensions (#204)
* Fix errors on switching dimensions
* fix other tests
* clippy
* fix log feature in test_simulation
* fix chunks oops
Diffstat (limited to 'azalea-core/src')
| -rw-r--r-- | azalea-core/src/data_registry.rs | 22 | ||||
| -rw-r--r-- | azalea-core/src/registry_holder.rs | 5 |
2 files changed, 26 insertions, 1 deletions
diff --git a/azalea-core/src/data_registry.rs b/azalea-core/src/data_registry.rs index a72d9caf..6e2c29ff 100644 --- a/azalea-core/src/data_registry.rs +++ b/azalea-core/src/data_registry.rs @@ -1,4 +1,4 @@ -use std::str::FromStr; +use std::{io::Cursor, str::FromStr}; use azalea_registry::DataRegistry; use simdnbt::owned::NbtCompound; @@ -23,5 +23,25 @@ pub trait ResolvableDataRegistry: DataRegistry { let resolved = registry_values.get_index(self.protocol_id() as usize)?; Some(resolved) } + + fn resolve_and_deserialize<T: simdnbt::Deserialize>( + &self, + registries: &RegistryHolder, + ) -> Option<Result<(ResourceLocation, T), simdnbt::DeserializeError>> { + let (name, value) = self.resolve(registries)?; + + let mut nbt_bytes = Vec::new(); + value.write(&mut nbt_bytes); + let nbt_borrow_compound = + simdnbt::borrow::read_compound(&mut Cursor::new(&nbt_bytes)).ok()?; + let value = match T::from_compound((&nbt_borrow_compound).into()) { + Ok(value) => value, + Err(err) => { + return Some(Err(err)); + } + }; + + Some(Ok((name.clone(), value))) + } } impl<T: DataRegistry> ResolvableDataRegistry for T {} diff --git a/azalea-core/src/registry_holder.rs b/azalea-core/src/registry_holder.rs index ec57eacc..b2f1f5b9 100644 --- a/azalea-core/src/registry_holder.rs +++ b/azalea-core/src/registry_holder.rs @@ -19,6 +19,11 @@ use crate::resource_location::ResourceLocation; /// The base of the registry. /// /// This is the registry that is sent to the client upon login. +/// +/// Note that `azalea-client` stores registries per-world instead of per-client +/// like you might expect. This is an optimization for swarms to reduce memory +/// usage, since registries are expected to be the same for every client in a +/// world. #[derive(Default, Debug, Clone)] pub struct RegistryHolder { pub map: HashMap<ResourceLocation, IndexMap<ResourceLocation, NbtCompound>>, |
