mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
Do not deserialize full registry by default (#83)
* Do not deserialize full registry by default * Only need height and min_y
This commit is contained in:
parent
cd0a1ed8d4
commit
1ff2495962
1 changed files with 27 additions and 29 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue