aboutsummaryrefslogtreecommitdiff
path: root/azalea-client/src/plugins/movement.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-12-16 09:42:54 -0200
committermat <git@matdoes.dev>2025-12-16 09:42:54 -0200
commit6f2fe2c9e5af1f2fa2c1b99c3d4ea0a7e90ae16c (patch)
treeb01afabf10b51e3024dfdc139803b590a36b08c2 /azalea-client/src/plugins/movement.rs
parent9bd529277f5025805da95f081657c180972e487e (diff)
downloadazalea-drasl-6f2fe2c9e5af1f2fa2c1b99c3d4ea0a7e90ae16c.tar.xz
change KnockbackEvent to an EntityEvent and fix ClientboundExplode representation
ty mahtog for pointing out the latter issue <3
Diffstat (limited to 'azalea-client/src/plugins/movement.rs')
-rw-r--r--azalea-client/src/plugins/movement.rs31
1 files changed, 15 insertions, 16 deletions
diff --git a/azalea-client/src/plugins/movement.rs b/azalea-client/src/plugins/movement.rs
index fd85de2d..c4409722 100644
--- a/azalea-client/src/plugins/movement.rs
+++ b/azalea-client/src/plugins/movement.rs
@@ -46,10 +46,9 @@ impl Plugin for MovementPlugin {
fn build(&self, app: &mut App) {
app.add_message::<StartWalkEvent>()
.add_message::<StartSprintEvent>()
- .add_message::<KnockbackEvent>()
.add_systems(
Update,
- (handle_sprint, handle_walk, handle_knockback)
+ (handle_sprint, handle_walk)
.chain()
.in_set(MoveEventsSystems)
.after(update_bounding_box)
@@ -70,7 +69,8 @@ impl Plugin for MovementPlugin {
send_position.after(PhysicsSystems),
)
.chain(),
- );
+ )
+ .add_observer(handle_knockback);
}
}
@@ -655,27 +655,26 @@ fn has_enough_impulse_to_start_sprinting(physics_state: &PhysicsState) -> bool {
/// Usually `KnockbackKind::Set` is used for normal knockback and
/// `KnockbackKind::Add` is used for explosions, but some servers (notably
/// Hypixel) use explosions for knockback.
-#[derive(Message)]
+#[derive(EntityEvent, Debug, Clone)]
pub struct KnockbackEvent {
pub entity: Entity,
- pub knockback: KnockbackType,
+ pub data: KnockbackData,
}
-pub enum KnockbackType {
+#[derive(Debug, Clone)]
+pub enum KnockbackData {
Set(Vec3),
Add(Vec3),
}
-pub fn handle_knockback(mut query: Query<&mut Physics>, mut events: MessageReader<KnockbackEvent>) {
- for event in events.read() {
- if let Ok(mut physics) = query.get_mut(event.entity) {
- match event.knockback {
- KnockbackType::Set(velocity) => {
- physics.velocity = velocity;
- }
- KnockbackType::Add(velocity) => {
- physics.velocity += velocity;
- }
+pub fn handle_knockback(knockback: On<KnockbackEvent>, mut query: Query<&mut Physics>) {
+ if let Ok(mut physics) = query.get_mut(knockback.entity) {
+ match knockback.data {
+ KnockbackData::Set(velocity) => {
+ physics.velocity = velocity;
+ }
+ KnockbackData::Add(velocity) => {
+ physics.velocity += velocity;
}
}
}