diff options
Diffstat (limited to 'azalea-core/src/position.rs')
| -rwxr-xr-x | azalea-core/src/position.rs | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 819d72cf..cba58415 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -8,11 +8,12 @@ use std::{ fmt, hash::Hash, io::{Cursor, Write}, - ops::{Add, AddAssign, Mul, Rem, Sub}, + ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, Sub}, }; use azalea_buf::{AzBuf, AzaleaRead, AzaleaWrite, BufReadError}; +use crate::direction::Direction; use crate::math; use crate::resource_location::ResourceLocation; @@ -138,7 +139,6 @@ macro_rules! vec3_impl { } } } - impl Add for $name { type Output = $name; @@ -147,6 +147,18 @@ macro_rules! vec3_impl { (&self).add(&rhs) } } + impl Add<$type> for $name { + type Output = Self; + + #[inline] + fn add(self, rhs: $type) -> Self::Output { + Self { + x: self.x + rhs, + y: self.y + rhs, + z: self.z + rhs, + } + } + } impl AddAssign for $name { #[inline] @@ -203,6 +215,35 @@ macro_rules! vec3_impl { } } } + impl MulAssign<$type> for $name { + #[inline] + fn mul_assign(&mut self, multiplier: $type) { + self.x *= multiplier; + self.y *= multiplier; + self.z *= multiplier; + } + } + + impl Div<$type> for $name { + type Output = Self; + + #[inline] + fn div(self, divisor: $type) -> Self::Output { + Self { + x: self.x / divisor, + y: self.y / divisor, + z: self.z / divisor, + } + } + } + impl DivAssign<$type> for $name { + #[inline] + fn div_assign(&mut self, divisor: $type) { + self.x /= divisor; + self.y /= divisor; + self.z /= divisor; + } + } impl From<($type, $type, $type)> for $name { #[inline] @@ -345,6 +386,10 @@ impl BlockPos { z: self.z.max(other.z), } } + + pub fn offset_with_direction(self, direction: Direction) -> Self { + self + direction.normal() + } } /// Chunk coordinates are used to represent where a chunk is in the world. You |
