Merge pull request #1905 from rdbtCVS/fix/server-player-sculk-events
🤖 Agent: Thanks rdbt! Every server player now emits its own movement game events, with per-player sculk history; the new server_player_sculk harness passes. I merged main (the guest swap code). Tested together with the other wave 2 contributor PRs: fmt, clippy -D warnings, and the horizon-client, horizon-world and horizon-protocol tests pass. Of the 127 harnesses the batch affects, 124 pass; the other three are a player-head mismatch fixed in #1934 and two worldgen timeouts on a loaded machine with no chunk differing. lan_e2e chat, fireball, cursor, looks, thrown, eat, shield, lava, contacts, projectiles and mobs pass with the host in-frame and on its server thread.
This commit is contained in:
@@ -84,6 +84,7 @@ pub(super) struct GuestPlay {
|
||||
equipped: Option<Vec<Option<ItemStack>>>,
|
||||
/// The guest's cast fishing hook (`Player.fishing`).
|
||||
pub(super) hook: Option<super::fishing::Hook>,
|
||||
sculk: super::sculk::PlayerEvents,
|
||||
}
|
||||
|
||||
/// A guest's command waiting for the hub (`LanHost::commands`).
|
||||
@@ -252,6 +253,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.
|
||||
@@ -259,6 +261,7 @@ impl Game<'_> {
|
||||
host.play.insert(conn, play);
|
||||
return None;
|
||||
};
|
||||
self.sculk.swap_player(&mut play.sculk);
|
||||
// The guest's own CombatTracker: damage to them is not the host's.
|
||||
// A new body starts with no record of the last one.
|
||||
let guest_combat = if fresh {
|
||||
@@ -492,6 +495,7 @@ impl Game<'_> {
|
||||
projectiles,
|
||||
modifiers,
|
||||
} = swap;
|
||||
self.sculk.swap_player(&mut play.sculk);
|
||||
// The guest's damage record back into their slot, the host's in place.
|
||||
let guest_combat = std::mem::replace(&mut self.combat, combat);
|
||||
self.guest_combat.insert(conn, guest_combat);
|
||||
@@ -2158,6 +2162,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),
|
||||
|
||||
@@ -63,6 +63,12 @@ struct Steps {
|
||||
on_ground: bool,
|
||||
in_water: bool,
|
||||
}
|
||||
#[derive(Default)]
|
||||
pub(super) struct PlayerEvents {
|
||||
steps: Option<Steps>,
|
||||
last_health: Option<f32>,
|
||||
}
|
||||
|
||||
#[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) {
|
||||
@@ -1498,6 +1513,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| {
|
||||
(
|
||||
@@ -1525,7 +1546,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<i64>)> = self
|
||||
.mobs
|
||||
.iter()
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user