mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
add some more convenience functions
This commit is contained in:
parent
64fceff1cc
commit
4eeda83ba4
3 changed files with 62 additions and 7 deletions
|
@ -86,9 +86,7 @@ impl Client {
|
|||
|
||||
/// Returns whether the player will try to jump next tick.
|
||||
pub fn jumping(&self) -> bool {
|
||||
let mut ecs = self.ecs.lock();
|
||||
let jumping_ref = self.query::<&Jumping>(&mut ecs);
|
||||
**jumping_ref
|
||||
*self.component::<Jumping>()
|
||||
}
|
||||
|
||||
/// Sets the direction the client is looking. `y_rot` is yaw (looking to the
|
||||
|
@ -101,6 +99,14 @@ impl Client {
|
|||
|
||||
(look_direction.y_rot, look_direction.x_rot) = (y_rot, x_rot);
|
||||
}
|
||||
|
||||
/// Returns the direction the client is looking. The first value is the y
|
||||
/// rotation (ie. yaw, looking to the side) and the second value is the x
|
||||
/// rotation (ie. pitch, looking up and down).
|
||||
pub fn direction(&self) -> (f32, f32) {
|
||||
let look_direction = self.component::<LookDirection>();
|
||||
(look_direction.y_rot, look_direction.x_rot)
|
||||
}
|
||||
}
|
||||
|
||||
/// A component that contains the look direction that was last sent over the
|
||||
|
|
|
@ -186,6 +186,25 @@ macro_rules! vec3_impl {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<($type, $type, $type)> for $name {
|
||||
#[inline]
|
||||
fn from(pos: ($type, $type, $type)) -> Self {
|
||||
Self::new(pos.0, pos.1, pos.2)
|
||||
}
|
||||
}
|
||||
impl From<&($type, $type, $type)> for $name {
|
||||
#[inline]
|
||||
fn from(pos: &($type, $type, $type)) -> Self {
|
||||
Self::new(pos.0, pos.1, pos.2)
|
||||
}
|
||||
}
|
||||
impl From<$name> for ($type, $type, $type) {
|
||||
#[inline]
|
||||
fn from(pos: $name) -> Self {
|
||||
(pos.x, pos.y, pos.z)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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,16 +202,43 @@ 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.
|
||||
#[derive(Debug, Component, Clone)]
|
||||
|
|
Loading…
Add table
Reference in a new issue