diff options
| author | mat <27899617+mat-1@users.noreply.github.com> | 2022-11-12 23:54:05 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-12 23:54:05 -0600 |
| commit | 6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc (patch) | |
| tree | a5e493ccd7ec24293b8d866242c3836146517122 /azalea-core/src/direction.rs | |
| parent | fa57d03627aa20b1df44caed7cb025b6db1d9b53 (diff) | |
| download | azalea-drasl-6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc.tar.xz | |
Pathfinder (#25)
Pathfinding is very much not done, but it works enough and I want to get this merged.
TODO: fast replanning, goals that aren't a single node, falling moves (it should be able to play the dropper), parkour moves
Diffstat (limited to 'azalea-core/src/direction.rs')
| -rwxr-xr-x[-rw-r--r--] | azalea-core/src/direction.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/azalea-core/src/direction.rs b/azalea-core/src/direction.rs index 22a19ee0..5a7f601a 100644..100755 --- a/azalea-core/src/direction.rs +++ b/azalea-core/src/direction.rs @@ -13,6 +13,15 @@ pub enum Direction { East, } +// TODO: make azalea_block use this instead of FacingCardinal +#[derive(Clone, Copy, Debug, McBuf)] +pub enum CardinalDirection { + North, + South, + West, + East, +} + #[derive(Clone, Copy, Debug)] pub enum Axis { X = 0, @@ -27,6 +36,55 @@ pub enum AxisCycle { Backward = 2, } +impl CardinalDirection { + #[inline] + pub fn x(self) -> i32 { + match self { + CardinalDirection::East => 1, + CardinalDirection::West => -1, + _ => 0, + } + } + #[inline] + pub fn z(self) -> i32 { + match self { + CardinalDirection::South => 1, + CardinalDirection::North => -1, + _ => 0, + } + } + + pub fn iter() -> impl Iterator<Item = CardinalDirection> { + [ + CardinalDirection::North, + CardinalDirection::South, + CardinalDirection::West, + CardinalDirection::East, + ] + .iter() + .copied() + } + + #[inline] + pub fn right(self) -> CardinalDirection { + match self { + CardinalDirection::North => CardinalDirection::East, + CardinalDirection::South => CardinalDirection::West, + CardinalDirection::West => CardinalDirection::North, + CardinalDirection::East => CardinalDirection::South, + } + } + #[inline] + pub fn left(self) -> CardinalDirection { + match self { + CardinalDirection::North => CardinalDirection::West, + CardinalDirection::South => CardinalDirection::East, + CardinalDirection::West => CardinalDirection::South, + CardinalDirection::East => CardinalDirection::North, + } + } +} + impl Axis { /// Pick x, y, or z from the arguments depending on the axis. #[inline] |
