From 74860c03126a02fea685d34c0e418e0a07e8847b Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:28:04 -0400 Subject: [PATCH] Emit sweep particles for eligible sword hits --- crates/horizon-client/src/game.rs | 45 ++++++++++++++++++++++- crates/horizon-client/src/game/lan_pvp.rs | 9 ++++- crates/horizon-client/src/motion.rs | 45 +++++++++++++++++++++++ 3 files changed, 96 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 117b83bc5..7d9754274 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -5856,6 +5856,38 @@ impl Game<'_> { let delay = 20.0 / (4.0 + speed).max(0.1); ((self.attack_ticks as f32 + 0.5) / delay).clamp(0.0, 1.0) } + /// `Player.isSweepAttack`: a charged, grounded sword hit below the movement limit. + pub(super) fn sweep_attack_position(&self, scale: f32, crit: bool) -> Option<[f64; 3]> { + let p = self.player.as_ref()?; + let sword = self.held().is_some_and(|s| { + self.res + .items + .item_tags + .get("minecraft:swords") + .is_some_and(|tag| tag.contains(&*s.item)) + }); + if !p.is_sweep_attack(scale, crit, sword) { + return None; + } + let yaw = f64::from(self.yaw.to_radians()); + Some([ + p.position.x - yaw.sin(), + p.position.y + f64::from(p.dimensions.height) * 0.5, + p.position.z + yaw.cos(), + ]) + } + /// The visual and sound part of `Player.doSweepAttack` after a successful hit. + pub(super) fn sweep_attack(&mut self, at: [f64; 3], from: Option<[f64; 3]>) { + self.particles.add( + &horizon_client::particles::ParticleOptions::simple( + horizon_client::particles::ParticleType::SweepAttack, + ), + at, + [0.0; 3], + ); + self.audio + .play("minecraft:entity.player.attack.sweep", from, 1.0, 1.0); + } /// `Player.attack`'s sounds when a vehicle takes the hit (it always does, /// and can't be hit critically): knockback when sprinting at full /// strength, then strong or weak. Before `swing_arm` resets the charge. @@ -5872,7 +5904,11 @@ impl Game<'_> { } else { "minecraft:entity.player.attack.weak" }; - self.audio.play(sound, from, 1.0, 1.0); + if let Some(at) = self.sweep_attack_position(self.attack_strength_scale(), false) { + self.sweep_attack(at, from); + } else { + self.audio.play(sound, from, 1.0, 1.0); + } } /// Player.attack with the attack-strength charge, crits and knockback. fn attack(&mut self) -> bool { @@ -5924,6 +5960,7 @@ impl Game<'_> { let target_kind = self.mobs[index].kind.id.clone(); let target_kind = format!("minecraft:{}", target_kind.trim_start_matches("minecraft:")); let (amount, scale, crit) = self.melee_damage(&target_kind); + let sweep = self.sweep_attack_position(scale, crit); self.attack_ticks = 0; if let Some(p) = self.player.as_mut() && !self.creative @@ -5983,7 +6020,11 @@ impl Game<'_> { "minecraft:entity.player.attack.weak" }; // Player.playServerSideSound: at the player. - self.audio.play(sound, from, 1.0, 1.0); + if let Some(at) = sweep { + self.sweep_attack(at, from); + } else { + self.audio.play(sound, from, 1.0, 1.0); + } // The hurt or death sound the mob raised (getHurtSound / getDeathSound, // its voice pitch from its own random). let queued = std::mem::take(&mut self.mobs[index].outbox); diff --git a/crates/horizon-client/src/game/lan_pvp.rs b/crates/horizon-client/src/game/lan_pvp.rs index dc91744de..bd10241ff 100644 --- a/crates/horizon-client/src/game/lan_pvp.rs +++ b/crates/horizon-client/src/game/lan_pvp.rs @@ -19,6 +19,7 @@ pub(super) struct Strike { scale: f32, crit: bool, from: [f64; 3], + sweep: Option<[f64; 3]>, } impl Game<'_> { @@ -73,6 +74,7 @@ impl Game<'_> { let p = self.player.as_ref()?; let from = [p.position.x, p.position.y, p.position.z]; let (amount, scale, crit) = self.melee_damage("minecraft:player"); + let sweep = self.sweep_attack_position(scale, crit); self.attack_ticks = 0; if let Some(p) = self.player.as_mut() && !self.creative @@ -85,6 +87,7 @@ impl Game<'_> { scale, crit, from, + sweep, }) } @@ -105,6 +108,10 @@ impl Game<'_> { (true, false, true) => "minecraft:entity.player.attack.strong", (true, false, false) => "minecraft:entity.player.attack.weak", }; - self.audio.play(sound, Some(s.from), 1.0, 1.0); + if let Some(at) = s.sweep.filter(|_| hurt) { + self.sweep_attack(at, Some(s.from)); + } else { + self.audio.play(sound, Some(s.from), 1.0, 1.0); + } } } diff --git a/crates/horizon-client/src/motion.rs b/crates/horizon-client/src/motion.rs index ae2486351..0eb79d65c 100644 --- a/crates/horizon-client/src/motion.rs +++ b/crates/horizon-client/src/motion.rs @@ -281,6 +281,17 @@ fn attribute_error(error: impl std::fmt::Debug) -> io::Error { io::Error::other(format!("movement attribute: {error:?}")) } impl PlayerMotion { + /// `Player.isSweepAttack`, using the resident player's known horizontal velocity. + pub fn is_sweep_attack(&self, strength: f32, critical: bool, sword: bool) -> bool { + let movement = self.velocity; + let limit = f64::from(self.speed) * 2.5; + strength > 0.9 + && !critical + && !self.sprinting + && self.ground.on_ground + && movement.x * movement.x + movement.z * movement.z < limit * limit + && sword + } pub fn load_environment_once( &mut self, pending: &mut bool, @@ -1986,6 +1997,40 @@ impl LivingMotionWorld for MotionWorld<'_, '_, '_> { mod tests { use super::*; + #[test] + fn sword_sweep_requires_charge_ground_and_slow_horizontal_movement() { + let root = std::env::var_os("HORIZON_TEST_RESOURCES") + .map(std::path::PathBuf::from) + .unwrap_or_else(|| { + Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + }); + if !root.join("movement-properties.nbt").exists() { + eprintln!("skipped sword sweep regression: prepared resources unavailable"); + return; + } + let assets = Assets::load(&root).unwrap(); + let resources = MotionResources::load(&root, &assets).unwrap(); + let mut p = PlayerMotion::new(&resources, Vec3::ZERO).unwrap(); + p.ground.on_ground = true; + p.speed = 0.1; + assert!(p.is_sweep_attack(1.0, false, true)); + assert!(!p.is_sweep_attack(0.9, false, true)); + assert!(!p.is_sweep_attack(1.0, true, true)); + assert!(!p.is_sweep_attack(1.0, false, false)); + p.sprinting = true; + assert!(!p.is_sweep_attack(1.0, false, true)); + p.sprinting = false; + p.ground.on_ground = false; + assert!(!p.is_sweep_attack(1.0, false, true)); + p.ground.on_ground = true; + p.velocity = Vec3::new(0.2, 10.0, 0.0); + assert!(p.is_sweep_attack(1.0, false, true)); + p.velocity.z = 0.2; + assert!(!p.is_sweep_attack(1.0, false, true)); + p.velocity = Vec3::new(f64::from(p.speed) * 2.5, 0.0, 0.0); + assert!(!p.is_sweep_attack(1.0, false, true)); + } + #[test] fn player_stands_walks_sneaks_and_jumps_on_ghast() { let root = std::env::var_os("HORIZON_TEST_RESOURCES")