diff options
| author | mat <git@matdoes.dev> | 2024-12-05 06:30:47 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2024-12-05 06:30:47 +0000 |
| commit | 39f4d68e1ff1f0fa0d45663335d83299d5d37790 (patch) | |
| tree | ac61d7bf437a1874c91d5c794b732dc599f86259 /azalea-core/src | |
| parent | 6379035b852f1b619565d27f5cee3b93042c2312 (diff) | |
| download | azalea-drasl-39f4d68e1ff1f0fa0d45663335d83299d5d37790.tar.xz | |
fix container_set_content, player_position, and recipe_book_remove packets
Diffstat (limited to 'azalea-core/src')
| -rw-r--r-- | azalea-core/src/math.rs | 9 | ||||
| -rwxr-xr-x | azalea-core/src/position.rs | 18 |
2 files changed, 27 insertions, 0 deletions
diff --git a/azalea-core/src/math.rs b/azalea-core/src/math.rs index 7c0ac7b4..62215749 100644 --- a/azalea-core/src/math.rs +++ b/azalea-core/src/math.rs @@ -68,6 +68,15 @@ pub fn fract(x: f64) -> f64 { x - floor } +// these are copied from the java standard library, we don't calculate the +// consts ourself to make sure it's the same as java +pub fn to_radians(degrees: f64) -> f64 { + degrees * 0.017453292519943295 +} +pub fn to_degrees(radians: f64) -> f64 { + radians * 57.29577951308232 +} + #[cfg(test)] mod tests { use super::*; diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 5948203f..9b800e28 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -13,6 +13,7 @@ use std::{ use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use crate::math; use crate::resource_location::ResourceLocation; macro_rules! vec3_impl { @@ -233,6 +234,23 @@ impl Vec3 { pub fn distance_to(&self, other: &Self) -> f64 { (self - other).length() } + + pub fn x_rot(self, radians: f32) -> Vec3 { + let x_delta = math::cos(radians); + let y_delta = math::sin(radians); + let x = self.x; + let y = self.y * (x_delta as f64) + self.z * (y_delta as f64); + let z = self.z * (x_delta as f64) - self.y * (y_delta as f64); + Vec3 { x, y, z } + } + pub fn y_rot(self, radians: f32) -> Vec3 { + let x_delta = math::cos(radians); + let y_delta = math::sin(radians); + let x = self.x * (x_delta as f64) + self.z * (y_delta as f64); + let y = self.y; + let z = self.z * (x_delta as f64) - self.x * (y_delta as f64); + Vec3 { x, y, z } + } } /// The coordinates of a block in the world. For entities (if the coordinate |
