Skip to content

Commit

Permalink
Add angle type
Browse files Browse the repository at this point in the history
  • Loading branch information
ya7on committed Feb 25, 2024
1 parent 3c95504 commit 40926b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Minecraft data types

mod angle;
pub(crate) mod base;
mod bitset;
mod boolean;
Expand All @@ -20,6 +21,7 @@ mod uuid;
mod varint;
mod vec;

pub use angle::MCAngle;
pub use bitset::MCBitSet;
pub use boolean::MCBoolean;
pub use byte::MCByte;
Expand Down
24 changes: 24 additions & 0 deletions src/types/angle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::utils::TcpUtils;
use crate::MCType;
use std::fmt::Debug;
use std::io::Read;

#[derive(Debug, Clone)]
pub struct MCAngle(pub i8);

impl MCAngle {
/// From -360 to 360
pub fn from_degrees(deegree: i16) -> Self {
Self((deegree % 360 / 360 * 256) as i8)
}
}

impl MCType for MCAngle {
fn pack(&self) -> Vec<u8> {
vec![self.0 as u8]
}

fn unpack(src: &mut dyn Read) -> Self {
Self(src.read_byte() as i8)
}
}

0 comments on commit 40926b5

Please sign in to comment.