aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/difficulty.rs
diff options
context:
space:
mode:
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..ebbb7708 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_into(buf: &mut impl Read) -> Result<Self, String> {
+ Ok(Difficulty::by_id(u8::read_into(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::*;