From 805d5532e541deb1888216c8ebfc15775d8b2ea5 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 15:04:04 +0200 Subject: [PATCH] Give mob, beacon, sculk and splash effects to every player On a server (the integrated server thread and the dedicated server) the host has no player of its own, so effects that only touched the host's player reached nobody; on a LAN world they reached only the host. Beacons, the warden's and shriekers' darkness, the elder guardian's mining fatigue, splash and lingering potions' splash and the raid victory's Hero of the Village now run for each player in the level, guests through `as_guest`. The elder guardian's curse sends the guest the GUARDIAN_ELDER_EFFECT game event, which the remote client now shows (the apparition and the curse sound). lan_e2e.py gains an `effects` check: a speed beacon next to both players must give both of them speed. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/beacon.rs | 4 ++ crates/horizon-client/src/game/creatures.rs | 41 ++++++++++-- crates/horizon-client/src/game/lan_actions.rs | 26 ++++++++ crates/horizon-client/src/game/potions.rs | 66 +++++++++++-------- crates/horizon-client/src/game/raids.rs | 14 ++-- crates/horizon-client/src/game/remote.rs | 15 +++++ crates/horizon-client/src/game/sculk.rs | 3 + crates/horizon-client/src/lan/hub.rs | 1 + tools/lan_e2e.py | 27 +++++++- 9 files changed, 153 insertions(+), 44 deletions(-) diff --git a/crates/horizon-client/src/game/beacon.rs b/crates/horizon-client/src/game/beacon.rs index 15a7de79d..c8c437965 100644 --- a/crates/horizon-client/src/game/beacon.rs +++ b/crates/horizon-client/src/game/beacon.rs @@ -220,7 +220,11 @@ impl Game<'_> { levels } /// `applyEffects`: the powers for players within `levels * 10 + 10` (any height above). + /// `BeaconBlockEntity.applyEffects`: every player in range. fn beacon_effects(&mut self, p: [i32; 3], b: &Beacon) { + self.for_each_player(|g| g.beacon_effects_on_player(p, b)); + } + fn beacon_effects_on_player(&mut self, p: [i32; 3], b: &Beacon) { let Some(primary) = b.primary.as_deref().and_then(effect_id) else { return; }; diff --git a/crates/horizon-client/src/game/creatures.rs b/crates/horizon-client/src/game/creatures.rs index 076c2fbef..6fc25eb67 100644 --- a/crates/horizon-client/src/game/creatures.rs +++ b/crates/horizon-client/src/game/creatures.rs @@ -1358,25 +1358,52 @@ impl Game<'_> { /// mining fatigue III for five minutes unless a stronger or longer one /// is on, with the curse sound and the elder's apparition. fn elder_curse(&mut self, at: [f64; 3]) { + let mut cursed = Vec::new(); + self.for_each_player(|g| { + if g.elder_curse_player(at) { + cursed.push(g.lan_acting); + } + }); + // A guest's client shows the apparition and plays the curse itself + // (ClientboundGameEventPacket.GUARDIAN_ELDER_EFFECT). + if let Some(host) = self.lan.as_ref() { + for conn in cursed.into_iter().flatten() { + host.hub.send_to( + conn, + &horizon_protocol::packets::play::Clientbound::GameEvent( + horizon_protocol::packets::play::GameEvent { + event: horizon_client::lan::hub::game_event::GUARDIAN_ELDER_EFFECT, + param: 1.0, + }, + ), + ); + } + } + } + /// The curse on the player in place; whether it took. + fn elder_curse_player(&mut self, at: [f64; 3]) -> bool { if self.creative || self.spectator() { - return; + return false; } let Some(p) = self.player.as_ref() else { - return; + return false; }; let d = p.position.subtract(Vec3::new(at[0], at[1], at[2])); if d.x * d.x + d.y * d.y + d.z * d.z >= 2500.0 || p.health.dead_or_dying() { - return; + return false; } let active = self.potions.effects.get("minecraft:mining_fatigue"); if active.is_some_and(|e| e.amplifier >= 2 && e.duration >= 1200) { - return; + return false; } let at = [p.position.x, p.position.y, p.position.z]; self.give_player_effect("minecraft:mining_fatigue", 6000, 2); - self.audio - .play("minecraft:entity.elder_guardian.curse", Some(at), 1.0, 1.0); - self.creatures.elder_apparition = super::mob_blocks::APPARITION_TICKS; + if self.lan_acting.is_none() { + self.audio + .play("minecraft:entity.elder_guardian.curse", Some(at), 1.0, 1.0); + self.creatures.elder_apparition = super::mob_blocks::APPARITION_TICKS; + } + true } /// Damage of a given type to the player from a point. pub(super) fn mob_hits_player_kind(&mut self, amount: f32, from: [f64; 3], kind: &str) { diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 6b0463290..bb81c913f 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -291,6 +291,32 @@ impl Game<'_> { Some(result) } + /// `ServerLevel.players()` in turn: the host's own player, then each + /// guest in the level in place with their state swapped in (`as_guest`). + /// What reaches the players around a point (a beacon's powers, a splash + /// potion, a warden's darkness, an elder guardian's curse) lands on each + /// of them, not only on the host. A server has no player of its own. + /// Inside a guest's action (the hub taken) only that player is in place. + pub(super) fn for_each_player(&mut self, mut f: impl FnMut(&mut Self)) { + if self.player.is_some() { + f(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.as_guest(&mut host, conn, &mut f); + } + self.lan = Some(host); + } + /// The game mode fields without `set_mode`'s side effects on the host. fn set_mode_raw(&mut self, id: i32) { use horizon_client::command::args::GameMode; diff --git a/crates/horizon-client/src/game/potions.rs b/crates/horizon-client/src/game/potions.rs index a60926256..ffa63b7c9 100644 --- a/crates/horizon-client/src/game/potions.rs +++ b/crates/horizon-client/src/game/potions.rs @@ -467,6 +467,41 @@ impl Game<'_> { self.splash(&stack, at); } } + /// A splash potion's effects on the player in place, by their distance. + fn splash_on_player( + &mut self, + effects: &'static [(&'static str, i32, i32)], + at: Vec3, + scale: f64, + ) { + if let Some(p) = self.player.as_ref() { + let center = Vec3::new( + p.position.x, + p.position.y + f64::from(p.dimensions.height) / 2.0, + p.position.z, + ); + let d2 = + (center.x - at.x).powi(2) + (center.y - at.y).powi(2) + (center.z - at.z).powi(2); + if d2 < 16.0 && (center.y - at.y).abs() <= 2.0 + f64::from(p.dimensions.height) { + let intensity = 1.0 - d2.sqrt() / 4.0; + for (id, duration, amp) in effects { + let instant = brewing::effect(id).is_some_and(|e| e.instant); + if instant { + if let Some(a) = horizon_client::effects::instant(id, *amp, intensity) { + self.apply_effect_action(a); + } + } else { + let d = (intensity * f64::from(*duration) * scale + 0.5) as i32; + if d > 20 + && let Some(e) = brewing::effect(id) + { + self.potions.effects.add(EffectInstance::new(e.id, d, *amp)); + } + } + } + } + } + } /// `ThrownSplashPotion.onHitAsPotion` (lingering clouds apply as a weaker splash). fn splash(&mut self, stack: &ItemStack, at: Vec3) { if &*stack.item == "minecraft:experience_bottle" { @@ -527,34 +562,9 @@ impl Game<'_> { let Some(def) = stack.potion().and_then(brewing::potion) else { return; }; - // The player. - if let Some(p) = self.player.as_ref() { - let center = Vec3::new( - p.position.x, - p.position.y + f64::from(p.dimensions.height) / 2.0, - p.position.z, - ); - let d2 = - (center.x - at.x).powi(2) + (center.y - at.y).powi(2) + (center.z - at.z).powi(2); - if d2 < 16.0 && (center.y - at.y).abs() <= 2.0 + f64::from(p.dimensions.height) { - let intensity = 1.0 - d2.sqrt() / 4.0; - for (id, duration, amp) in def.effects { - let instant = brewing::effect(id).is_some_and(|e| e.instant); - if instant { - if let Some(a) = horizon_client::effects::instant(id, *amp, intensity) { - self.apply_effect_action(a); - } - } else { - let d = (intensity * f64::from(*duration) * scale + 0.5) as i32; - if d > 20 - && let Some(e) = brewing::effect(id) - { - self.potions.effects.add(EffectInstance::new(e.id, d, *amp)); - } - } - } - } - } + // Every player in range (`ThrownSplashPotion.applySplash` over + // `LivingEntity`s, the players among them). + self.for_each_player(|g| g.splash_on_player(def.effects, at, scale)); // Mobs take the instant effects (undead invert healing and harming). let undead = &self.res.stations.enchantments.entity_tags; let mut hits = Vec::new(); diff --git a/crates/horizon-client/src/game/raids.rs b/crates/horizon-client/src/game/raids.rs index ff06d5ac8..25a440af3 100644 --- a/crates/horizon-client/src/game/raids.rs +++ b/crates/horizon-client/src/game/raids.rs @@ -624,17 +624,17 @@ impl Game<'_> { raider::state_mut(m).ticks_outside_raid = ticks; } } - Action::Victory { heroes, amplifier } => { - let me = self.level.player_uuid; - if me.is_some_and(|u| heroes.contains(&u)) && !self.spectator() { + // Raid.tick on a victory: each hero who is still alive. + Action::Victory { heroes, amplifier } => self.for_each_player(|g| { + if heroes.contains(&g.acting_uuid()) && !g.spectator() { let mut effect = EffectInstance::new("hero_of_the_village", raid::HERO_DURATION, amplifier); effect.visible = false; - self.potions.effects.add(effect); - self.stats.custom("raid_win", 1); - self.trigger_player("minecraft:hero_of_the_village"); + g.potions.effects.add(effect); + g.stats.custom("raid_win", 1); + g.trigger_player("minecraft:hero_of_the_village"); } - } + }), } } /// `Raid.playSound`: the horn, 13 blocks away from the player toward the diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 05e1f81c3..f5539ffd2 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -1439,6 +1439,21 @@ impl Game<'_> { } } C::GameEvent(p) => match p.event { + // GUARDIAN_ELDER_EFFECT: the apparition, and the curse sound + // unless the elder guardian is silent. + 10 => { + self.creatures.elder_apparition = super::mob_blocks::APPARITION_TICKS; + if p.param == 1.0 + && let Some(at) = self.player.as_ref().map(|m| m.position) + { + self.audio.play( + "minecraft:entity.elder_guardian.curse", + Some([at.x, at.y, at.z]), + 1.0, + 1.0, + ); + } + } 1 => { self.world.weather.raining = true; self.world.weather.rain_level = (0.0, 0.0); diff --git a/crates/horizon-client/src/game/sculk.rs b/crates/horizon-client/src/game/sculk.rs index c06a23871..e33b78d5f 100644 --- a/crates/horizon-client/src/game/sculk.rs +++ b/crates/horizon-client/src/game/sculk.rs @@ -1180,6 +1180,9 @@ impl Game<'_> { /// `Warden.applyDarknessAround` / `MobEffectUtil.addEffectToPlayersAround`. pub(super) fn apply_darkness(&mut self, at: [f64; 3], radius: f64) { + self.for_each_player(|g| g.darkness_on_player(at, radius)); + } + fn darkness_on_player(&mut self, at: [f64; 3], radius: f64) { if self.creative || self.spectator() { return; } diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index b751fb034..bc5761246 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -32,6 +32,7 @@ pub mod game_event { pub const CHANGE_GAME_MODE: u8 = 3; pub const RAIN_LEVEL: u8 = 7; pub const THUNDER_LEVEL: u8 = 8; + pub const GUARDIAN_ELDER_EFFECT: u8 = 10; pub const LEVEL_CHUNKS_LOAD_START: u8 = 13; } diff --git a/tools/lan_e2e.py b/tools/lan_e2e.py index 48d45f714..2de0a564c 100755 --- a/tools/lan_e2e.py +++ b/tools/lan_e2e.py @@ -22,6 +22,7 @@ address. The script then checks, from both sides, what a guest's game used to ge - containers: the guest's ender chest holds the guest's items, not the host's, and a double chest opens as 9x6 with the right half first; - feedback: the guest's command feedback names the guest and shows the numbers; +- effects: a beacon's power reaches every player in range, the host and the guest; - portals: (--server-thread) the server holds a level per dimension: the guest goes to the Nether through a portal while the host stays, then the host goes to the End while the guest is in the Nether, and both come back. @@ -56,7 +57,7 @@ ROOT = Path(__file__).resolve().parents[1] GUEST_NAME = 'Guest' # The host plays single player on its server thread (--server-thread). SERVER_THREAD = False -CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback', 'trials', 'portals'] +CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback', 'trials', 'effects', 'portals'] class Game: @@ -294,6 +295,28 @@ def check_sign(host, guest, out): return placed +def effect_ids(game): + return [e.get('id', '').removeprefix('minecraft:') for e in game('state')['player'].get('effects', [])] + + +def check_effects(host, guest, out): + x, y, z = (int(v // 1) for v in pos_of(host)) + bx, by, bz = x - 3, y, z - 3 + host('command', command=f'fill {bx - 1} {by - 1} {bz - 1} {bx + 1} {by - 1} {bz + 1} minecraft:iron_block') + host('command', command=f'setblock {bx} {by} {bz} minecraft:beacon{{primary_effect:"minecraft:speed"}}') + # BeaconBlockEntity.tick applies its powers every 80 ticks, once the beam has reached the sky. + seen = {} + for _ in range(15): + host.wait(20) + seen = {'host': effect_ids(host), 'guest': effect_ids(guest)} + if all('speed' in v for v in seen.values()): + break + host.shot(out, 'effects') + guest.shot(out, 'effects') + assert 'speed' in seen['host'] and 'speed' in seen['guest'], f'beacon effects: {seen}' + return seen + + def wait_dimension(game, dimension, ticks): """Wait up to `ticks` for the game to be in `dimension` with its world loaded around it.""" for _ in range(ticks // 20): @@ -727,7 +750,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name 'chest': check_chest, 'crafting': check_crafting, 'sign': check_sign, 'damage': check_damage, 'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp, 'containers': check_containers, 'feedback': check_feedback, 'trials': check_trials, - 'walls': check_walls, 'portals': check_portals} + 'walls': check_walls, 'effects': check_effects, 'portals': check_portals} def run(ctl, out, resources, checks):