The locator bar has one waypoint manager per level
Vanilla keeps a ServerWaypointManager per level: a player in another level is neither a transmitter nor a receiver there. Horizon passed every player to one manager whatever their dimension, so a player who went to the Nether stayed tracked at their Nether coordinates by the players left in the Overworld (`track Bob block 0 100 0`), and nothing was re-tracked when they came back. Each level now has its own manager, ticked with the players in that level: a player changing level leaves the old one (untracked for everyone there, as ServerLevel.removePlayerImmediately) and joins the new one (addDuringTeleport). The player-targets and dimension-players harnesses now compare the waypoints too, instead of leaving them out. Fixes #843 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,9 +59,10 @@ pub(super) struct LanHost {
|
||||
pub mob_players: HashMap<u32, u32>,
|
||||
/// An integrated server's owner (game/integrated.rs).
|
||||
pub owner: Option<Owner>,
|
||||
/// The players' locator bars (game/lan_waypoints.rs), and the guests who
|
||||
/// are dead, whose respawn replaces their waypoint.
|
||||
pub waypoints: lan::waypoints::Waypoints,
|
||||
/// The players' locator bars, one waypoint manager per level by
|
||||
/// dimension id (game/lan_waypoints.rs), and the guests who are dead,
|
||||
/// whose respawn replaces their waypoint.
|
||||
pub waypoints: std::collections::HashMap<String, lan::waypoints::Waypoints>,
|
||||
pub waypoint_dead: std::collections::HashSet<u128>,
|
||||
/// Guests' commands waiting for the hub to be back in `self.lan`, where
|
||||
/// a command can reach every player (game/lan_actions.rs).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! The locator bar of the players on a served world (lan/waypoints.rs): what
|
||||
//! each player looks like to the waypoint manager this tick.
|
||||
//! each player looks like to their level's waypoint manager this tick.
|
||||
use super::{Game, lan::LanHost};
|
||||
use horizon_client::{
|
||||
items::ItemStack,
|
||||
@@ -27,8 +27,12 @@ impl Game<'_> {
|
||||
Some((team.name.clone(), color))
|
||||
}
|
||||
|
||||
/// Each level's `ServerWaypointManager` ticked with the players in that
|
||||
/// level: a player who changes level leaves the old one's manager
|
||||
/// (`ServerLevel.removePlayerImmediately`: untracked for everyone there)
|
||||
/// and joins the new one's (`addDuringTeleport`).
|
||||
pub(super) fn lan_update_waypoints(&mut self, host: &mut LanHost, state: Option<&HostState>) {
|
||||
let mut players = Vec::new();
|
||||
let mut players: Vec<(&str, waypoints::Player)> = Vec::new();
|
||||
if let Some(h) = state {
|
||||
let icon = self
|
||||
.cmds
|
||||
@@ -39,22 +43,25 @@ impl Game<'_> {
|
||||
color: i.color,
|
||||
})
|
||||
.unwrap_or_default();
|
||||
players.push(waypoints::Player {
|
||||
uuid: h.uuid,
|
||||
conn: None,
|
||||
position: h.position,
|
||||
spectator: self.spectator(),
|
||||
transmit_range: transmit_range(
|
||||
h.sneaking,
|
||||
self.potions.effects.get("invisibility").is_some(),
|
||||
h.equipment[5].as_ref(),
|
||||
),
|
||||
receive_range: PLAYER_RANGE,
|
||||
first_tick: false,
|
||||
view_distance: host.hub.config.view_distance,
|
||||
team: self.waypoint_team(&h.name),
|
||||
icon,
|
||||
});
|
||||
players.push((
|
||||
self.dim.id(),
|
||||
waypoints::Player {
|
||||
uuid: h.uuid,
|
||||
conn: None,
|
||||
position: h.position,
|
||||
spectator: self.spectator(),
|
||||
transmit_range: transmit_range(
|
||||
h.sneaking,
|
||||
self.potions.effects.get("invisibility").is_some(),
|
||||
h.equipment[5].as_ref(),
|
||||
),
|
||||
receive_range: PLAYER_RANGE,
|
||||
first_tick: false,
|
||||
view_distance: host.hub.config.view_distance,
|
||||
team: self.waypoint_team(&h.name),
|
||||
icon,
|
||||
},
|
||||
));
|
||||
}
|
||||
let mut respawned = Vec::new();
|
||||
for g in host.hub.guests.iter().filter(|g| g.placed) {
|
||||
@@ -66,27 +73,51 @@ impl Game<'_> {
|
||||
}
|
||||
// Player.updatePlayerPose: the shift key crouches unless flying.
|
||||
let crouching = g.sneaking && !g.flying && !g.fall_flying && !g.sleeping;
|
||||
players.push(waypoints::Player {
|
||||
uuid: g.uuid,
|
||||
conn: Some(g.conn),
|
||||
position: g.position,
|
||||
spectator: g.spectator(),
|
||||
transmit_range: transmit_range(
|
||||
crouching,
|
||||
g.effects.get("invisibility").is_some(),
|
||||
g.armor[0].as_ref(),
|
||||
),
|
||||
receive_range: PLAYER_RANGE,
|
||||
first_tick: g.ticks == 0,
|
||||
view_distance: g.view_distance,
|
||||
team: self.waypoint_team(&g.name),
|
||||
icon: Icon::default(),
|
||||
});
|
||||
players.push((
|
||||
&g.dimension,
|
||||
waypoints::Player {
|
||||
uuid: g.uuid,
|
||||
conn: Some(g.conn),
|
||||
position: g.position,
|
||||
spectator: g.spectator(),
|
||||
transmit_range: transmit_range(
|
||||
crouching,
|
||||
g.effects.get("invisibility").is_some(),
|
||||
g.armor[0].as_ref(),
|
||||
),
|
||||
receive_range: PLAYER_RANGE,
|
||||
first_tick: g.ticks == 0,
|
||||
view_distance: g.view_distance,
|
||||
team: self.waypoint_team(&g.name),
|
||||
icon: Icon::default(),
|
||||
},
|
||||
));
|
||||
}
|
||||
host.waypoint_dead
|
||||
.retain(|uuid| players.iter().any(|p| p.uuid == *uuid));
|
||||
.retain(|uuid| players.iter().any(|(_, p)| p.uuid == *uuid));
|
||||
let locator_bar = self.ui.rules.bool("locator_bar");
|
||||
for (conn, packet) in host.waypoints.tick(&players, &respawned, locator_bar) {
|
||||
let mut levels: Vec<String> = host.waypoints.keys().cloned().collect();
|
||||
for (level, _) in &players {
|
||||
if !levels.iter().any(|l| l == level) {
|
||||
levels.push((*level).to_owned());
|
||||
}
|
||||
}
|
||||
levels.sort();
|
||||
let mut out = Vec::new();
|
||||
for level in levels {
|
||||
let here: Vec<waypoints::Player> = players
|
||||
.iter()
|
||||
.filter(|(l, _)| *l == level)
|
||||
.map(|(_, p)| p.clone())
|
||||
.collect();
|
||||
let manager = host.waypoints.entry(level.clone()).or_default();
|
||||
out.extend(manager.tick(&here, &respawned, locator_bar));
|
||||
// Nobody left in the level: nothing to remember there.
|
||||
if here.is_empty() {
|
||||
host.waypoints.remove(&level);
|
||||
}
|
||||
}
|
||||
for (conn, packet) in out {
|
||||
if let Some(g) = host.hub.guest(conn) {
|
||||
g.send(&packet);
|
||||
}
|
||||
|
||||
@@ -93,9 +93,18 @@ def run_side(label, server_command, client_command, build, world):
|
||||
return out.read_text(encoding='utf-8').splitlines()
|
||||
|
||||
|
||||
SHOWN = ('add', 'remove', 'respawn', 'track', 'untrack', 'update')
|
||||
|
||||
|
||||
def shown(lines):
|
||||
"""Each player's adds, removes and respawns, without the waypoints (the locator bar harness has those)."""
|
||||
return [l for l in lines if l.split(' ', 2)[2:3] and l.split(' ', 2)[2].split(' ')[0] in ('add', 'remove', 'respawn')]
|
||||
"""Each player's adds, removes, respawns and waypoints, step by step; sorted within a step (the packets of one
|
||||
step may leave in another order within the tick)."""
|
||||
steps = {}
|
||||
for line in lines:
|
||||
parts = line.split(' ', 2)
|
||||
if len(parts) == 3 and parts[2].split(' ')[0] in SHOWN:
|
||||
steps.setdefault((parts[0], parts[1]), []).append(line)
|
||||
return [l for key in steps for l in sorted(steps[key])]
|
||||
|
||||
|
||||
def main():
|
||||
@@ -139,7 +148,7 @@ def main():
|
||||
java=subprocess.check_output(['java', '--version'], text=True).splitlines()[0],
|
||||
lines=len(vanilla), output_sha256=lab.digest(build / 'horizon.txt', 'sha256'),
|
||||
scope='Two players on a dedicated server changing dimensions (Nether, End, back): the other players each '
|
||||
'is sent and loses, and the dimensions it respawns into.'))
|
||||
'is sent and loses, the dimensions it respawns into and its locator bar waypoints.'))
|
||||
print(f'server dimension players: {len(vanilla)} lines identical')
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,9 @@ vanilla generated first, with Alice and Bob as operators in creative. LocatorBar
|
||||
of vanilla's protocol code) and records, step by step, the system chat each receives and what the server changes
|
||||
about it: game mode events, teleports, inventory slots, effects, its death (with the death message), the other
|
||||
players it is sent or loses and the levels it respawns into. Each player's lines in each step are compared exactly,
|
||||
in sorted order (the packets of one step may leave in another order within the tick). The locator bar's waypoints
|
||||
and what a death does besides its messages are left to their own harnesses.
|
||||
in sorted order (the packets of one step may leave in another order within the tick), with the locator bar's
|
||||
waypoints (one manager per level: a player in another level is untracked). What a death does besides its messages
|
||||
is left to its own harness.
|
||||
"""
|
||||
import hashlib
|
||||
import os
|
||||
@@ -78,7 +79,6 @@ SCRIPT = [
|
||||
]
|
||||
# What the players' locator bars show has its own harness (test_locator_bar_parity), and what a death does
|
||||
# besides its messages (drops, the body leaving) the player combat ones: here only the messages of `kill`.
|
||||
WAYPOINTS = ('track ', 'untrack ', 'update ')
|
||||
DEATH_STEP = 'step=console-kill'
|
||||
STEP_SECONDS = 2.5
|
||||
|
||||
@@ -134,7 +134,7 @@ def run_side(label, server_command, client_command, build, world):
|
||||
# At the death, Alice picks up Bob's drops (and gets their advancements) in vanilla.
|
||||
death_side = step == DEATH_STEP and (not rest.startswith(('chat ', 'killed '))
|
||||
or 'chat.type.advancement' in rest)
|
||||
if rest.startswith(WAYPOINTS) or death_side:
|
||||
if death_side:
|
||||
continue
|
||||
if step != 'step=start':
|
||||
steps.setdefault((who, step), []).append(line)
|
||||
|
||||
Reference in New Issue
Block a user