aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/resource_location.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-core/src/resource_location.rs')
-rwxr-xr-xazalea-core/src/resource_location.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs
index cdf8f381..acca0c58 100755
--- a/azalea-core/src/resource_location.rs
+++ b/azalea-core/src/resource_location.rs
@@ -1,5 +1,8 @@
//! A resource, like minecraft:stone
+use azalea_buf::{McBufReadable, McBufWritable};
+use std::io::{Read, Write};
+
#[derive(Hash, Clone, PartialEq, Eq)]
pub struct ResourceLocation {
pub namespace: String,
@@ -42,8 +45,22 @@ impl std::fmt::Debug for ResourceLocation {
}
}
+impl McBufReadable for ResourceLocation {
+ fn read_into(buf: &mut impl Read) -> Result<Self, String> {
+ let location_string = String::read_into(buf)?;
+ ResourceLocation::new(&location_string)
+ }
+}
+impl McBufWritable for ResourceLocation {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ self.to_string().write_into(buf)
+ }
+}
+
#[cfg(test)]
mod tests {
+ use std::io::Cursor;
+
use super::*;
#[test]
@@ -70,4 +87,20 @@ mod tests {
assert_eq!(r.namespace, "azalea");
assert_eq!(r.path, "");
}
+
+ #[test]
+ fn mcbuf_resource_location() {
+ let mut buf = Vec::new();
+ ResourceLocation::new("minecraft:dirt")
+ .unwrap()
+ .write_into(&mut buf)
+ .unwrap();
+
+ let mut buf = Cursor::new(buf);
+
+ assert_eq!(
+ ResourceLocation::read_into(&mut buf).unwrap(),
+ ResourceLocation::new("minecraft:dirt").unwrap()
+ );
+ }
}