diff options
| author | mat <git@matdoes.dev> | 2023-08-25 02:34:31 -0500 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2023-08-25 02:34:31 -0500 |
| commit | d5465cd28e43d48b3e913fdb1161eb907e4d80d0 (patch) | |
| tree | b0962ac1bd09b434c67296c038ef3b26245ce6d7 /azalea-entity/src/lib.rs | |
| parent | 9c31f8033f006d5f505ce97e359638d6c1136859 (diff) | |
| download | azalea-drasl-d5465cd28e43d48b3e913fdb1161eb907e4d80d0.tar.xz | |
add basic pathfinding test
Diffstat (limited to 'azalea-entity/src/lib.rs')
| -rw-r--r-- | azalea-entity/src/lib.rs | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs index c67817f3..db42a0ba 100644 --- a/azalea-entity/src/lib.rs +++ b/azalea-entity/src/lib.rs @@ -125,6 +125,11 @@ impl Debug for EntityUuid { /// automatically. #[derive(Component, Clone, Copy, Debug, Default, PartialEq, Deref, DerefMut)] pub struct Position(Vec3); +impl Position { + pub fn new(pos: Vec3) -> Self { + Self(pos) + } +} impl From<&Position> for Vec3 { fn from(value: &Position) -> Self { value.0 @@ -184,7 +189,7 @@ 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)] +#[derive(Debug, Component, Clone, Deref, DerefMut, Default)] pub struct Jumping(bool); /// A component that contains the direction an entity is looking. @@ -196,7 +201,7 @@ pub struct LookDirection { /// The physics data relating to the entity, such as position, velocity, and /// bounding box. -#[derive(Debug, Component)] +#[derive(Debug, Component, Clone)] pub struct Physics { pub delta: Vec3, @@ -219,6 +224,26 @@ pub struct Physics { pub has_impulse: bool, } +impl Physics { + pub fn new(dimensions: EntityDimensions, pos: &Vec3) -> Self { + Self { + delta: Vec3::default(), + + xxa: 0., + yya: 0., + zza: 0., + + on_ground: false, + last_on_ground: false, + + bounding_box: dimensions.make_bounding_box(pos), + dimensions, + + has_impulse: false, + } + } +} + /// Marker component for entities that are dead. /// /// "Dead" means that the entity has 0 health. @@ -297,22 +322,7 @@ impl EntityBundle { world_name: InstanceName(world_name), position: Position(pos), last_sent_position: LastSentPosition(pos), - physics: Physics { - delta: Vec3::default(), - - xxa: 0., - yya: 0., - zza: 0., - - on_ground: false, - last_on_ground: false, - - // TODO: have this be based on the entity type - bounding_box: dimensions.make_bounding_box(&pos), - dimensions, - - has_impulse: false, - }, + physics: Physics::new(dimensions, &pos), eye_height: EyeHeight(eye_height), direction: LookDirection::default(), |
