aboutsummaryrefslogtreecommitdiff
path: root/azalea-client
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2024-12-11 19:51:12 -0600
committerGitHub <noreply@github.com>2024-12-11 19:51:12 -0600
commite9136c9cbbf9010b8352127e129c1cd290f377bd (patch)
treedb83316a273153106dd3b343c9d6d4fce234d132 /azalea-client
parent23932003d98db0f5f976146aa9a11e5d04a74695 (diff)
downloadazalea-drasl-e9136c9cbbf9010b8352127e129c1cd290f377bd.tar.xz
Implement EntityPositionSync (#196)
* implement EntityPositionSync * fix EntityPositionSync setting the wrong vec_delta_codec and also move into a RelativeEntityUpdate
Diffstat (limited to 'azalea-client')
-rw-r--r--azalea-client/src/movement.rs13
-rw-r--r--azalea-client/src/packet_handling/game.rs142
2 files changed, 118 insertions, 37 deletions
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index 03183e24..bdc29f2f 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -195,7 +195,7 @@ pub fn send_position(
pos: **position,
x_rot: direction.x_rot,
y_rot: direction.y_rot,
- on_ground: physics.on_ground,
+ on_ground: physics.on_ground(),
}
.into_variant(),
)
@@ -205,7 +205,7 @@ pub fn send_position(
x: position.x,
y: position.y,
z: position.z,
- on_ground: physics.on_ground,
+ on_ground: physics.on_ground(),
}
.into_variant(),
)
@@ -214,14 +214,14 @@ pub fn send_position(
ServerboundMovePlayerRot {
x_rot: direction.x_rot,
y_rot: direction.y_rot,
- on_ground: physics.on_ground,
+ on_ground: physics.on_ground(),
}
.into_variant(),
)
- } else if physics.last_on_ground != physics.on_ground {
+ } else if physics.last_on_ground() != physics.on_ground() {
Some(
ServerboundMovePlayerStatusOnly {
- on_ground: physics.on_ground,
+ on_ground: physics.on_ground(),
}
.into_variant(),
)
@@ -238,7 +238,8 @@ pub fn send_position(
last_direction.x_rot = direction.x_rot;
}
- physics.last_on_ground = physics.on_ground;
+ let on_ground = physics.on_ground();
+ physics.set_last_on_ground(on_ground);
// minecraft checks for autojump here, but also autojump is bad so
packet
diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs
index d4d84f75..0c505d07 100644
--- a/azalea-client/src/packet_handling/game.rs
+++ b/azalea-client/src/packet_handling/game.rs
@@ -451,8 +451,16 @@ pub fn process_packet_events(ecs: &mut World) {
let new_y = apply_change(position.y, p.relative.y, p.change.pos.y);
let new_z = apply_change(position.z, p.relative.z, p.change.pos.z);
- let new_y_rot = apply_change(direction.y_rot, p.relative.y_rot, p.change.y_rot);
- let new_x_rot = apply_change(direction.x_rot, p.relative.x_rot, p.change.x_rot);
+ let new_y_rot = apply_change(
+ direction.y_rot,
+ p.relative.y_rot,
+ p.change.look_direction.y_rot,
+ );
+ let new_x_rot = apply_change(
+ direction.x_rot,
+ p.relative.x_rot,
+ p.change.look_direction.x_rot,
+ );
let mut new_delta_from_rotations = physics.velocity;
if p.relative.rotate_delta {
@@ -829,30 +837,29 @@ pub fn process_packet_events(ecs: &mut World) {
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.id));
-
- 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).queue(RelativeEntityUpdate {
- partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity| {
- let mut position = entity.get_mut::<Position>().unwrap();
- 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 {
+ let Some(entity) = entity_id_index.get(&MinecraftEntityId(p.id)) else {
warn!("Got teleport entity packet for unknown entity id {}", p.id);
- }
+ continue;
+ };
+
+ 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).queue(RelativeEntityUpdate {
+ partial_world: instance_holder.partial_instance.clone(),
+ update: Box::new(move |entity| {
+ let mut position = entity.get_mut::<Position>().unwrap();
+ 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;
+ }
+ }),
+ });
system_state.apply(ecs);
}
@@ -870,15 +877,26 @@ pub fn process_packet_events(ecs: &mut World) {
let (mut commands, mut query) = system_state.get_mut(ecs);
let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap();
+ debug!("Got move entity pos packet {p:?}");
+
let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id));
if let Some(entity) = entity {
- let delta = p.delta.clone();
+ let new_delta = p.delta.clone();
+ let new_on_ground = p.on_ground;
commands.entity(entity).queue(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
update: Box::new(move |entity_mut| {
+ let mut physics = entity_mut.get_mut::<Physics>().unwrap();
+ let new_pos = physics.vec_delta_codec.decode(
+ new_delta.xa as i64,
+ new_delta.ya as i64,
+ new_delta.za as i64,
+ );
+ physics.vec_delta_codec.set_base(new_pos);
+ physics.set_on_ground(new_on_ground);
+
let mut position = entity_mut.get_mut::<Position>().unwrap();
- let new_pos = position.with_delta(&delta);
if new_pos != **position {
**position = new_pos;
}
@@ -901,23 +919,36 @@ pub fn process_packet_events(ecs: &mut World) {
let (mut commands, mut query) = system_state.get_mut(ecs);
let (entity_id_index, instance_holder) = query.get_mut(player_entity).unwrap();
+ debug!("Got move entity pos rot packet {p:?}");
+
let entity = entity_id_index.get(&MinecraftEntityId(p.entity_id));
if let Some(entity) = entity {
- let delta = p.delta.clone();
+ let new_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.,
};
+ let new_on_ground = p.on_ground;
+
commands.entity(entity).queue(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
update: Box::new(move |entity_mut| {
+ let mut physics = entity_mut.get_mut::<Physics>().unwrap();
+ let new_pos = physics.vec_delta_codec.decode(
+ new_delta.xa as i64,
+ new_delta.ya as i64,
+ new_delta.za as i64,
+ );
+ physics.vec_delta_codec.set_base(new_pos);
+ physics.set_on_ground(new_on_ground);
+
let mut position = entity_mut.get_mut::<Position>().unwrap();
- let new_pos = position.with_delta(&delta);
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;
@@ -949,10 +980,14 @@ pub fn process_packet_events(ecs: &mut World) {
x_rot: (p.x_rot as i32 * 360) as f32 / 256.,
y_rot: (p.y_rot as i32 * 360) as f32 / 256.,
};
+ let new_on_ground = p.on_ground;
commands.entity(entity).queue(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
update: Box::new(move |entity_mut| {
+ let mut physics = entity_mut.get_mut::<Physics>().unwrap();
+ physics.set_on_ground(new_on_ground);
+
let mut look_direction = entity_mut.get_mut::<LookDirection>().unwrap();
if new_look_direction != *look_direction {
*look_direction = new_look_direction;
@@ -1416,7 +1451,7 @@ pub fn process_packet_events(ecs: &mut World) {
system_state.apply(ecs);
}
- ClientboundGamePacket::StartConfiguration(_) => {
+ ClientboundGamePacket::StartConfiguration(_p) => {
let mut system_state: SystemState<(Commands, EventWriter<SendPacketEvent>)> =
SystemState::new(ecs);
let (mut commands, mut packet_events) = system_state.get_mut(ecs);
@@ -1434,6 +1469,52 @@ pub fn process_packet_events(ecs: &mut World) {
system_state.apply(ecs);
}
+ ClientboundGamePacket::EntityPositionSync(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 Some(entity) = entity_id_index.get(&MinecraftEntityId(p.id)) else {
+ warn!("Got teleport entity packet for unknown entity id {}", p.id);
+ continue;
+ };
+
+ let new_position = p.values.pos;
+ let new_on_ground = p.on_ground;
+ let new_look_direction = p.values.look_direction;
+
+ commands.entity(entity).queue(RelativeEntityUpdate {
+ partial_world: instance_holder.partial_instance.clone(),
+ update: Box::new(move |entity_mut| {
+ let is_local_entity = entity_mut.get::<LocalEntity>().is_some();
+ let mut physics = entity_mut.get_mut::<Physics>().unwrap();
+
+ physics.vec_delta_codec.set_base(new_position);
+
+ if is_local_entity {
+ debug!("Ignoring entity position sync packet for local player");
+ return;
+ }
+
+ physics.set_on_ground(new_on_ground);
+
+ let mut last_sent_position =
+ entity_mut.get_mut::<LastSentPosition>().unwrap();
+ **last_sent_position = new_position;
+ let mut position = entity_mut.get_mut::<Position>().unwrap();
+ **position = new_position;
+
+ let mut look_direction = entity_mut.get_mut::<LookDirection>().unwrap();
+ *look_direction = new_look_direction;
+ }),
+ });
+
+ system_state.apply(ecs);
+ }
+
ClientboundGamePacket::SelectAdvancementsTab(_) => {}
ClientboundGamePacket::SetActionBarText(_) => {}
ClientboundGamePacket::SetBorderCenter(_) => {}
@@ -1476,7 +1557,6 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::ProjectilePower(_) => {}
ClientboundGamePacket::CustomReportDetails(_) => {}
ClientboundGamePacket::ServerLinks(_) => {}
- ClientboundGamePacket::EntityPositionSync(_) => {}
ClientboundGamePacket::PlayerRotation(_) => {}
ClientboundGamePacket::RecipeBookAdd(_) => {}
ClientboundGamePacket::RecipeBookRemove(_) => {}