From f96101cd47f35e998ac1f032f92ce7a4de82f89e Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 23 Oct 2026 23:02:07 +0200 Subject: [PATCH] Strikes and mob effects reach a server's players: lightning, evoker fangs, poison, axolotls Lightning (Entity.thunderHit) and evoker fangs (EvokerFangs.dealDamageTo) hit every entity in their box, but thunder_hit and fangs_bite only looked at the window's own player, so a server's players (guests, and single player on the server thread) were never struck (#1480, #1481). Both now run their player part for each guest too, through Game::each_guest_hit. The effects a mob gives the player it acts on (cave spider and bee poison, husk hunger, wither skeleton wither, the nautilus's breath) and an axolotl's help after a kill stayed with the server's own player: acts_on_player now routes MobEvent::EffectPlayer and MobEvent::AxolotlSupportPlayer to the guest the mob sees, like its blows (#1484, #1485). tools/lan_e2e.py gains a strikes check: a bolt hurts each player standing in water, and a cave spider poisons them. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/fangs.rs | 18 ++++--- crates/horizon-client/src/game/lan_mobs.rs | 21 ++++++++ crates/horizon-client/src/game/lightning.rs | 38 +++++++------ tools/lan_e2e.py | 60 +++++++++++++++++++++ 4 files changed, 115 insertions(+), 22 deletions(-) diff --git a/crates/horizon-client/src/game/fangs.rs b/crates/horizon-client/src/game/fangs.rs index 0939f6490..cdf2d17a5 100644 --- a/crates/horizon-client/src/game/fangs.rs +++ b/crates/horizon-client/src/game/fangs.rs @@ -69,12 +69,18 @@ impl Game<'_> { let lo = Vec3::new(f.pos[0] - half, f.pos[1], f.pos[2] - half); let hi = Vec3::new(f.pos[0] + half, f.pos[1] + 0.8, f.pos[2] + half); let b = horizon_core::geometry::Aabb::new(lo, hi); - if let Some(p) = self.player_view() - && p.alive - && p.bounds.intersects(b) - { - self.mob_hits_player_kind(6.0, f.pos, "minecraft:indirect_magic"); - } + // Every player in the box, the server's players too. + let pos = f.pos; + let bite = move |g: &mut Self| { + if let Some(p) = g.player_view() + && p.alive + && p.bounds.intersects(b) + { + g.mob_hits_player_kind(6.0, pos, "minecraft:indirect_magic"); + } + }; + bite(self); + self.each_guest_hit(bite); for m in &mut self.mobs { let ally = matches!( m.species(), diff --git a/crates/horizon-client/src/game/lan_mobs.rs b/crates/horizon-client/src/game/lan_mobs.rs index 0ee991737..b3f42f0c7 100644 --- a/crates/horizon-client/src/game/lan_mobs.rs +++ b/crates/horizon-client/src/game/lan_mobs.rs @@ -78,6 +78,8 @@ pub(super) fn acts_on_player(e: &MobEvent) -> bool { target: Who::Player, .. } + | MobEvent::EffectPlayer { .. } + | MobEvent::AxolotlSupportPlayer ) } @@ -115,6 +117,25 @@ impl Game<'_> { views } + /// Runs `f` as each guest in play here, for what strikes every player in + /// an area (`Level.getEntities`), not only the window's own. + pub(super) fn each_guest_hit(&mut self, mut f: impl FnMut(&mut Self)) { + let Some(mut host) = self.lan.take() else { + return; + }; + let conns: Vec = host + .hub + .guests + .iter() + .filter(|g| host.hub.here(g) && g.loaded && !g.dead) + .map(|g| g.conn) + .collect(); + for conn in conns { + self.guest_hit_by(&mut host, conn, &mut f); + } + self.lan = Some(host); + } + /// Mob events aimed at a guest, run as that guest (`guest_hit_by`). pub(super) fn lan_guest_mob_events(&mut self, events: Vec<(u32, MobEvent)>) { if events.is_empty() { diff --git a/crates/horizon-client/src/game/lightning.rs b/crates/horizon-client/src/game/lightning.rs index 476cb5aa4..916bd2a0a 100644 --- a/crates/horizon-client/src/game/lightning.rs +++ b/crates/horizon-client/src/game/lightning.rs @@ -280,11 +280,12 @@ impl Game<'_> { } /// `thunderHit` for entities within 3 blocks (up to 9 above). fn thunder_hit(&mut self, b: &mut Bolt) { - let inside = |p: [f64; 3]| { - (p[0] - b.at[0]).abs() <= 3.0 - && (p[2] - b.at[2]).abs() <= 3.0 - && p[1] >= b.at[1] - 3.0 - && p[1] <= b.at[1] + 9.0 + let at = b.at; + let inside = move |p: [f64; 3]| { + (p[0] - at[0]).abs() <= 3.0 + && (p[2] - at[2]).abs() <= 3.0 + && p[1] >= at[1] - 3.0 + && p[1] <= at[1] + 9.0 }; let damage = Damage { kind: DamageKind::Generic, @@ -349,19 +350,24 @@ impl Game<'_> { if !events.is_empty() { let _ = self.handle_mob_events(events); } - if let Some(p) = self.player.as_ref().map(|p| p.position) - && inside([p.x, p.y, p.z]) - { - if let Some(p) = self.player.as_mut() { - p.fire_ticks += 1; - if p.fire_ticks == 0 - && let Err(error) = p.ignite_for_ticks(160) - { - self.error = Some(error); + // Every player in the box, the server's players too. + let strike = move |g: &mut Self| { + if let Some(p) = g.player.as_ref().map(|p| p.position) + && inside([p.x, p.y, p.z]) + { + if let Some(p) = g.player.as_mut() { + p.fire_ticks += 1; + if p.fire_ticks == 0 + && let Err(error) = p.ignite_for_ticks(160) + { + g.error = Some(error); + } } + g.hurt_player_by("minecraft:lightning_bolt", 5.0); } - self.hurt_player_by("minecraft:lightning_bolt", 5.0); - } + }; + strike(self); + self.each_guest_hit(strike); // Dropped items burn up (ItemEntity health 5), save fire-resistant ones. self.dropped.retain(|e| { !inside([e.position.x, e.position.y, e.position.z]) diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 8318b6a1f..49ba0d186 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -210,6 +210,8 @@ address. The script then checks, from both sides, what a guest's game used to ge - body: the host and the guest each walk while drawing a bow (slowed), stand on powder snow with leather boots (held up) and without (sinking), and sprint-swim looking down (diving): their own client decides it (#1278, #1296, #1303). +- strikes: a bolt strikes the host and the guest standing in water and hurts them, and a cave + spider's bite poisons them (#1480, #1484). Each check is reported on its own (a failing one doesn't stop the others) and the screenshots of both sides go to --out (host-*.png, guest-*.png). @@ -4925,5 +4927,63 @@ CHECKS += ['body'] CHECK_FNS.update(body=check_body) +def check_strikes(host, guest, out): + """What a mob or the sky does to every player in reach, the server's players too (#1480, + #1484): a bolt striking a player standing in water costs them health (Entity.thunderHit), and + a cave spider's bite poisons them (CaveSpider.doHurtTarget on Normal).""" + hx, hy, hz = (int(v // 1) for v in pos_of(host)) + seen = {} + try: + host('command', command='difficulty normal') + host('command', command='time set 18000') + for game, dz in ((host, -5), (guest, 5)): + x, z = hx, hz + dz + host('command', command=f'fill {x - 3} {hy - 1} {z - 3} {x + 3} {hy + 3} {z + 3} minecraft:stone') + host('command', command=f'fill {x - 2} {hy} {z - 2} {x + 2} {hy + 3} {z + 2} minecraft:air') + host('command', command=f'fill {x - 2} {hy} {z - 2} {x + 2} {hy} {z + 2} minecraft:water') + game('command', command='gamemode survival') + game('command', command='clear @s') + game('command', command='effect clear @s') + game('command', command='effect give @s minecraft:instant_health 1 5') + game('command', command=f'tp @s {x + 0.5} {hy} {z + 0.5}') + game.wait(20) + before = game('state')['player'].get('health') + game('command', command=f'summon minecraft:lightning_bolt {x + 0.5} {hy} {z + 0.5}') + game.wait(20) + s = {'bolt': (before, game('state')['player'].get('health'))} + host('command', command=f'summon minecraft:cave_spider {x + 1.5} {hy} {z + 0.5}') + poisoned = False + for _ in range(40): + game.wait(5) + if 'poison' in effect_ids(game): + poisoned = True + break + s['poisoned'] = poisoned + s['bitten'] = game('state')['player'].get('health') + host('command', command='kill @e[type=minecraft:cave_spider]') + game.wait(5) + game.shot(out, 'strikes') + host('command', command=f'fill {x - 3} {hy - 1} {z - 3} {x + 3} {hy + 3} {z + 3} minecraft:air') + host('command', command=f'fill {x - 3} {hy - 1} {z - 3} {x + 3} {hy - 1} {z + 3} minecraft:stone') + seen[game.name] = s + finally: + host('command', command='kill @e[type=minecraft:cave_spider]') + host('command', command='time set day') + for game in (host, guest): + back_to_game(game) + game('command', command='effect clear @s') + game('command', command='effect give @s minecraft:instant_health 1 5') + face_each_other(host, guest) + for name, s in seen.items(): + a, b = s['bolt'] + assert a is not None and b is not None and a - b >= 3, f'{name} struck by lightning: {seen}' + assert s['poisoned'], f'{name} bitten by a cave spider: {seen}' + return seen + + +CHECKS += ['strikes'] +CHECK_FNS.update(strikes=check_strikes) + + if __name__ == '__main__': main()