Merge pull request #2650 from kacpherek/fix/pvp-axe-disables-shield

🤖 Agent: Proven in union R1 (branch union/cg19-r1, main + 83 of kacpherek's PRs): the 98 harnesses it can affect, clippy -D warnings, tests, lan_e2e in-frame and on the server thread.
This commit is contained in:
Ludovic Marie
2026-10-27 15:02:55 +01:00
committed by GitHub
3 changed files with 40 additions and 1 deletions
+4
View File
@@ -42,6 +42,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<u32>,
+13
View File
@@ -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.
@@ -129,6 +131,14 @@ impl Game<'_> {
let (xd, zd) = self.extra_knockback_direction();
self.attack_ticks = 0;
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,
@@ -136,6 +146,7 @@ impl Game<'_> {
crit,
magic,
from,
disable_blocking,
sweep,
knockback: (strength, xd, zd),
knockback_attack,
@@ -250,7 +261,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);
+23 -1
View File
@@ -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;
@@ -219,6 +226,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() {