aboutsummaryrefslogtreecommitdiff
path: root/azalea-entity
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-08-25 02:34:31 -0500
committermat <git@matdoes.dev>2023-08-25 02:34:31 -0500
commitd5465cd28e43d48b3e913fdb1161eb907e4d80d0 (patch)
treeb0962ac1bd09b434c67296c038ef3b26245ce6d7 /azalea-entity
parent9c31f8033f006d5f505ce97e359638d6c1136859 (diff)
downloadazalea-drasl-d5465cd28e43d48b3e913fdb1161eb907e4d80d0.tar.xz
add basic pathfinding test
Diffstat (limited to 'azalea-entity')
-rwxr-xr-xazalea-entity/src/dimensions.rs2
-rw-r--r--azalea-entity/src/lib.rs46
-rw-r--r--azalea-entity/src/plugin/indexing.rs1
3 files changed, 30 insertions, 19 deletions
diff --git a/azalea-entity/src/dimensions.rs b/azalea-entity/src/dimensions.rs
index 1d013d10..ab5a1808 100755
--- a/azalea-entity/src/dimensions.rs
+++ b/azalea-entity/src/dimensions.rs
@@ -1,6 +1,6 @@
use azalea_core::{Vec3, AABB};
-#[derive(Debug, Default)]
+#[derive(Debug, Default, Clone)]
pub struct EntityDimensions {
pub width: f32,
pub height: f32,
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(),
diff --git a/azalea-entity/src/plugin/indexing.rs b/azalea-entity/src/plugin/indexing.rs
index 23f53c5f..3a349f5c 100644
--- a/azalea-entity/src/plugin/indexing.rs
+++ b/azalea-entity/src/plugin/indexing.rs
@@ -229,6 +229,7 @@ pub fn update_entity_chunk_positions(
}
/// Despawn entities that aren't being loaded by anything.
+#[allow(clippy::type_complexity)]
pub fn remove_despawned_entities_from_indexes(
mut commands: Commands,
mut entity_infos: ResMut<EntityUuidIndex>,