diff --git a/schemsearch-files/Cargo.toml b/schemsearch-files/Cargo.toml
index 76d6ddf..cfaaff8 100644
--- a/schemsearch-files/Cargo.toml
+++ b/schemsearch-files/Cargo.toml
@@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
flate2 = "1.0.25"
-hematite-nbt = "0.5.2"
+fastnbt = "2.4.3"
serde = "1.0.152"
serde_json = "1.0.84"
diff --git a/schemsearch-files/src/lib.rs b/schemsearch-files/src/lib.rs
index cd1efe3..719d47f 100644
--- a/schemsearch-files/src/lib.rs
+++ b/schemsearch-files/src/lib.rs
@@ -15,17 +15,21 @@
* along with this program. If not, see .
*/
+use std::collections::HashMap;
use std::io::Read;
use std::path::PathBuf;
-use nbt::{Error, from_gzip_reader, Map, Value};
+use fastnbt::error::Error;
+use fastnbt::Value;
+use flate2::read::GzDecoder;
use serde::{Deserialize, Deserializer, Serialize};
+use serde::de::value::MapDeserializer;
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
struct SchematicRaw {
version: i32,
#[serde(flatten)]
- data: Map,
+ data: HashMap,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
@@ -74,7 +78,7 @@ impl SchematicVersioned {
}
#[inline]
- pub fn get_palette(&self) -> &Map {
+ pub fn get_palette(&self) -> &HashMap {
return match self {
SchematicVersioned::V1(schematic) => &schematic.palette,
SchematicVersioned::V2(schematic) => &schematic.palette,
@@ -105,15 +109,15 @@ impl From for SchematicVersioned {
fn from(value: SchematicRaw) -> Self {
match value.version {
1 => {
- let schematic: SpongeV1Schematic = serde_json::from_value(serde_json::to_value(value.data).unwrap()).unwrap();
+ let schematic: SpongeV1Schematic = SpongeV1Schematic::deserialize(MapDeserializer::new(value.data.into_iter())).unwrap();
return SchematicVersioned::V1(schematic);
},
2 => {
- let schematic: SpongeV2Schematic = serde_json::from_value(serde_json::to_value(value.data).unwrap()).unwrap();
+ let schematic: SpongeV2Schematic = SpongeV2Schematic::deserialize(MapDeserializer::new(value.data.into_iter())).unwrap();
return SchematicVersioned::V2(schematic);
},
3 => {
- let schematic: SpongeV3Schematic = serde_json::from_value(serde_json::to_value(value.data).unwrap()).unwrap();
+ let schematic: SpongeV3Schematic = SpongeV3Schematic::deserialize(MapDeserializer::new(value.data.into_iter())).unwrap();
return SchematicVersioned::V3(schematic);
}
_ => panic!("Unknown Schematic Version: {}", value.version),
@@ -124,13 +128,13 @@ impl From for SchematicVersioned {
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct SpongeV1Schematic {
- pub metadata: Map,
+ pub metadata: HashMap,
pub width: u16,
pub height: u16,
pub length: u16,
pub offset: [i32; 3],
pub palette_max: i32,
- pub palette: Map,
+ pub palette: HashMap,
#[serde(deserialize_with = "read_blockdata")]
pub block_data: Vec,
pub tile_entities: Vec,
@@ -140,13 +144,13 @@ pub struct SpongeV1Schematic {
#[serde(rename_all = "PascalCase")]
pub struct SpongeV2Schematic {
pub data_version: i32,
- pub metadata: Map,
+ pub metadata: HashMap,
pub width: u16,
pub height: u16,
pub length: u16,
pub offset: [i32; 3],
pub palette_max: i32,
- pub palette: Map,
+ pub palette: HashMap,
#[serde(deserialize_with = "read_blockdata")]
pub block_data: Vec,
pub block_entities: Vec,
@@ -157,7 +161,7 @@ pub struct SpongeV2Schematic {
#[serde(rename_all = "PascalCase")]
pub struct SpongeV3Schematic {
pub data_version: i32,
- pub metadata: Map,
+ pub metadata: HashMap,
pub width: u16,
pub height: u16,
pub length: u16,
@@ -169,7 +173,7 @@ pub struct SpongeV3Schematic {
#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "PascalCase")]
pub struct BlockContainer {
- pub palette: Map,
+ pub palette: HashMap,
#[serde(deserialize_with = "read_blockdata")]
pub block_data: Vec,
pub block_entities: Vec,
@@ -195,7 +199,7 @@ pub struct BlockEntity {
pub struct BlockEntityV3 {
pub id: String,
pub pos: [i32; 3],
- pub data: Map,
+ pub data: HashMap,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -207,7 +211,7 @@ pub struct Entity {
impl SchematicVersioned {
pub fn load_data(data: R) -> Result where R: Read {
- let raw: SchematicRaw = from_gzip_reader(data)?;
+ let raw: SchematicRaw = fastnbt::from_reader(GzDecoder::new(data))?;
Ok(SchematicVersioned::from(raw))
}