From 84a3f1ee1832967b8d1eed3b55dfae767efaeee9 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Sun, 25 Oct 2026 19:30:34 +0000 Subject: [PATCH] Emit sculk movement events for each server player Co-Authored-By: OpenAI Codex GPT-6.1 --- crates/horizon-client/src/game/lan_actions.rs | 5 ++ crates/horizon-client/src/game/sculk.rs | 25 +++++- tools/test_server_player_sculk_parity.py | 87 +++++++++++++++++++ 3 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 tools/test_server_player_sculk_parity.py diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 18f529184..b8c161428 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -84,6 +84,7 @@ pub(super) struct GuestPlay { equipped: Option>>, /// The guest's cast fishing hook (`Player.fishing`). pub(super) hook: Option, + sculk: super::sculk::PlayerEvents, } /// A guest's command waiting for the hub (`LanHost::commands`). @@ -250,6 +251,7 @@ impl Game<'_> { if fresh { // A new body (joined, respawned, changed level): nothing on it yet. play.equipped = None; + play.sculk = Default::default(); } let g = &mut host.hub.guests[i]; // The guest's body. @@ -257,6 +259,7 @@ impl Game<'_> { host.play.insert(conn, play); return None; }; + self.sculk.swap_player(&mut play.sculk); self.potions.swap_player(&mut g.effects, &mut play.potions); motion.position = Vec3::new(g.position[0], g.position[1], g.position[2]); motion.ground.on_ground = g.on_ground; @@ -478,6 +481,7 @@ impl Game<'_> { projectiles, modifiers, } = swap; + self.sculk.swap_player(&mut play.sculk); play.modifiers = std::mem::replace(&mut self.applied_modifiers, modifiers); // What the guest shot is theirs (Projectile.setOwner). for p in self.creatures.projectiles.iter_mut().skip(projectiles) { @@ -2095,6 +2099,7 @@ impl Game<'_> { let Some((events, marked)) = events else { return; }; + self.as_guest(host, conn, |game| game.tick_player_sculk_events()); for event in events { match event { MotionEvent::HurtSound(sound) => self.player_hurt_sound(sound, at), diff --git a/crates/horizon-client/src/game/sculk.rs b/crates/horizon-client/src/game/sculk.rs index a11a643c1..84e3d5cb2 100644 --- a/crates/horizon-client/src/game/sculk.rs +++ b/crates/horizon-client/src/game/sculk.rs @@ -63,6 +63,12 @@ struct Steps { on_ground: bool, in_water: bool, } +#[derive(Default)] +pub(super) struct PlayerEvents { + steps: Option, + last_health: Option, +} + #[derive(Default)] pub(super) struct SculkState { /// The player's warning level toward a warden. @@ -86,6 +92,15 @@ pub(super) struct SculkState { } impl SculkState { + pub(super) fn swap_player(&mut self, other: &mut PlayerEvents) { + let steps = self.steps.remove(&Who::Player); + if let Some(guest) = other.steps.take() { + self.steps.insert(Who::Player, guest); + } + other.steps = steps; + std::mem::swap(&mut self.last_health, &mut other.last_health); + } + /// Exchange the level-held parts (its sculk block entities and the /// chunks scanned for them) with another level's (game/levels.rs). pub(super) fn swap_level(&mut self, other: &mut Self) { @@ -1491,6 +1506,12 @@ impl Game<'_> { /// Events from entities moving, getting hurt and dying, derived from what /// changed this tick. fn tick_entity_events(&mut self) { + self.tick_player_sculk_events(); + self.tick_mob_sculk_events(); + } + + /// Entity.move emits on the authoritative server too, for each ServerPlayer. + pub(super) fn tick_player_sculk_events(&mut self) { // The player. let player = self.player.as_ref().map(|p| { ( @@ -1518,7 +1539,9 @@ impl Game<'_> { } self.sculk.last_health = Some(health); } - // Mobs. + } + + fn tick_mob_sculk_events(&mut self) { let snapshot: Vec<(u32, [f64; 3], bool, bool, Species, Option)> = self .mobs .iter() diff --git a/tools/test_server_player_sculk_parity.py b/tools/test_server_player_sculk_parity.py new file mode 100644 index 000000000..33489ad5a --- /dev/null +++ b/tools/test_server_player_sculk_parity.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python3 +"""Both players' ordinary walking activates a sculk sensor on the server. + +Exercise Entity.move movement emission through real client input, alongside +sculk's deterministic vanilla oracle. Check the integrated-server and in-frame +hosts: the guest always uses the server-player path. +""" +import json +import math +import subprocess + +import lab +import lan_e2e as lan + + +def until(game, observe, predicate, ticks=100): + value = observe() + for _ in range(ticks): + if predicate(value): + return value + game.wait(1) + value = observe() + assert predicate(value), value + return value + + +def check_walk(host, guest, out, role): + player = host if role == 'host' else guest + hx, y, hz = (math.floor(v) for v in lan.pos_of(host)) + x, z = hx + 6, hz + (-8 if role == 'host' else 8) + sensor = (x + 3, y, z + 1) + player('command', command='gamemode survival') + host('command', command=f'fill {x - 2} {y - 1} {z - 2} {x + 5} {y - 1} {z + 5} minecraft:stone') + host('command', command=f'fill {x - 2} {y} {z - 2} {x + 5} {y + 3} {z + 5} minecraft:air') + start = (x + 0.5, y, z + 0.5) + player('command', command=f'tp @s {start[0]} {start[1]} {start[2]} 0 0') + until(player, lambda: lan.pos_of(player), lambda p: math.dist(p, start) < 0.1) + player.raw('look', 0, 0) + player.wait(2) + host('command', command=f'setblock {sensor[0]} {sensor[1]} {sensor[2]} minecraft:sculk_sensor') + phase = lambda game: game.raw('getblock', *sensor)['block'] + try: + until(host, lambda: phase(host), lambda s: 'sculk_sensor_phase=inactive' in s) + player.wait(10) + assert 'sculk_sensor_phase=inactive' in phase(host), 'setup activated the sensor' + player.raw('key', 'w', 'down') + try: + player.wait(15) + finally: + player.raw('key', 'w', 'up') + moved = {'client': math.dist(lan.pos_of(player), start), + 'server': math.dist(lan.server_player(host, player)['position'], start)} + assert all(d > 1 for d in moved.values()), moved + for viewer in (host, guest): + until(viewer, lambda: phase(viewer), lambda s: 'sculk_sensor_phase=active' in s, ticks=85) + return {'moved': moved, 'phase': phase(host)} + finally: + player.raw('key', 'w', 'up') + host('command', command=f'fill {x - 2} {y} {z - 2} {x + 5} {y + 3} {z + 5} minecraft:air') + + +def main(): + subprocess.run(['cargo', 'build', '--locked', '--profile', 'fast', '-p', 'horizon-client', + '--bin', 'horizon-client', '--bin', 'horizon-ctl'], cwd=lab.ROOT, check=True) + metadata = json.loads(subprocess.check_output( + ['cargo', 'metadata', '--format-version', '1', '--no-deps'], cwd=lab.ROOT, text=True)) + ctl = lab.ROOT / metadata['target_directory'] / 'fast' / 'horizon-ctl' + checks = ['sculk-walk-host', 'sculk-walk-guest'] + for role, name in zip(('host', 'guest'), checks): + lan.CHECK_FNS[name] = lambda h, g, o, role=role: check_walk(h, g, o, role) + # Use the runner's current display (xvfb on Linux), with fresh isolated homes. + lan.game_env = lambda _screen, home: lab.game_env( + HORIZON_HOME=home, HORIZON_TELEMETRY_URL='off') + reports = {} + for threaded in (True, False): + lan.SERVER_THREAD = threaded + mode = 'server-thread' if threaded else 'in-frame' + out = lab.LOCAL / 'server-player-sculk-parity' / mode + out.mkdir(parents=True, exist_ok=True) + # lan.Game launches each client with lab.game_env and private scratch homes. + reports[mode] = lan.run(ctl, out, lab.RESOURCES.resolve(), checks) + lab.write_json(lab.LOCAL / 'server-player-sculk-parity' / 'report.json', reports) + assert all(r['pass'] for mode in reports.values() for r in mode.values()), reports + + +if __name__ == '__main__': + main()