From b0c8f964b25f84296b2176e824e45b41143a77bd Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Mon, 19 Oct 2026 10:34:03 +0200 Subject: [PATCH] Server: players on one team without friendly fire don't hurt each other Player attacks between the host and guests, or two guests, only checked the pvp game rule. ServerPlayer.canHarmPlayer also asks the victim's team (Player.canHarmPlayer): an ally on a team with friendlyFire false takes no damage, and the attacker hears the no-damage sound. lan_e2e's pvp check puts both players on such a team and checks that neither hurts the other. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/lan_pvp.rs | 14 ++++++++++++++ tools/lan_e2e.py | 14 ++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/game/lan_pvp.rs b/crates/horizon-client/src/game/lan_pvp.rs index 1bdf9146a..dba2ed8e6 100644 --- a/crates/horizon-client/src/game/lan_pvp.rs +++ b/crates/horizon-client/src/game/lan_pvp.rs @@ -20,6 +20,8 @@ pub(super) struct Strike { crit: bool, from: [f64; 3], sweep: Option<[f64; 3]>, + /// The attacker's team, for the victim's `Player.canHarmPlayer`. + team: Option, } impl Game<'_> { @@ -88,12 +90,24 @@ impl Game<'_> { crit, from, sweep, + team: self.player_team().cloned(), }) } /// The hit landing on the victim, then the attacker's attack sound. pub(super) fn pvp_land(&mut self, host: &mut LanHost, victim: Victim, s: &Strike) { + // ServerPlayer.canHarmPlayer: the pvp game rule, then the victim's + // team (Player.canHarmPlayer: allies only with friendly fire on). + let team = match victim { + Victim::Host => self.player_team(), + Victim::Guest(conn) => host + .hub + .guest(conn) + .and_then(|g| self.score.board.players_team(&g.name)), + }; + let harm = horizon_client::scoreboard::teams_allow_damage(team, s.team.as_ref()); let hurt = self.ui.rules.bool("pvp") + && harm && match victim { Victim::Host => self.mob_hits_player(s.amount, s.from, "minecraft:player_attack"), Victim::Guest(conn) => self diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 9f494b022..723ef342c 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -18,7 +18,8 @@ address. The script then checks, from both sides, what a guest's game used to ge - mobs: with the host in creative, a zombie and a skeleton go for the guest and hurt them; - hazards: a guest in survival gets hungry sprint-jumping and is hurt by lava, a block at the eyes, drowning and the void (then respawns); -- pvp: the guest and the host hit each other with a sword; with the pvp game rule off, nothing; +- pvp: the guest and the host hit each other with a sword; with the pvp game rule off, or on one + team without friendly fire, nothing; - respawn: a player killed is drawn dead by the other side, and alive again once it respawns (the respawned player is a new entity to the others); the host dies, and on the server thread the guest too; @@ -582,8 +583,14 @@ def check_pvp(host, guest, out): hits = {} try: for name, rule, attacker in (('guest hits host', 'true', guest), ('host hits guest', 'true', host), - ('pvp off', 'false', guest)): + ('pvp off', 'false', guest), ('guest hits teammate', 'true', guest), + ('host hits teammate', 'true', host)): host('command', command=f'gamerule pvp {rule}') + if name == 'guest hits teammate': + # Player.canHarmPlayer: the victim's team without friendly fire spares its allies. + host('command', command='team add parity_allies') + host('command', command='team modify parity_allies friendlyFire false') + host('command', command='team join parity_allies @a') face_each_other(host, guest) attacker.wait(30) # a full attack charge victim = (lambda: host('state')['player']['health']) if attacker is guest else (lambda: remote(guest)['health']) @@ -594,9 +601,12 @@ def check_pvp(host, guest, out): attacker.shot(out, 'pvp-' + name.replace(' ', '-')) finally: host('command', command='gamerule pvp true') + host('command', command='team remove parity_allies') assert hits['guest hits host'][1] < hits['guest hits host'][0], f'the guest did not hurt the host: {hits}' assert hits['host hits guest'][1] < hits['host hits guest'][0], f'the host did not hurt the guest: {hits}' assert hits['pvp off'][1] == hits['pvp off'][0], f'pvp off still hurts: {hits}' + for name in ('guest hits teammate', 'host hits teammate'): + assert hits[name][1] == hits[name][0], f'friendly fire off still hurts ({name}): {hits}' return hits