From 4afb5748f2312a5f274cb5523893ab79693d5ca9 Mon Sep 17 00:00:00 2001 From: Kacpherek Date: Tue, 27 Oct 2026 06:22:13 +0100 Subject: [PATCH] Let a player's axe hit disable the victim's shield --- crates/horizon-client/src/game/combat.rs | 4 ++++ crates/horizon-client/src/game/lan_pvp.rs | 13 ++++++++++++ crates/horizon-client/src/game/shield.rs | 24 ++++++++++++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game/combat.rs b/crates/horizon-client/src/game/combat.rs index 2d6b75902..f0395dda1 100644 --- a/crates/horizon-client/src/game/combat.rs +++ b/crates/horizon-client/src/game/combat.rs @@ -33,6 +33,10 @@ pub(super) struct CombatTracker { /// The projectile hitting the player now is another player's that /// `ServerPlayer.canHarmPlayer` refuses (the `pvp` rule, an ally). pub(super) refuse_player_hit: bool, + /// The player whose melee hit is landing on the player now: where they + /// stand and the seconds their weapon disables a shield for + /// (`getSecondsToDisableBlocking`). + pub(super) player_attacker: Option<([f64; 3], f32)>, /// The mob exploding now (`ServerExplosion.source`): its team's friendly /// fire decides whom the blast may hurt. pub(super) explosion_source: Option, diff --git a/crates/horizon-client/src/game/lan_pvp.rs b/crates/horizon-client/src/game/lan_pvp.rs index 65520221a..8e15bb1f3 100644 --- a/crates/horizon-client/src/game/lan_pvp.rs +++ b/crates/horizon-client/src/game/lan_pvp.rs @@ -40,6 +40,8 @@ pub(super) struct Strike { /// `Player.attack`'s `magicBoost > 0`: the enchantments added damage. magic: bool, from: [f64; 3], + /// `getSecondsToDisableBlocking` of the attacker's weapon. + disable_blocking: f32, sweep: Option<[f64; 3]>, /// `causeExtraKnockback`: its strength and direction (the attacker's /// yaw), and whether the hit is a sprinting knockback attack. @@ -122,6 +124,14 @@ impl Game<'_> { p.cause_food_exhaustion(0.1); } self.swing_arm(); + // LivingEntity.getSecondsToDisableBlocking: the held weapon's value, + // none while another item is in use. + let disable_blocking = if self.using.is_some() { + 0.0 + } else { + self.attack_item_info() + .map_or(0.0, |i| i.disable_blocking_seconds) + }; Some(Strike { attacker: self.lan_acting, amount, @@ -129,6 +139,7 @@ impl Game<'_> { crit, magic, from, + disable_blocking, sweep, knockback: (strength, xd, zd), knockback_attack, @@ -243,7 +254,9 @@ impl Game<'_> { // Player.attack: the hurt (with its knockback away from the // attacker), then causeExtraKnockback along the attacker's yaw. let land = |g: &mut Self| { + g.combat.player_attacker = Some((s.from, s.disable_blocking)); let hurt = g.mob_hits_player(s.amount, s.from, "minecraft:player_attack"); + g.combat.player_attacker = None; let (strength, xd, zd) = s.knockback; if hurt && strength > 0.0 { g.knock_back_player(f64::from(strength), xd, zd); diff --git a/crates/horizon-client/src/game/shield.rs b/crates/horizon-client/src/game/shield.rs index c4f7f98d1..e75dd56de 100644 --- a/crates/horizon-client/src/game/shield.rs +++ b/crates/horizon-client/src/game/shield.rs @@ -176,7 +176,14 @@ impl Game<'_> { if projectile { return; } - let Some(id) = attacker else { return }; + let Some(id) = attacker else { + // Another player's melee hit has no mob behind it. + if let Some((from, disable)) = self.combat.player_attacker { + let fully = outcome.blocked >= damage; + self.blocked_by_attacker(&component, [from[0], from[2]], fully, disable, at); + } + return; + }; let fully = outcome.blocked >= damage; let Some(m) = self.mobs.iter().find(|m| m.id == id) else { return; @@ -214,6 +221,21 @@ impl Game<'_> { let _ = self.handle_mob_events(events); return; } + self.blocked_by_attacker(&component, [mx, mz], fully, disable, at); + } + + /// What a blocked melee hit does to the defender once the shield took + /// it: `LivingEntity.blockedByItem` knocks them back unless fully + /// blocked, then `Player.blockUsingItem` disables the shield. + fn blocked_by_attacker( + &mut self, + component: &horizon_client::items::BlocksAttacks, + attacker: [f64; 2], + fully: bool, + disable: f32, + at: Option<[f64; 3]>, + ) { + let [mx, mz] = attacker; // LivingEntity.blockedByItem: defender.knockback(0.5, defender - attacker), // which moves the defender along -(xd, zd). if !fully && let Some(p) = self.player.as_mut() {