aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2024-02-24 00:39:38 -0600
committermat <git@matdoes.dev>2024-02-24 00:39:38 -0600
commit64fceff1cc65ee1dd1c72f08004e40179be9f9a4 (patch)
tree3df2fa5c0d3551f8b124858c208fa44a5e927f1b
parent5c85158e7ca6bbd357be520029326c08d456a107 (diff)
downloadazalea-drasl-64fceff1cc65ee1dd1c72f08004e40179be9f9a4.tar.xz
track entity rotations
-rw-r--r--azalea-client/src/packet_handling/game.rs53
-rw-r--r--azalea-entity/src/lib.rs2
2 files changed, 51 insertions, 4 deletions
diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs
index bd88258a..30b736c0 100644
--- a/azalea-client/src/packet_handling/game.rs
+++ b/azalea-client/src/packet_handling/game.rs
@@ -419,7 +419,6 @@ pub fn process_packet_events(ecs: &mut World) {
debug!("Got recipe packet");
}
ClientboundGamePacket::PlayerPosition(p) => {
- // TODO: reply with teleport confirm
debug!("Got player position packet {p:?}");
#[allow(clippy::type_complexity)]
@@ -839,6 +838,10 @@ pub fn process_packet_events(ecs: &mut World) {
if let Some(entity) = entity {
let new_pos = p.position;
+ let new_look_direction = LookDirection {
+ x_rot: (p.x_rot as i32 * 360) as f32 / 256.,
+ y_rot: (p.y_rot as i32 * 360) as f32 / 256.,
+ };
commands.entity(entity).add(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
update: Box::new(move |entity| {
@@ -846,6 +849,10 @@ pub fn process_packet_events(ecs: &mut World) {
if new_pos != **position {
**position = new_pos;
}
+ let mut look_direction = entity.get_mut::<LookDirection>().unwrap();
+ if new_look_direction != *look_direction {
+ *look_direction = new_look_direction;
+ }
}),
});
} else {
@@ -903,6 +910,11 @@ pub fn process_packet_events(ecs: &mut World) {
if let Some(entity) = entity {
let delta = p.delta.clone();
+ let new_look_direction = LookDirection {
+ x_rot: (p.x_rot as i32 * 360) as f32 / 256.,
+ y_rot: (p.y_rot as i32 * 360) as f32 / 256.,
+ };
+
commands.entity(entity).add(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
update: Box::new(move |entity_mut| {
@@ -911,6 +923,10 @@ pub fn process_packet_events(ecs: &mut World) {
if new_pos != **position {
**position = new_pos;
}
+ let mut look_direction = entity_mut.get_mut::<LookDirection>().unwrap();
+ if new_look_direction != *look_direction {
+ *look_direction = new_look_direction;
+ }
}),
});
} else {
@@ -923,8 +939,39 @@ pub fn process_packet_events(ecs: &mut World) {
system_state.apply(ecs);
}
- ClientboundGamePacket::MoveEntityRot(_p) => {
- // debug!("Got move entity rot packet {p:?}");
+ ClientboundGamePacket::MoveEntityRot(p) => {
+ let mut system_state: SystemState<(
+ Commands,
+ Query<(&EntityIdIndex, &InstanceHolder)>,
+ )> = SystemState::new(ecs);
+ let (mut commands, mut query) = system_state.get_mut(ecs);
+ let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap();
+
+ let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id));
+
+ if let Some(entity) = entity {
+ let new_look_direction = LookDirection {
+ x_rot: (p.x_rot as i32 * 360) as f32 / 256.,
+ y_rot: (p.y_rot as i32 * 360) as f32 / 256.,
+ };
+
+ commands.entity(entity).add(RelativeEntityUpdate {
+ partial_world: instance_holder.partial_instance.clone(),
+ update: Box::new(move |entity_mut| {
+ let mut look_direction = entity_mut.get_mut::<LookDirection>().unwrap();
+ if new_look_direction != *look_direction {
+ *look_direction = new_look_direction;
+ }
+ }),
+ });
+ } else {
+ warn!(
+ "Got move entity rot packet for unknown entity id {}",
+ p.entity_id
+ );
+ }
+
+ system_state.apply(ecs);
}
ClientboundGamePacket::KeepAlive(p) => {
debug!("Got keep alive packet {p:?} for {player_entity:?}");
diff --git a/azalea-entity/src/lib.rs b/azalea-entity/src/lib.rs
index eb5b5b25..f39a6e4f 100644
--- a/azalea-entity/src/lib.rs
+++ b/azalea-entity/src/lib.rs
@@ -203,7 +203,7 @@ impl From<&LastSentPosition> for BlockPos {
pub struct Jumping(bool);
/// A component that contains the direction an entity is looking.
-#[derive(Debug, Component, Clone, Default)]
+#[derive(Debug, Component, Clone, Default, PartialEq)]
pub struct LookDirection {
pub x_rot: f32,
pub y_rot: f32,