aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/difficulty.rs
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-25 14:25:56 -0500
committermat <github@matdoes.dev>2022-06-25 14:25:56 -0500
commitc46eb556e2e7964f0709572a0151c181752c3182 (patch)
treeda65427d74aaa66e002385989faee04c7bac6cbd /azalea-core/src/difficulty.rs
parent8755f18c2b0c11a51a81f60b5501d9d57d0c370e (diff)
parent77980f0018eca3a192994021b76ad5d05bff88ea (diff)
downloadazalea-drasl-c46eb556e2e7964f0709572a0151c181752c3182.tar.xz
Merge branch 'main' into 1.19.1
Diffstat (limited to 'azalea-core/src/difficulty.rs')
-rwxr-xr-xazalea-core/src/difficulty.rs27
1 files changed, 22 insertions, 5 deletions
diff --git a/azalea-core/src/difficulty.rs b/azalea-core/src/difficulty.rs
index 5d869325..718359f3 100755
--- a/azalea-core/src/difficulty.rs
+++ b/azalea-core/src/difficulty.rs
@@ -1,11 +1,16 @@
-use std::fmt::{Debug, Error, Formatter};
+use std::{
+ fmt::{Debug, Error, Formatter},
+ io::{Read, Write},
+};
+
+use azalea_buf::{McBufReadable, McBufWritable};
#[derive(Hash, Clone, Debug, PartialEq)]
pub enum Difficulty {
- PEACEFUL,
- EASY,
- NORMAL,
- HARD,
+ PEACEFUL = 0,
+ EASY = 1,
+ NORMAL = 2,
+ HARD = 3,
}
pub enum Err {
@@ -61,6 +66,18 @@ impl Difficulty {
}
}
+impl McBufReadable for Difficulty {
+ fn read_from(buf: &mut impl Read) -> Result<Self, String> {
+ Ok(Difficulty::by_id(u8::read_from(buf)?))
+ }
+}
+
+impl McBufWritable for Difficulty {
+ fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
+ u8::write_into(&self.id(), buf)
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;