From 881989a7bcdcfdc612d36bba2dadeb5bfe28566d Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sun, 4 May 2025 20:26:26 +0200 Subject: [PATCH] Refactor NBT handling for version 3 schematics Update logic to process "Schematic" key in NBT for version 3, ensuring compatibility with nested tags. Adjust function signatures to pass CompoundTag references, optimizing data handling and reducing unnecessary clones. --- schemsearch-files/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/schemsearch-files/src/lib.rs b/schemsearch-files/src/lib.rs index c1dda3f..ec2a44d 100644 --- a/schemsearch-files/src/lib.rs +++ b/schemsearch-files/src/lib.rs @@ -65,7 +65,7 @@ impl SpongeSchematic { pub fn load_data(data: &mut R) -> Result where R: Read { let nbt: CompoundTag = nbt::decode::read_gzip_compound_tag(data).map_err(|e| e.to_string())?; let version = nbt.get_i32("Version").unwrap_or_else(|_| { - return if nbt.contains_key("Blocks") { + return if nbt.contains_key("Schematic") { 3 } else if nbt.contains_key("BlockEntities") { 2 @@ -79,7 +79,7 @@ impl SpongeSchematic { match version { 1 => SpongeSchematic::from_nbt_1(nbt), 2 => SpongeSchematic::from_nbt_2(nbt), - 3 => SpongeSchematic::from_nbt_3(nbt), + 3 => SpongeSchematic::from_nbt_3(nbt.get_compound_tag("Schematic").map_err(|e| e.to_string())?), _ => Err("Invalid schematic: Unknown Version".to_string()), } } @@ -121,7 +121,7 @@ impl SpongeSchematic { }) } - pub fn from_nbt_3(nbt: CompoundTag) -> Result { + pub fn from_nbt_3(nbt: &CompoundTag) -> Result { let blocks = nbt.get_compound_tag("Blocks").map_err(|e| e.to_string())?; Ok(Self{ data_version: nbt.get_i32("DataVersion").map_err(|e| e.to_string())?,