aboutsummaryrefslogtreecommitdiff
path: root/azalea-core/src
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-core/src')
-rw-r--r--azalea-core/src/aabb.rs2
-rw-r--r--azalea-core/src/block_hit_result.rs34
-rw-r--r--azalea-core/src/hit_result.rs68
-rw-r--r--azalea-core/src/lib.rs2
4 files changed, 70 insertions, 36 deletions
diff --git a/azalea-core/src/aabb.rs b/azalea-core/src/aabb.rs
index 6796e79c..42ae797d 100644
--- a/azalea-core/src/aabb.rs
+++ b/azalea-core/src/aabb.rs
@@ -1,6 +1,6 @@
use crate::{
- block_hit_result::BlockHitResult,
direction::{Axis, Direction},
+ hit_result::BlockHitResult,
math::EPSILON,
position::{BlockPos, Vec3},
};
diff --git a/azalea-core/src/block_hit_result.rs b/azalea-core/src/block_hit_result.rs
deleted file mode 100644
index 4d930453..00000000
--- a/azalea-core/src/block_hit_result.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use crate::{
- direction::Direction,
- position::{BlockPos, Vec3},
-};
-
-#[derive(Debug, Clone, Copy, PartialEq)]
-pub struct BlockHitResult {
- pub location: Vec3,
- pub direction: Direction,
- pub block_pos: BlockPos,
- pub miss: bool,
- pub inside: bool,
- pub world_border: bool,
-}
-
-impl BlockHitResult {
- pub fn miss(location: Vec3, direction: Direction, block_pos: BlockPos) -> Self {
- Self {
- location,
- direction,
- block_pos,
- miss: true,
- inside: false,
- world_border: false,
- }
- }
-
- pub fn with_direction(&self, direction: Direction) -> Self {
- Self { direction, ..*self }
- }
- pub fn with_position(&self, block_pos: BlockPos) -> Self {
- Self { block_pos, ..*self }
- }
-}
diff --git a/azalea-core/src/hit_result.rs b/azalea-core/src/hit_result.rs
new file mode 100644
index 00000000..2fc78115
--- /dev/null
+++ b/azalea-core/src/hit_result.rs
@@ -0,0 +1,68 @@
+use crate::{
+ direction::Direction,
+ position::{BlockPos, Vec3},
+};
+
+/// The block or entity that our player is looking at and can interact with.
+///
+/// If there's nothing, it'll be a [`BlockHitResult`] with `miss` set to true.
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub enum HitResult {
+ Block(BlockHitResult),
+ /// TODO
+ Entity,
+}
+impl HitResult {
+ pub fn is_miss(&self) -> bool {
+ match self {
+ HitResult::Block(block_hit_result) => block_hit_result.miss,
+ HitResult::Entity => false,
+ }
+ }
+
+ pub fn is_block_hit_and_not_miss(&self) -> bool {
+ match self {
+ HitResult::Block(block_hit_result) => !block_hit_result.miss,
+ HitResult::Entity => false,
+ }
+ }
+
+ /// Returns the [`BlockHitResult`], if we were looking at a block and it
+ /// wasn't a miss.
+ pub fn as_block_hit_result_if_not_miss(&self) -> Option<&BlockHitResult> {
+ match self {
+ HitResult::Block(block_hit_result) if !block_hit_result.miss => Some(block_hit_result),
+ _ => None,
+ }
+ }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq)]
+pub struct BlockHitResult {
+ pub location: Vec3,
+ pub direction: Direction,
+ pub block_pos: BlockPos,
+ pub inside: bool,
+ pub world_border: bool,
+ pub miss: bool,
+}
+
+impl BlockHitResult {
+ pub fn miss(location: Vec3, direction: Direction, block_pos: BlockPos) -> Self {
+ Self {
+ location,
+ direction,
+ block_pos,
+ miss: true,
+ inside: false,
+ world_border: false,
+ }
+ }
+
+ pub fn with_direction(&self, direction: Direction) -> Self {
+ Self { direction, ..*self }
+ }
+ pub fn with_position(&self, block_pos: BlockPos) -> Self {
+ Self { block_pos, ..*self }
+ }
+}
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index a539dbd4..6c5e57c1 100644
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -2,7 +2,6 @@
pub mod aabb;
pub mod bitset;
-pub mod block_hit_result;
pub mod color;
pub mod cursor3d;
pub mod data_registry;
@@ -11,6 +10,7 @@ pub mod difficulty;
pub mod direction;
pub mod filterable;
pub mod game_type;
+pub mod hit_result;
pub mod math;
pub mod objectives;
pub mod position;