aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/resource_location.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-06-25 05:09:26 +0000
committerGitHub <noreply@github.com>2022-06-25 05:09:26 +0000
commit7d3e57763e32ac9cf94180b1c714704cfbc3034d (patch)
tree2dcfe72bf09a42f6614f9dc988dc0254162ea0bf /azalea-core/src/resource_location.rs
parent69c47eda4c496b13dadd80976bffd2fab7ea5894 (diff)
parentca7067e173129f3044ebc8c77634f06da29a086e (diff)
downloadazalea-drasl-7d3e57763e32ac9cf94180b1c714704cfbc3034d.tar.xz
Merge pull request #10 from mat-1/azalea-entity
azalea-entity
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()
+ );
+ }
}