aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-02-24 06:02:11 -0600
committermat <git@matdoes.dev>2024-02-24 06:02:11 -0600
commit4eeda83ba4bdb5e20c765a46e43227f4f9b39b69 (patch)
tree479d06d13870c17abfda96d704b21cc2eb85488b /azalea-entity/src
parent64fceff1cc65ee1dd1c72f08004e40179be9f9a4 (diff)
downloadazalea-drasl-4eeda83ba4bdb5e20c765a46e43227f4f9b39b69.tar.xz
add some more convenience functions
Diffstat (limited to 'azalea-entity/src')
-rw-r--r--azalea-entity/src/lib.rs38
1 files changed, 34 insertions, 4 deletions
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs
index f39a6e4f..e08284a9 100644
--- a/azalea-entity/src/lib.rs
+++ b/azalea-entity/src/lib.rs
@@ -23,7 +23,10 @@ use bevy_ecs::{bundle::Bundle, component::Component};
pub use data::*;
use derive_more::{Deref, DerefMut};
pub use dimensions::EntityDimensions;
-use std::fmt::Debug;
+use std::{
+ fmt::Debug,
+ hash::{Hash, Hasher},
+};
use uuid::Uuid;
pub use crate::plugin::*;
@@ -199,15 +202,42 @@ impl From<&LastSentPosition> for BlockPos {
///
/// If this is true, the entity will try to jump every tick. (It's equivalent to
/// the space key being held in vanilla.)
-#[derive(Debug, Component, Clone, Deref, DerefMut, Default)]
+#[derive(Debug, Component, Copy, Clone, Deref, DerefMut, Default)]
pub struct Jumping(bool);
/// A component that contains the direction an entity is looking.
-#[derive(Debug, Component, Clone, Default, PartialEq)]
+#[derive(Debug, Component, Copy, Clone, Default, PartialEq)]
pub struct LookDirection {
- pub x_rot: f32,
+ /// Left and right. Aka yaw.
pub y_rot: f32,
+ /// Up and down. Aka pitch.
+ pub x_rot: f32,
+}
+
+impl LookDirection {
+ pub fn new(y_rot: f32, x_rot: f32) -> Self {
+ Self { y_rot, x_rot }
+ }
+}
+
+impl From<LookDirection> for (f32, f32) {
+ fn from(value: LookDirection) -> Self {
+ (value.y_rot, value.x_rot)
+ }
+}
+impl From<(f32, f32)> for LookDirection {
+ fn from((y_rot, x_rot): (f32, f32)) -> Self {
+ Self { y_rot, x_rot }
+ }
+}
+
+impl Hash for LookDirection {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.y_rot.to_bits().hash(state);
+ self.x_rot.to_bits().hash(state);
+ }
}
+impl Eq for LookDirection {}
/// The physics data relating to the entity, such as position, velocity, and
/// bounding box.