aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/packet_handling
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-10-12 22:39:29 -0500
committermat <git@matdoes.dev>2023-10-12 22:39:29 -0500
commiteeec59adabb8c084c8b6b847a31130eb7c37d2ee (patch)
tree6ffa8e6d83ba5d6095062abf06406edf7f10d276 /azalea-client/src/packet_handling
parent79ad1e93bf6ce2b7c2da6925a7c85b33bb76f154 (diff)
downloadazalea-drasl-eeec59adabb8c084c8b6b847a31130eb7c37d2ee.tar.xz
KnockbackEvent and rename Physics::delta to velocity
Diffstat (limited to 'azalea-client/src/packet_handling')
-rw-r--r--azalea-client/src/packet_handling/game.rs44
1 files changed, 27 insertions, 17 deletions
diff --git a/azalea-client/src/packet_handling/game.rs b/azalea-client/src/packet_handling/game.rs
index 6e138565..1d8c6cc9 100644
--- a/azalea-client/src/packet_handling/game.rs
+++ b/azalea-client/src/packet_handling/game.rs
@@ -44,6 +44,7 @@ use crate::{
GameProfileComponent, Hunger, InstanceHolder, LocalGameMode, PlayerAbilities,
SendPacketEvent, TabList,
},
+ movement::{KnockbackEvent, KnockbackType},
raw_connection::RawConnection,
ClientInformation, PlayerInfo, ReceivedRegistries,
};
@@ -422,7 +423,7 @@ pub fn process_packet_events(ecs: &mut World) {
continue;
};
- let delta_movement = physics.delta;
+ let delta_movement = physics.velocity;
let is_x_relative = p.relative_arguments.x;
let is_y_relative = p.relative_arguments.y;
@@ -459,7 +460,7 @@ pub fn process_packet_events(ecs: &mut World) {
y_rot += direction.y_rot;
}
- physics.delta = Vec3 {
+ physics.velocity = Vec3 {
x: delta_x,
y: delta_y,
z: delta_z,
@@ -797,15 +798,21 @@ pub fn process_packet_events(ecs: &mut World) {
continue;
};
+ // this is to make sure the same entity velocity update doesn't get sent
+ // multiple times when in swarms
commands.entity(entity).add(RelativeEntityUpdate {
partial_world: instance_holder.partial_instance.clone(),
- update: Box::new(move |entity| {
- let mut physics = entity.get_mut::<Physics>().unwrap();
- physics.delta = Vec3 {
- x: p.xa as f64 / 8000.,
- y: p.ya as f64 / 8000.,
- z: p.za as f64 / 8000.,
- };
+ update: Box::new(move |entity_mut| {
+ entity_mut.world_scope(|world| {
+ world.send_event(KnockbackEvent {
+ entity,
+ kind: KnockbackType::Set(Vec3 {
+ x: p.xa as f64 / 8000.,
+ y: p.ya as f64 / 8000.,
+ z: p.za as f64 / 8000.,
+ }),
+ })
+ });
}),
});
@@ -1186,15 +1193,18 @@ pub fn process_packet_events(ecs: &mut World) {
ClientboundGamePacket::DeleteChat(_) => {}
ClientboundGamePacket::Explode(p) => {
trace!("Got explode packet {p:?}");
- let mut system_state: SystemState<Query<&mut Physics>> = SystemState::new(ecs);
- let mut query = system_state.get_mut(ecs);
- let mut physics = query.get_mut(player_entity).unwrap();
+ let mut system_state: SystemState<EventWriter<KnockbackEvent>> =
+ SystemState::new(ecs);
+ let mut knockback_events = system_state.get_mut(ecs);
- physics.delta += Vec3 {
- x: p.knockback_x as f64,
- y: p.knockback_y as f64,
- z: p.knockback_z as f64,
- };
+ knockback_events.send(KnockbackEvent {
+ entity: player_entity,
+ kind: KnockbackType::Set(Vec3 {
+ x: p.knockback_x as f64,
+ y: p.knockback_y as f64,
+ z: p.knockback_z as f64,
+ }),
+ });
system_state.apply(ecs);
}