diff options
| author | EightFactorial <29801334+EightFactorial@users.noreply.github.com> | 2023-03-12 18:49:10 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-12 20:49:10 -0500 |
| commit | 1ff24959627d03d7b2491ad3111d270ef128a4be (patch) | |
| tree | 9d6c7f5171c2a9677e6e1bd99eecf01f77fc8ee9 /azalea-protocol/src | |
| parent | cd0a1ed8d4c7670eb58d33f521026e760798e1a5 (diff) | |
| download | azalea-drasl-1ff24959627d03d7b2491ad3111d270ef128a4be.tar.xz | |
Do not deserialize full registry by default (#83)
* Do not deserialize full registry by default
* Only need height and min_y
Diffstat (limited to 'azalea-protocol/src')
| -rwxr-xr-x | azalea-protocol/src/packets/game/clientbound_login_packet.rs | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/azalea-protocol/src/packets/game/clientbound_login_packet.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs index de5444b8..03edbea5 100755 --- a/azalea-protocol/src/packets/game/clientbound_login_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs @@ -95,12 +95,24 @@ pub mod registry { #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "strict_registry", serde(deny_unknown_fields))] pub struct RegistryRoot { + #[cfg(feature = "strict_registry")] #[serde(rename = "minecraft:chat_type")] pub chat_type: RegistryType<ChatTypeElement>, + + #[cfg(not(feature = "strict_registry"))] + #[serde(rename = "minecraft:chat_type")] + pub chat_type: Tag, + #[serde(rename = "minecraft:dimension_type")] pub dimension_type: RegistryType<DimensionTypeElement>, + + #[cfg(feature = "strict_registry")] #[serde(rename = "minecraft:worldgen/biome")] pub world_type: RegistryType<WorldTypeElement>, + + #[cfg(not(feature = "strict_registry"))] + #[serde(rename = "minecraft:worldgen/biome")] + pub world_type: Tag, } /// A collection of values for a certain type of registry data. @@ -170,8 +182,9 @@ pub mod registry { } /// Dimension attributes. + #[cfg(feature = "strict_registry")] #[derive(Debug, Clone, Serialize, Deserialize)] - #[cfg_attr(feature = "strict_registry", serde(deny_unknown_fields))] + #[serde(deny_unknown_fields)] pub struct DimensionTypeElement { pub ambient_light: f32, #[serde(with = "Convert")] @@ -203,6 +216,14 @@ pub mod registry { pub ultrawarm: bool, } + /// Dimension attributes. + #[cfg(not(feature = "strict_registry"))] + #[derive(Debug, Clone, Serialize, Deserialize)] + pub struct DimensionTypeElement { + pub height: u32, + pub min_y: i32, + } + /// The light level at which monsters can spawn. /// /// This can be either a single minimum value, or a formula with a min and @@ -412,29 +433,22 @@ pub mod registry { #[cfg(test)] mod tests { - use super::registry::{ - ChatTypeElement, DimensionTypeElement, RegistryHolder, RegistryRoot, RegistryType, - WorldTypeElement, - }; + use super::registry::{DimensionTypeElement, RegistryHolder, RegistryRoot, RegistryType}; use azalea_core::ResourceLocation; use azalea_nbt::Tag; #[test] fn test_convert() { + // Do NOT use Tag::End, they should be Tag::Compound. + // This is just for testing. let registry = RegistryHolder { root: RegistryRoot { - chat_type: RegistryType::<ChatTypeElement> { - kind: ResourceLocation::new("minecraft:chat_type").unwrap(), - value: Vec::new(), - }, + chat_type: Tag::End, dimension_type: RegistryType::<DimensionTypeElement> { kind: ResourceLocation::new("minecraft:dimension_type").unwrap(), value: Vec::new(), }, - world_type: RegistryType::<WorldTypeElement> { - kind: ResourceLocation::new("minecraft:worldgen/biome").unwrap(), - value: Vec::new(), - }, + world_type: Tag::End, }, }; @@ -447,14 +461,6 @@ mod tests { .as_compound() .unwrap(); - let chat = root - .get("minecraft:chat_type") - .unwrap() - .as_compound() - .unwrap(); - let chat_type = chat.get("type").unwrap().as_string().unwrap(); - assert!(chat_type == "minecraft:chat_type"); - let dimension = root .get("minecraft:dimension_type") .unwrap() @@ -462,13 +468,5 @@ mod tests { .unwrap(); let dimension_type = dimension.get("type").unwrap().as_string().unwrap(); assert!(dimension_type == "minecraft:dimension_type"); - - let world = root - .get("minecraft:worldgen/biome") - .unwrap() - .as_compound() - .unwrap(); - let world_type = world.get("type").unwrap().as_string().unwrap(); - assert!(world_type == "minecraft:worldgen/biome"); } } |
