aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src/direction.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2025-01-10 16:45:27 -0600
committerGitHub <noreply@github.com>2025-01-10 16:45:27 -0600
commit0d16f01571ec8315f3979eae46981e559ade1cf9 (patch)
treeea43c32a57b0e6a67579d75a134dfbc009d09781 /azalea-core/src/direction.rs
parent615d8f9d2ac56b3244d328587243301da253eafd (diff)
downloadazalea-drasl-0d16f01571ec8315f3979eae46981e559ade1cf9.tar.xz
Fluid physics (#199)
* start implementing fluid physics * Initial implementation of fluid pushing * different travel function in water * bubble columns * jumping in water * cleanup * change ultrawarm to be required * fix for clippy
Diffstat (limited to 'azalea-core/src/direction.rs')
-rwxr-xr-xazalea-core/src/direction.rs43
1 files changed, 34 insertions, 9 deletions
diff --git a/azalea-core/src/direction.rs b/azalea-core/src/direction.rs
index 6ff55615..d458f487 100755
--- a/azalea-core/src/direction.rs
+++ b/azalea-core/src/direction.rs
@@ -1,6 +1,6 @@
use azalea_buf::AzBuf;
-use crate::position::Vec3;
+use crate::position::{BlockPos, Vec3};
#[derive(Clone, Copy, Debug, AzBuf, Default, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
@@ -15,6 +15,14 @@ pub enum Direction {
}
impl Direction {
+ pub const HORIZONTAL: [Direction; 4] = [
+ Direction::North,
+ Direction::South,
+ Direction::West,
+ Direction::East,
+ ];
+ pub const VERTICAL: [Direction; 2] = [Direction::Down, Direction::Up];
+
pub fn nearest(vec: Vec3) -> Direction {
let mut best_direction = Direction::North;
let mut best_direction_amount = 0.0;
@@ -29,7 +37,7 @@ impl Direction {
]
.iter()
{
- let amount = dir.normal().dot(vec);
+ let amount = dir.normal_vec3().dot(vec);
if amount > best_direction_amount {
best_direction = *dir;
best_direction_amount = amount;
@@ -39,17 +47,23 @@ impl Direction {
best_direction
}
- pub fn normal(self) -> Vec3 {
+ #[inline]
+ pub fn normal(self) -> BlockPos {
match self {
- Direction::Down => Vec3::new(0.0, -1.0, 0.0),
- Direction::Up => Vec3::new(0.0, 1.0, 0.0),
- Direction::North => Vec3::new(0.0, 0.0, -1.0),
- Direction::South => Vec3::new(0.0, 0.0, 1.0),
- Direction::West => Vec3::new(-1.0, 0.0, 0.0),
- Direction::East => Vec3::new(1.0, 0.0, 0.0),
+ Direction::Down => BlockPos::new(0, -1, 0),
+ Direction::Up => BlockPos::new(0, 1, 0),
+ Direction::North => BlockPos::new(0, 0, -1),
+ Direction::South => BlockPos::new(0, 0, 1),
+ Direction::West => BlockPos::new(-1, 0, 0),
+ Direction::East => BlockPos::new(1, 0, 0),
}
}
+ #[inline]
+ pub fn normal_vec3(self) -> Vec3 {
+ self.normal().to_vec3_floored()
+ }
+
pub fn opposite(self) -> Direction {
match self {
Direction::Down => Direction::Up,
@@ -60,6 +74,16 @@ impl Direction {
Direction::East => Direction::West,
}
}
+
+ pub fn x(self) -> i32 {
+ self.normal().x
+ }
+ pub fn y(self) -> i32 {
+ self.normal().y
+ }
+ pub fn z(self) -> i32 {
+ self.normal().z
+ }
}
/// The four cardinal directions.
@@ -75,6 +99,7 @@ pub enum CardinalDirection {
East,
}
+/// A 3D axis like x, y, z.
#[derive(Clone, Copy, Debug)]
pub enum Axis {
X = 0,