From 833f306e8b8faddd232b5c736b2134ed08adcb6c Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Fri, 21 Feb 2025 13:43:56 -0600 Subject: Fix errors on switching dimensions (#204) * Fix errors on switching dimensions * fix other tests * clippy * fix log feature in test_simulation * fix chunks oops --- azalea-core/src/data_registry.rs | 22 +++++++++++++++++++++- azalea-core/src/registry_holder.rs | 5 +++++ 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'azalea-core/src') 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( + &self, + registries: &RegistryHolder, + ) -> Option> { + 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 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>, -- cgit v1.2.3