From 5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:09:56 -0600 Subject: Add World::find_block (#80) * start adding World::find_block * keep working on find_block * BlockStates * fix sorting * update examples that use find_one_block * azalea_block::properties * fix tests * add a gotoblock command to testbot --- azalea-core/src/position.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'azalea-core/src') diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs index 5ba7143e..3c452d3a 100755 --- a/azalea-core/src/position.rs +++ b/azalea-core/src/position.rs @@ -12,6 +12,8 @@ macro_rules! vec3_impl { Self { x, y, z } } + /// Get the distance of this vector to the origin by doing `x^2 + y^2 + + /// z^2`. pub fn length_sqr(&self) -> $type { self.x * self.x + self.y * self.y + self.z * self.z } @@ -139,6 +141,11 @@ impl BlockPos { z: self.z as f64 + 0.5, } } + + /// Get the distance of this vector from the origin by doing `x + y + z`. + pub fn length_manhattan(&self) -> u32 { + (self.x.abs() + self.y.abs() + self.z.abs()) as u32 + } } /// Chunk coordinates are used to represent where a chunk is in the world. You @@ -148,12 +155,21 @@ pub struct ChunkPos { pub x: i32, pub z: i32, } - impl ChunkPos { pub fn new(x: i32, z: i32) -> Self { ChunkPos { x, z } } } +impl Add for ChunkPos { + type Output = Self; + + fn add(self, rhs: Self) -> Self::Output { + Self { + x: self.x + rhs.x, + z: self.z + rhs.z, + } + } +} /// The coordinates of a chunk section in the world. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] -- cgit v1.2.3