diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2023-03-07 22:09:56 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-07 22:09:56 -0600 |
| commit | 5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea (patch) | |
| tree | 72719e46479e7884ea535c768ab7c244ce048063 /azalea-core | |
| parent | 719379a8a76ab0685f2bd14bebe2f0cd1e97f06b (diff) | |
| download | azalea-drasl-5dd35c7ed82c38ef36ca28f630e8d05c5db2cbea.tar.xz | |
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
Diffstat (limited to 'azalea-core')
| -rwxr-xr-x | azalea-core/src/position.rs | 18 |
1 files changed, 17 insertions, 1 deletions
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<ChunkPos> 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)] |
