From ae22d5dd960c930f0fefc42b337d9c066e4af1be Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 00:33:21 +0200 Subject: [PATCH 01/46] Online mode: players named in commands are their accounts An online-mode server checks players by their account's UUID, so op, whitelist, ban and pardon now resolve a name as vanilla's CachedUserNameToIdResolver does: a player on the server, then one seen since the start (in memory; vanilla also keeps usercache.json), then the services' profiles/getByName endpoint through the discovery document. A name with no account is "That player does not exist", with vanilla's "Couldn't find profile with name" warning. Offline servers keep the offline profiles. horizon-server does the same while the server is stopped (op, whitelist add, and the players init writes), and removes entries by the name already on the list. `init --offline` (or HORIZON_ONLINE=false) sets online-mode off; init's note now warns about offline servers only. The online-mode harness adds a sixth login: `whitelist add` for the player who joined earlier needs no lookup and lets them in, and an unknown name is looked up and refused, on vanilla's server and on Horizon's (43 checks). Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1 + crates/horizon-client/src/game/dedicated.rs | 100 ++++++++++++++------ crates/horizon-client/src/game/lan.rs | 1 + crates/horizon-server-files/Cargo.toml | 4 +- crates/horizon-server-files/src/lib.rs | 8 +- crates/horizon-server-files/src/profiles.rs | 100 ++++++++++++++++++++ crates/horizon-server/src/config.rs | 2 +- crates/horizon-server/src/init.rs | 36 ++++--- crates/horizon-server/src/lists.rs | 27 +++++- crates/horizon-server/src/main.rs | 3 +- tools/test_online_mode_parity.py | 53 ++++++++++- 11 files changed, 282 insertions(+), 53 deletions(-) create mode 100644 crates/horizon-server-files/src/profiles.rs diff --git a/Cargo.lock b/Cargo.lock index 1d5897d11..aadf1e1c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1573,6 +1573,7 @@ dependencies = [ "horizon-protocol", "horizon-world", "log", + "ureq", ] [[package]] diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs index 6f1ba3fee..9bc1e1fce 100644 --- a/crates/horizon-client/src/game/dedicated.rs +++ b/crates/horizon-client/src/game/dedicated.rs @@ -58,6 +58,21 @@ struct Setup { } static SETUP: OnceLock>> = OnceLock::new(); +/// CachedUserNameToIdResolver, kept in memory only (vanilla also saves it to +/// usercache.json): players who joined, and accounts found by name, by name +/// in lower case. +static USER_CACHE: OnceLock>> = OnceLock::new(); + +/// PlayerList.placeNewPlayer adds the player to the name cache. +pub(super) fn remember(name: &str, uuid: u128) { + let user = NameAndId { + id: uuid, + name: name.to_owned(), + }; + let cache = USER_CACHE.get_or_init(Default::default); + cache.lock().unwrap().insert(name.to_lowercase(), user); +} + /// Log4j's console pattern: `[HH:mm:ss] [thread/LEVEL]: message`. pub(super) fn log(level: &str, message: &str) { log_from("Server thread", level, message); @@ -316,6 +331,8 @@ struct ServerState { /// When the last passes of the loop ended, for the tick rate horizon-server shows. ticks: std::collections::VecDeque, paused: bool, + /// online-mode: names given to commands are looked up as accounts. + online: bool, } impl Game<'_> { @@ -512,6 +529,7 @@ impl Game<'_> { empty_ticks: 0, ticks: Default::default(), paused: false, + online: props.online_mode, }; let pause_after = props.pause_when_empty_seconds * 20; let idle_timeout = props.player_idle_timeout; @@ -640,23 +658,46 @@ impl Game<'_> { host.hub.resend_commands(); } - /// A known player by name: online first, else the offline profile. - fn resolve(&self, name: &str) -> NameAndId { - self.lan - .as_ref() - .and_then(|h| { - h.hub - .guests - .iter() - .find(|g| g.name.eq_ignore_ascii_case(name)) - }) - .map_or_else( - || NameAndId::offline(name), - |g| NameAndId { - id: g.uuid, - name: g.name.clone(), - }, - ) + /// A player on the server, by name. + fn online_player(&self, name: &str) -> Option { + let hub = &self.lan.as_ref()?.hub; + let g = hub + .guests + .iter() + .find(|g| g.name.eq_ignore_ascii_case(name))?; + Some(NameAndId { + id: g.uuid, + name: g.name.clone(), + }) + } + + /// GameProfileArgument: a player on the server, else one seen since the + /// start, else the name resolved as the server's mode says (an online + /// server asks the services, an offline one makes the offline profile). + /// None, told to the console: no such account. + fn resolve(&self, name: &str, online: bool) -> Option { + let user = self.online_player(name).or_else(|| { + let key = name.to_lowercase(); + let cache = USER_CACHE.get_or_init(Default::default); + if let Some(user) = cache.lock().unwrap().get(&key) { + return Some(user.clone()); + } + let user = horizon_server_files::profiles::resolve(name, online); + let Some(user) = user else { + if online { + log("WARN", &format!("Couldn't find profile with name: {key}")); + } + return None; + }; + if online { + cache.lock().unwrap().insert(key, user.clone()); + } + Some(user) + }); + if user.is_none() { + self.console_reply(Text::translate("argument.player.unknown", &[])); + } + user } /// MinecraftServer.sendSystemMessage: what the console is told. @@ -739,7 +780,9 @@ impl Game<'_> { )); } "op" | "deop" if !rest.is_empty() => { - let user = self.resolve(rest[0]); + let Some(user) = self.resolve(rest[0], state.online) else { + return; + }; let level = 4; let changed = { let mut l = state.lists.lock().unwrap(); @@ -769,7 +812,9 @@ impl Game<'_> { } "whitelist" => self.console_whitelist(state, &rest), "ban" if !rest.is_empty() => { - let user = self.resolve(rest[0]); + let Some(user) = self.resolve(rest[0], state.online) else { + return; + }; let reason = (rest.len() > 1).then(|| rest[1..].join(" ")); let added = state.lists.lock().unwrap().bans.add(BanEntry::new( user.clone(), @@ -859,7 +904,9 @@ impl Game<'_> { } } "pardon" if !rest.is_empty() => { - let user = self.resolve(rest[0]); + let Some(user) = self.resolve(rest[0], state.online) else { + return; + }; let removed = state.lists.lock().unwrap().bans.remove(&user); let key = if removed { "commands.pardon.success" @@ -925,15 +972,10 @@ impl Game<'_> { } } "kick" if !rest.is_empty() => { - let user = self.resolve(rest[0]); - let online = self - .lan - .as_ref() - .is_some_and(|h| h.hub.guests.iter().any(|g| g.uuid == user.id)); - if !online { + let Some(user) = self.online_player(rest[0]) else { self.console_reply(Text::translate("argument.entity.notfound.player", &[])); return; - } + }; let reason = if rest.len() > 1 { Tag::String(JavaString::from(rest[1..].join(" ").as_str())) } else { @@ -1013,7 +1055,9 @@ impl Game<'_> { self.console_reply(Text::translate("commands.whitelist.reloaded", &[])); } ["add", name] | ["remove", name] => { - let user = self.resolve(name); + let Some(user) = self.resolve(name, state.online) else { + return; + }; let mut l = state.lists.lock().unwrap(); let (ok, key) = if rest[0] == "add" { if l.white.contains(&user) { diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index c416c202f..3e570f5ef 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -673,6 +673,7 @@ impl Game<'_> { && let Some(g) = host.hub.guest(conn) { // PlayerList.placeNewPlayer, then the broadcast join message. + super::dedicated::remember(&g.name, g.uuid); let [x, y, z] = g.position; super::dedicated::log( "INFO", diff --git a/crates/horizon-server-files/Cargo.toml b/crates/horizon-server-files/Cargo.toml index 52114718d..184dadc90 100644 --- a/crates/horizon-server-files/Cargo.toml +++ b/crates/horizon-server-files/Cargo.toml @@ -4,13 +4,15 @@ version = "0.1.0" edition.workspace = true license.workspace = true rust-version = "1.90" -description = "The dedicated server's vanilla files: server.properties, eula.txt, ops, whitelist and bans" +description = "The dedicated server's vanilla files: server.properties, eula.txt, ops, whitelist and bans, and account lookups" [dependencies] horizon-core = { path = "../horizon-core" } horizon-protocol = { path = "../horizon-protocol" } horizon-world = { path = "../horizon-world" } log = "0.4" +# Online mode: finding accounts by name (the services' profiles endpoint). +ureq = { version = "2", default-features = false, features = ["tls"] } [lints] workspace = true diff --git a/crates/horizon-server-files/src/lib.rs b/crates/horizon-server-files/src/lib.rs index 30c75c869..babb02771 100644 --- a/crates/horizon-server-files/src/lib.rs +++ b/crates/horizon-server-files/src/lib.rs @@ -1,10 +1,12 @@ //! The dedicated server's files and settings, ported from //! net.minecraft.server.dedicated and net.minecraft.server.players: -//! server.properties, eula.txt and the four user lists. The game's dedicated -//! server (`horizon-client --dedicated`) reads them, and `horizon-server` -//! manages them; this crate needs neither a window nor the game. +//! server.properties, eula.txt, the four user lists and looking players up +//! by name in online mode. The game's dedicated server +//! (`horizon-client --dedicated`) reads them, and `horizon-server` manages +//! them; this crate needs neither a window nor the game. pub mod eula; pub mod java_properties; pub mod json; +pub mod profiles; pub mod properties; pub mod user_lists; diff --git a/crates/horizon-server-files/src/profiles.rs b/crates/horizon-server-files/src/profiles.rs new file mode 100644 index 000000000..a093fbfb1 --- /dev/null +++ b/crates/horizon-server-files/src/profiles.rs @@ -0,0 +1,100 @@ +//! Finding a player's account by name, as an online-mode server does for the +//! names given to `op`, `whitelist` and `ban` (CachedUserNameToIdResolver, +//! MinecraftServicesProfileRepository.findProfileByName): the services' +//! `profiles` / `getByName` endpoint, found through the discovery document. +use crate::{ + json::{self, Json}, + user_lists::NameAndId, +}; +use std::time::Duration; + +/// Mojang's services discovery document. +pub const DEFAULT_DISCOVERY: &str = "https://discovery.minecraftservices.com/minecraft/client"; + +/// The discovery document's URL: `HORIZON_API_DISCOVERY` overrides it like +/// authlib's `-Dminecraft.api.discovery.host`. +pub fn discovery_url() -> String { + std::env::var("HORIZON_API_DISCOVERY") + .ok() + .filter(|u| !u.is_empty()) + .unwrap_or_else(|| DEFAULT_DISCOVERY.to_owned()) +} + +/// StringUtil.isValidPlayerName: at most 16 UTF-16 units, none a control +/// character, a space or above ASCII. +pub fn valid_player_name(name: &str) -> bool { + name.encode_utf16().count() <= 16 && name.encode_utf16().all(|c| c > 32 && c < 127) +} + +/// How a server resolves a name it was given (CachedUserNameToIdResolver.get, +/// without the usercache.json cache): an offline server makes the offline +/// profile; an online one asks the services (for the name in lower case) and +/// knows nobody they don't. +pub fn resolve(name: &str, online: bool) -> Option { + if online && valid_player_name(name) { + find_by_name(&discovery_url(), &name.to_ascii_lowercase()) + } else { + (!online).then(|| NameAndId::offline(name)) + } +} + +/// MinecraftServicesProfileRepository.findProfileByName: the account named +/// `name` (any case), or None when there is none or the services don't +/// answer (vanilla logs both as "Couldn't find profile with name"). +pub fn find_by_name(discovery: &str, name: &str) -> Option { + let agent = ureq::AgentBuilder::new() + .timeout(Duration::from_secs(15)) + .user_agent(concat!("Horizon/", env!("CARGO_PKG_VERSION"))) + .build(); + let doc = json::parse(&agent.get(discovery).call().ok()?.into_string().ok()?, true).ok()?; + let url = endpoint(&doc, "profiles", "getByName")?.replace("{name}", &name.to_lowercase()); + found(&agent.get(&url).call().ok()?.into_string().ok()?, name) +} + +/// MinecraftServicesDiscoveryService.getUrl(service, endpoint). +fn endpoint(doc: &Json, service: &str, name: &str) -> Option { + doc.get("discovery")? + .get(service)? + .get("endpoints")? + .get(name)? + .get("uri")? + .as_string() +} + +/// The answer, authlib's NameAndId: `{"id", "name"}`, the id undashed. +pub fn found(answer: &str, name: &str) -> Option { + let profile = json::parse(answer, true).ok()?; + let found = profile.get("name")?.as_string()?; + let id = profile.get("id")?.as_string()?.replace('-', ""); + (found.eq_ignore_ascii_case(name) && id.len() == 32).then_some(())?; + Some(NameAndId { + id: u128::from_str_radix(&id, 16).ok()?, + name: found, + }) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn names_and_answers() { + assert!(valid_player_name("Alex_123")); + assert!(!valid_player_name("two words")); + assert!(!valid_player_name("ThisNameIsTooLong")); + assert!(!valid_player_name("caf\u{e9}")); + assert_eq!(resolve("Alex", false), Some(NameAndId::offline("Alex"))); + assert_eq!(resolve("not valid", true), None); + let answer = r#"{"id":"069a79f444e94726a5befca90e38aaf5","name":"Notch"}"#; + assert_eq!( + found(answer, "notch"), + Some(NameAndId { + id: 0x069a79f444e94726a5befca90e38aaf5, + name: "Notch".into() + }) + ); + assert_eq!(found(answer, "Steve"), None); + assert_eq!(found("{}", "Notch"), None); + assert_eq!(found("", "Notch"), None); + } +} diff --git a/crates/horizon-server/src/config.rs b/crates/horizon-server/src/config.rs index c62869e27..3c389f858 100644 --- a/crates/horizon-server/src/config.rs +++ b/crates/horizon-server/src/config.rs @@ -23,7 +23,7 @@ motd = "A Minecraft Server" port = 25565 bind = "" # listen on every address, or only on this one (server-ip) max_players = 20 -online_mode = true # not supported by Horizon yet: the server runs offline and says so +online_mode = true # check players' Minecraft accounts (false: anyone joins under any name) whitelist = true # only whitelisted players and operators can join enforce_whitelist = false # kick online players taken off the whitelist view_distance = 10 diff --git a/crates/horizon-server/src/init.rs b/crates/horizon-server/src/init.rs index 37e43df80..757b6def8 100644 --- a/crates/horizon-server/src/init.rs +++ b/crates/horizon-server/src/init.rs @@ -6,7 +6,7 @@ use crate::{config, config::Config, engine}; use horizon_server_files::{ eula, java_properties::now_millis, - user_lists::{NameAndId, OpEntry, OpList, WhiteEntry, WhiteList}, + user_lists::{OpEntry, OpList, WhiteEntry, WhiteList}, }; use std::{ io::{BufRead, IsTerminal, Write}, @@ -23,6 +23,8 @@ pub struct Answers { pub whitelist: Option, pub players: Vec, pub op: Option, + /// online-mode (true unless set): players' Minecraft accounts are checked. + pub online: Option, /// Take the default for every question not answered by a flag. pub yes: bool, } @@ -30,7 +32,7 @@ pub struct Answers { impl Answers { /// The answers in the environment, for containers: `HORIZON_EULA=true`, `HORIZON_WORLD`, /// `HORIZON_SEED`, `HORIZON_PORT`, `HORIZON_WHITELIST=true|false`, `HORIZON_PLAYERS` (names separated by - /// commas) and `HORIZON_OP`. Flags given on the command line win. + /// commas), `HORIZON_OP` and `HORIZON_ONLINE=true|false`. Flags given on the command line win. pub fn from_env() -> Result { let var = |name: &str| std::env::var(name).ok().filter(|v| !v.is_empty()); let flag = |name: &str| var(name).map(|v| v.eq_ignore_ascii_case("true")); @@ -54,6 +56,7 @@ impl Answers { }) .unwrap_or_default(), op: var("HORIZON_OP"), + online: flag("HORIZON_ONLINE"), yes: false, }) } @@ -172,6 +175,9 @@ pub fn run(dir: &Path, answers: Answers) -> Result<(), String> { } // 4. Who may join. + if let Some(online) = answers.online { + cfg.server.online_mode = online; + } cfg.server.whitelist = answers.whitelist.unwrap_or_else(|| { prompt.yes( "Only let in players you list (whitelist)?", @@ -193,7 +199,7 @@ pub fn run(dir: &Path, answers: Answers) -> Result<(), String> { .yes(&format!("Make {first} an operator?"), true) .then(|| first.clone()) }); - add_players(dir, &players, op.as_deref())?; + add_players(dir, &players, op.as_deref(), cfg.server.online_mode)?; // 5. The game and its files. match engine::program(&cfg, dir) { @@ -213,24 +219,29 @@ pub fn run(dir: &Path, answers: Answers) -> Result<(), String> { toml_path.display(), dir.display() ); - if cfg.server.online_mode { + if !cfg.server.online_mode { println!( - "Note: Horizon's server doesn't check Mojang accounts yet (online mode), so it runs offline: \ - keep the whitelist on, or play on a LAN or a tailnet." + "Note: online mode is off, so anyone can join under any name: keep the whitelist on, or play on a \ + LAN or a tailnet." ); } Ok(()) } -/// Adds players to the whitelist (and one as an operator) in vanilla's files, with offline UUIDs as the -/// server runs offline. -fn add_players(dir: &Path, players: &[String], op: Option<&str>) -> Result<(), String> { +/// Adds players to the whitelist (and one as an operator) in vanilla's files, with the profiles the server +/// will see: offline ones, or in online mode their accounts. +fn add_players( + dir: &Path, + players: &[String], + op: Option<&str>, + online: bool, +) -> Result<(), String> { if !players.is_empty() { let mut white = WhiteList::new(dir.join("whitelist.json")); let _ = white.load(); for name in players { white.add(WhiteEntry { - user: NameAndId::offline(name), + user: crate::lists::account(name, online)?, }); } println!("Whitelisted: {}", players.join(", ")); @@ -239,7 +250,7 @@ fn add_players(dir: &Path, players: &[String], op: Option<&str>) -> Result<(), S let mut ops = OpList::new(dir.join("ops.json")); let _ = ops.load(); ops.add(OpEntry { - user: NameAndId::offline(name), + user: crate::lists::account(name, online)?, level: 4, bypasses_player_limit: false, }); @@ -264,6 +275,8 @@ mod tests { whitelist: Some(true), players: vec!["Alex".into(), "Steve".into()], op: Some("Alex".into()), + // Offline: no account lookups in a test. + online: Some(false), yes: true, }; run(&dir, answers).unwrap(); @@ -277,6 +290,7 @@ mod tests { ("survival", "12345", 25599) ); assert!(eula::agreed(&dir.join("eula.txt")).unwrap()); + assert!(!cfg.server.online_mode); let white = std::fs::read_to_string(dir.join("whitelist.json")).unwrap(); assert!( white.contains("\"Alex\"") && white.contains("\"Steve\""), diff --git a/crates/horizon-server/src/lists.rs b/crates/horizon-server/src/lists.rs index 398ccfe10..a6c466666 100644 --- a/crates/horizon-server/src/lists.rs +++ b/crates/horizon-server/src/lists.rs @@ -20,7 +20,7 @@ pub fn run(dir: &Path, command: &str, args: &[String]) -> Result<(), String> { let message = match (command, args.as_slice()) { ("op", [name]) => { let mut ops = load(OpList::new(ops_path))?; - let user = NameAndId::offline(name); + let user = account(name, config.server.online_mode)?; if ops.contains(&user) { "Nothing changed. The player already is an operator".to_owned() } else { @@ -34,7 +34,8 @@ pub fn run(dir: &Path, command: &str, args: &[String]) -> Result<(), String> { } ("deop", [name]) => { let mut ops = load(OpList::new(ops_path))?; - if ops.remove(&NameAndId::offline(name)) { + let user = listed(ops.entries().iter().map(|e| &e.user), name); + if user.is_some_and(|user| ops.remove(&user)) { format!("Made {name} no longer a server operator") } else { "Nothing changed. The player is not an operator".to_owned() @@ -42,7 +43,7 @@ pub fn run(dir: &Path, command: &str, args: &[String]) -> Result<(), String> { } ("whitelist", ["add", name]) => { let mut white = load(WhiteList::new(white_path))?; - let user = NameAndId::offline(name); + let user = account(name, config.server.online_mode)?; if white.contains(&user) { "Player is already whitelisted".to_owned() } else { @@ -52,7 +53,8 @@ pub fn run(dir: &Path, command: &str, args: &[String]) -> Result<(), String> { } ("whitelist", ["remove", name]) => { let mut white = load(WhiteList::new(white_path))?; - if white.remove(&NameAndId::offline(name)) { + let user = listed(white.entries().iter().map(|e| &e.user), name); + if user.is_some_and(|user| white.remove(&user)) { format!("Removed {name} from the whitelist") } else { "Player is not whitelisted".to_owned() @@ -97,6 +99,23 @@ pub fn run(dir: &Path, command: &str, args: &[String]) -> Result<(), String> { Ok(()) } +/// The profile a running server would store for `name`: the offline one, or in online mode the account the +/// services know by that name. +pub fn account(name: &str, online: bool) -> Result { + horizon_server_files::profiles::resolve(name, online).ok_or_else(|| { + if online { + format!("That player does not exist (no Minecraft account is named {name}, or the services didn't answer)") + } else { + "That player does not exist".to_owned() + } + }) +} + +/// The entry already on a list under `name` (any case), so removing needs no lookup. +fn listed<'a>(mut users: impl Iterator, name: &str) -> Option { + users.find(|u| u.name.eq_ignore_ascii_case(name)).cloned() +} + /// A list from its file; a missing file is an empty list, a broken one an error (vanilla would replace it). fn load( mut list: horizon_server_files::user_lists::UserList, diff --git a/crates/horizon-server/src/main.rs b/crates/horizon-server/src/main.rs index af45015de..c37da27a5 100644 --- a/crates/horizon-server/src/main.rs +++ b/crates/horizon-server/src/main.rs @@ -23,7 +23,7 @@ Usage: horizon-server [--dir DIR] init Set up a server here: the EULA, the world, the port, who may join (asks, or takes flags: --eula --world NAME --seed SEED --port N --whitelist/--no-whitelist --player NAME... --op NAME - --yes) + --offline --yes) run Run the server in the foreground; type console commands, Ctrl-C stops it cleanly. It restarts the game if it crashes. start Run the server in the background (its output goes to logs/supervisor.log) @@ -150,6 +150,7 @@ fn init_answers(args: &[String]) -> Result { "--no-whitelist" => answers.whitelist = Some(false), "--player" => answers.players.push(value(arg)?), "--op" => answers.op = Some(value(arg)?), + "--offline" => answers.online = Some(false), other => return Err(format!("init: unknown option {other}")), } } diff --git a/tools/test_online_mode_parity.py b/tools/test_online_mode_parity.py index 8e349bf0d..e6679b7b5 100644 --- a/tools/test_online_mode_parity.py +++ b/tools/test_online_mode_parity.py @@ -21,7 +21,10 @@ Also checked, with vanilla's messages: - a token the session service rejects ("Failed to log in: Invalid session"); - a join the session service forgets (the server: "Failed to verify username!"); - no account at all (the client refuses before joining); -- a verified player the whitelist refuses. +- a verified player the whitelist refuses; +- `whitelist add` in online mode: a player who joined before is known by name + and let in; another name is looked up through the services' profile lookup, + and one with no account is refused ("That player does not exist"). Horizon's dedicated server then runs the same steps in online mode (`HORIZON_API_DISCOVERY` points it at the mock too): it must give the client @@ -100,6 +103,14 @@ class Services: query = dict(urllib.parse.parse_qsl(url.query)) if url.path == '/minecraft/client': return self.reply(200, services.discovery()) + if url.path.startswith('/users/profiles/minecraft/'): + # profiles/getByName: the account with that name, ignoring case. + name = urllib.parse.unquote(url.path.rsplit('/', 1)[1]) + with services.lock: + services.log.append(('lookup', name)) + if name.lower() == PLAYER.lower(): + return self.reply(200, {'id': PLAYER_UUID, 'name': PLAYER}) + return self.reply(404, {'error': 'NOT_FOUND', 'errorMessage': f'Couldn\'t find any profile with name {name}'}) if url.path == '/session/minecraft/hasJoined': with services.lock: ok = services.joined.get(query.get('username')) == query.get('serverId') @@ -107,11 +118,15 @@ class Services: if ok: return self.reply(200, {'id': PLAYER_UUID, 'name': query['username'], 'properties': []}) return self.reply(204) + with services.lock: + services.log.append(('unknown', url.path)) self.reply(404, {'error': 'NotFound', 'path': url.path}) def do_POST(self): body = json.loads(self.rfile.read(int(self.headers.get('Content-Length', 0))) or b'{}') if self.path != '/session/minecraft/join': + with services.lock: + services.log.append(('unknown', self.path)) return self.reply(404, {'error': 'NotFound'}) token, profile, server_id = body.get('accessToken'), body.get('selectedProfile'), body.get('serverId') accepted = token in (GOOD, FORGET) and profile == PLAYER_UUID @@ -135,7 +150,8 @@ class Services: 'session': endpoints(join='/session/minecraft/join', verify='/session/minecraft/hasJoined', getProfileById='/session/minecraft/profile/{profileId}'), 'player': {'endpoints': {}}, - 'profiles': {'endpoints': {'getTexture': {'validUris': [self.url + '/texture/{textureId}']}}}, + 'profiles': {'endpoints': {'getTexture': {'validUris': [self.url + '/texture/{textureId}']}, + 'getByName': {'uri': self.url + '/users/profiles/minecraft/{name}'}}}, 'telemetry': {'endpoints': {}}, }} @@ -189,8 +205,19 @@ def player_lines(lines): return out +def wait_after(server, mark, pattern, timeout=30): + """A line matching `pattern` among those the server printed after `mark`.""" + regex = re.compile(pattern) + deadline = time.time() + timeout + while time.time() < deadline: + if any(regex.search(l) for l in server.lines[mark:]): + return + time.sleep(0.2) + raise AssertionError(f'no {pattern!r} after line {mark} of {server.log_path.name}') + + def run_side(label, command, binary, build, services, discovery): - """The five logins against one server; its checks and its log about the player.""" + """The six logins against one server; its checks and its log about the player.""" port = free_port() directory = build / label shutil.rmtree(directory, ignore_errors=True) @@ -261,6 +288,24 @@ def run_side(label, command, binary, build, services, discovery): check('not whitelisted: client message', got['error'], 'disconnected: You are not white-listed on this server!') check('not whitelisted: verified first', [(e[0], e[3]) for e in services.take_log()], [('join', True), ('verify', True)]) + + # 6. Whitelisted by name: the server knows the player from their first join (its name cache), so it + # asks the services nothing, and lets them in. + mark = len(server.lines) + server.console('whitelist add tester') + wait_after(server, mark, r'Added Tester to the whitelist') + check('whitelist add: known player, no lookup', services.take_log(), []) + got = run_client(binary, build, port, f'{label}-whitelisted', GOOD, discovery) + wait_after(server, mark, r'Tester left the game') + check('whitelisted: connected throughout', got['error'], None) + services.take_log() + # A name nobody joined with: the server looks the account up, and there is none. + mark = len(server.lines) + server.console('whitelist add Nobody') + wait_after(server, mark, r'That player does not exist') + check('whitelist add: lookup failure logged', + any("Couldn't find profile with name: nobody" in l for l in server.lines[mark:]), True) + check('whitelist add: no such account', services.take_log(), [('lookup', 'nobody')]) time.sleep(1) finally: server.stop() @@ -310,7 +355,7 @@ def main(): java=subprocess.check_output(['java', '--version'], text=True).splitlines()[0], checks=len(checks), scope='Online-mode login against vanilla\'s dedicated server and Horizon\'s, with a mock session service: ' 'server hash, RSA key packet, AES/CFB8, session join and verify, play; rejected token, forgotten ' - 'join, no account, whitelist; the servers\' log lines about the player.')) + 'join, no account, whitelist, whitelist add by account name; the servers\' log lines about the player.')) print(f'online mode: {len(checks)} checks ok') From 78791b79ceb6c7c7dc6f1fa4b02e2d6e91f2f3d4 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Sat, 17 Oct 2026 01:03:14 +0100 Subject: [PATCH 02/46] Cache resolved block behaviours across launches --- Cargo.lock | 57 ++ crates/horizon-world/Cargo.toml | 3 + .../examples/behaviour_load_profile.rs | 27 + crates/horizon-world/src/level/data.rs | 17 +- crates/horizon-world/src/level/data/cache.rs | 810 ++++++++++++++++++ tools/profile_client_startup.py | 49 ++ 6 files changed, 960 insertions(+), 3 deletions(-) create mode 100644 crates/horizon-world/examples/behaviour_load_profile.rs create mode 100644 crates/horizon-world/src/level/data/cache.rs create mode 100644 tools/profile_client_startup.py diff --git a/Cargo.lock b/Cargo.lock index 1d5897d11..9726316b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,6 +196,15 @@ dependencies = [ "libloading", ] +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + [[package]] name = "atomic-waker" version = "1.1.2" @@ -322,6 +331,12 @@ dependencies = [ "syn 3.0.6", ] +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + [[package]] name = "bytes" version = "1.12.1" @@ -742,6 +757,12 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "critical-section" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" + [[package]] name = "crossbeam-utils" version = "0.8.23" @@ -1307,6 +1328,15 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + [[package]] name = "hashbrown" version = "0.15.5" @@ -1337,6 +1367,20 @@ dependencies = [ "foldhash 0.2.0", ] +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32", + "rustc_version", + "serde", + "spin", + "stable_deref_trait", +] + [[package]] name = "heck" version = "0.5.0" @@ -1608,7 +1652,10 @@ dependencies = [ "horizon-core", "libm", "lz4_flex", + "postcard", + "serde", "serde_json", + "sha2", "xxhash-rust", ] @@ -2872,6 +2919,7 @@ dependencies = [ "cobs", "embedded-io 0.4.0", "embedded-io 0.6.1", + "heapless", "serde", ] @@ -3458,6 +3506,15 @@ dependencies = [ "sha2", ] +[[package]] +name = "spin" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" +dependencies = [ + "lock_api", +] + [[package]] name = "spirv" version = "0.4.0+sdk-1.4.341.0" diff --git a/crates/horizon-world/Cargo.toml b/crates/horizon-world/Cargo.toml index 078692bff..3e5f9466d 100644 --- a/crates/horizon-world/Cargo.toml +++ b/crates/horizon-world/Cargo.toml @@ -9,6 +9,9 @@ description = "Horizon vanilla world data, NBT, regions and chunk storage" [dependencies] libm = "=0.2.16" serde_json = { version = "1.0.151", features = ["raw_value"] } +serde = { version = "1", features = ["derive"] } +sha2 = "0.10" +postcard = { version = "=1.1.3", features = ["alloc"] } horizon-core = { path = "../horizon-core" } flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"] } lz4_flex = { version = "0.14", default-features = false, features = ["std", "safe-encode", "safe-decode", "checked-decode"] } diff --git a/crates/horizon-world/examples/behaviour_load_profile.rs b/crates/horizon-world/examples/behaviour_load_profile.rs new file mode 100644 index 000000000..e6619afa1 --- /dev/null +++ b/crates/horizon-world/examples/behaviour_load_profile.rs @@ -0,0 +1,27 @@ +//! Measure registry and behaviour load times using prepared client resources. +use horizon_world::level::{Behaviours, data::load_registry}; +use std::{path::Path, time::Instant}; + +fn main() -> Result<(), Box> { + let root = std::env::args() + .nth(1) + .expect("resource directory argument"); + let root = Path::new(&root); + let started = Instant::now(); + let registry = load_registry(root)?; + eprintln!( + "registry_ms={:.3}", + started.elapsed().as_secs_f64() * 1000.0 + ); + for iteration in 0..3 { + let started = Instant::now(); + let behaviours = Behaviours::load(®istry, root)?; + eprintln!( + "behaviours_{}_ms={:.3}", + iteration, + started.elapsed().as_secs_f64() * 1000.0 + ); + std::hint::black_box(behaviours); + } + Ok(()) +} diff --git a/crates/horizon-world/src/level/data.rs b/crates/horizon-world/src/level/data.rs index 455a2ed57..83349232c 100644 --- a/crates/horizon-world/src/level/data.rs +++ b/crates/horizon-world/src/level/data.rs @@ -21,6 +21,8 @@ use std::{ path::Path, sync::Arc, }; +#[path = "data/cache.rs"] +mod cache; /// Per-state flags read from vanilla accessors over an empty level. pub mod state_flags { @@ -251,7 +253,7 @@ macro_rules! named_blocks { #[derive(Clone, Copy, Debug)] pub struct Named { $(pub $field: BlockId,)* } impl Named { - fn resolve(table: &StateTable) -> io::Result { + pub(super) fn resolve(table: &StateTable) -> io::Result { Ok(Self { $($field: table.block_by_name(concat!("minecraft:", $name)).ok_or_else(|| invalid(concat!("missing block ", $name)))?,)* }) } } @@ -393,7 +395,7 @@ macro_rules! tags { #[derive(Clone, Debug, Default)] pub struct Tags { $(pub $field: Arc,)* } impl Tags { - fn resolve(all: &HashMap>) -> Self { + pub(super) fn resolve(all: &HashMap>) -> Self { Self { $($field: all.get(concat!("minecraft:", $name)).cloned().unwrap_or_default(),)* } } } @@ -487,7 +489,7 @@ macro_rules! props { #[derive(Clone, Copy, Debug)] pub struct Props { $(pub $field: PropKey,)* } impl Props { - fn resolve(table: &mut StateTable) -> Self { + pub(super) fn resolve(table: &mut StateTable) -> Self { Self { $($field: table.key($name),)* } } } @@ -653,6 +655,15 @@ pub fn load_registry(root: &Path) -> io::Result { } pub(super) fn load(registry: &BlockRegistry, root: &Path) -> io::Result { + if let Some(behaviours) = cache::load(registry, root) { + return Ok(behaviours); + } + let behaviours = load_uncached(registry, root)?; + cache::store(registry, root, &behaviours); + Ok(behaviours) +} + +fn load_uncached(registry: &BlockRegistry, root: &Path) -> io::Result { let mut table = StateTable::new(registry)?; let props = Props::resolve(&mut table); let named = Named::resolve(&table)?; diff --git a/crates/horizon-world/src/level/data/cache.rs b/crates/horizon-world/src/level/data/cache.rs new file mode 100644 index 000000000..3a18a7131 --- /dev/null +++ b/crates/horizon-world/src/level/data/cache.rs @@ -0,0 +1,810 @@ +//! A disposable, versioned snapshot of resolved behaviour tables. +//! +//! The source resources remain authoritative. Failed reads, unsupported +//! versions, corrupt payloads and write failures always use the normal loader. +use super::*; +use serde::{Deserialize, Serialize}; +use sha2::{Digest, Sha256}; +use std::{ + io::Write, + path::PathBuf, + sync::atomic::{AtomicU64, Ordering}, +}; + +const MAGIC: &[u8; 8] = b"HZBEHAV\0"; +const VERSION: u32 = 2; +const FILE_NAME: &str = ".horizon-behaviours-v2.bin"; +const MAX_FILE_BYTES: usize = 128 * 1024 * 1024; +const MAX_DECODED_BYTES: usize = 256 * 1024 * 1024; +static NEXT_TEMP: AtomicU64 = AtomicU64::new(0); + +#[derive(Serialize, Deserialize)] +struct Snapshot { + tags: HashMap>, + facts: Vec, + shapes: Vec, + shape_info: Vec<[u8; 3]>, + fluid_tags: [u8; 6], + blocks: Vec, + items: HashMap, +} + +#[derive(Serialize, Deserialize)] +struct Fact { + flags: u32, + sturdy: u32, + weak: u32, + strong: u32, + fluid_kind: u8, + fluid_amount: u8, + fluid_falling: bool, + emission: u8, + dampening: u8, + hardness: f32, + push: u8, + instrument: u8, + shape: i32, +} + +#[derive(Serialize, Deserialize)] +struct Shape { + coords: [Vec; 3], + occupied: Vec, + cube: bool, + coordinate_cubes: [bool; 3], + min: [i32; 3], + max: [i32; 3], + /// Preserve the shared singleton identities used by vanilla shape shortcuts. + singleton: u8, +} + +#[derive(Serialize, Deserialize)] +struct SetTypeSnapshot { + name: String, + can_open_by_hand: bool, + can_open_by_wind_charge: bool, + arrows: bool, + mobs_only: bool, + door_open: String, + door_close: String, + trapdoor_open: String, + trapdoor_close: String, + plate_on: String, + plate_off: String, + button_on: String, + button_off: String, +} + +#[derive(Serialize, Deserialize)] +struct SoundsSnapshot { + volume: f32, + pitch: f32, + place: String, + break_: String, + fall: String, +} + +#[derive(Serialize, Deserialize)] +struct Block { + chain: Vec, + interfaces: u16, + set_type: Option, + gate_open: Option, + gate_close: Option, + open_sound: Option, + close_sound: Option, + ticks_to_stay_pressed: i32, + max_weight: i32, + link: Option, + link2: Option, + support_tag: Option>, + support_tag2: Option>, + feature: Option, + grow_probability: f64, + growth_direction: u8, + schedule_fluid_ticks: bool, + weather: u8, + ignite_odds: i32, + burn_odds: i32, + sounds: SoundsSnapshot, + item: String, + dynamic_shape: bool, +} + +#[derive(Serialize, Deserialize)] +struct Item { + block: u16, + wall_block: Option, + attachment: Option, + kind: u8, + game_master: bool, +} + +fn fingerprint(registry: &BlockRegistry, root: &Path) -> io::Result<[u8; 32]> { + let mut hasher = Sha256::new(); + hasher.update(b"horizon resolved behaviours 2"); + for relative in [ + "facts.json", + "block-behaviours.json", + "gameplay-facts.json", + "block-tags.json", + "cached-collision.nbt", + ] { + hash_file(&mut hasher, root, &root.join(relative))?; + } + let mut fluids: Vec = fs::read_dir(root.join("data/minecraft/tags/fluid"))? + .map(|entry| entry.map(|entry| entry.path())) + .collect::>()?; + fluids.sort(); + for path in fluids { + hash_file(&mut hasher, root, &path)?; + } + // The registry argument may be modified independently of facts.json. + hasher.update((registry.len() as u64).to_le_bytes()); + let mut seen = std::collections::HashSet::new(); + for index in 0..registry.len() { + let state = registry + .state(BlockStateId(index as u32)) + .ok_or_else(|| invalid("missing registry state"))?; + hash_str(&mut hasher, &state.name); + let mut props: Vec<_> = state.properties.iter().collect(); + props.sort_by_key(|(key, _)| *key); + hasher.update((props.len() as u32).to_le_bytes()); + for (key, value) in props { + hash_str(&mut hasher, key); + hash_str(&mut hasher, value); + } + if seen.insert(state.name.as_str()) { + let default = registry + .default_state(&state.name) + .ok_or_else(|| invalid("missing default state"))?; + hasher.update(default.0.to_le_bytes()); + } + } + Ok(hasher.finalize().into()) +} + +fn hash_str(hasher: &mut Sha256, text: &str) { + hasher.update((text.len() as u64).to_le_bytes()); + hasher.update(text.as_bytes()); +} + +fn hash_file(hasher: &mut Sha256, root: &Path, path: &Path) -> io::Result<()> { + let relative = path + .strip_prefix(root) + .map_err(|e| invalid(e.to_string()))?; + hash_str(hasher, &relative.to_string_lossy()); + let bytes = fs::read(path)?; + hasher.update((bytes.len() as u64).to_le_bytes()); + hasher.update(bytes); + Ok(()) +} + +fn direction(index: u8) -> io::Result { + Direction::ALL + .get(index as usize) + .copied() + .ok_or_else(|| invalid("cached direction out of range")) +} +fn direction_index(direction: Direction) -> u8 { + Direction::ALL.iter().position(|d| *d == direction).unwrap() as u8 +} +fn class(index: u16) -> io::Result { + Class::ALL + .get(index as usize) + .copied() + .ok_or_else(|| invalid("cached block class out of range")) +} +fn kind(index: u8) -> io::Result { + Ok(match index { + 0 => ItemKind::Block, + 1 => ItemKind::DoubleHigh, + 2 => ItemKind::StandingAndWall, + 3 => ItemKind::Scaffolding, + 4 => ItemKind::PlaceOnWater, + 5 => ItemKind::HangingSign, + 6 => ItemKind::SolidBucket, + 7 => ItemKind::Other, + _ => return Err(invalid("cached item kind out of range")), + }) +} +fn kind_index(kind: ItemKind) -> u8 { + match kind { + ItemKind::Block => 0, + ItemKind::DoubleHigh => 1, + ItemKind::StandingAndWall => 2, + ItemKind::Scaffolding => 3, + ItemKind::PlaceOnWater => 4, + ItemKind::HangingSign => 5, + ItemKind::SolidBucket => 6, + ItemKind::Other => 7, + } +} +fn push(index: u8) -> io::Result { + Ok(match index { + 0 => PushReaction::PushPull, + 1 => PushReaction::Push, + 2 => PushReaction::Popped, + 3 => PushReaction::Immoveable, + 4 => PushReaction::IgnoreEntity, + _ => return Err(invalid("cached push reaction out of range")), + }) +} +fn push_index(push: PushReaction) -> u8 { + match push { + PushReaction::PushPull => 0, + PushReaction::Push => 1, + PushReaction::Popped => 2, + PushReaction::Immoveable => 3, + PushReaction::IgnoreEntity => 4, + } +} + +impl From<&SetType> for SetTypeSnapshot { + fn from(value: &SetType) -> Self { + Self { + name: value.name.to_string(), + can_open_by_hand: value.can_open_by_hand, + can_open_by_wind_charge: value.can_open_by_wind_charge, + arrows: value.arrows, + mobs_only: value.mobs_only, + door_open: value.door_open.to_string(), + door_close: value.door_close.to_string(), + trapdoor_open: value.trapdoor_open.to_string(), + trapdoor_close: value.trapdoor_close.to_string(), + plate_on: value.plate_on.to_string(), + plate_off: value.plate_off.to_string(), + button_on: value.button_on.to_string(), + button_off: value.button_off.to_string(), + } + } +} +impl From for SetType { + fn from(value: SetTypeSnapshot) -> Self { + Self { + name: value.name.into(), + can_open_by_hand: value.can_open_by_hand, + can_open_by_wind_charge: value.can_open_by_wind_charge, + arrows: value.arrows, + mobs_only: value.mobs_only, + door_open: Arc::from(value.door_open), + door_close: Arc::from(value.door_close), + trapdoor_open: Arc::from(value.trapdoor_open), + trapdoor_close: Arc::from(value.trapdoor_close), + plate_on: Arc::from(value.plate_on), + plate_off: Arc::from(value.plate_off), + button_on: Arc::from(value.button_on), + button_off: Arc::from(value.button_off), + } + } +} +impl From<&Sounds> for SoundsSnapshot { + fn from(value: &Sounds) -> Self { + Self { + volume: value.volume, + pitch: value.pitch, + place: value.place.to_string(), + break_: value.break_.to_string(), + fall: value.fall.to_string(), + } + } +} +impl From for Sounds { + fn from(value: SoundsSnapshot) -> Self { + Self { + volume: value.volume, + pitch: value.pitch, + place: Arc::from(value.place), + break_: Arc::from(value.break_), + fall: Arc::from(value.fall), + } + } +} + +impl Snapshot { + fn capture(behaviours: &Behaviours) -> Self { + let tags = behaviours + .all_tags + .iter() + .map(|(key, value)| (key.clone(), value.0.clone())) + .collect(); + let facts = behaviours + .facts + .iter() + .map(|fact| Fact { + flags: fact.flags, + sturdy: fact.sturdy, + weak: fact.weak, + strong: fact.strong, + fluid_kind: fact.fluid.kind() as u8, + fluid_amount: fact.fluid.amount(), + fluid_falling: fact.fluid.falling(), + emission: fact.emission, + dampening: fact.dampening, + hardness: fact.hardness, + push: push_index(fact.push), + instrument: fact.instrument, + shape: fact.shape, + }) + .collect(); + let shapes = behaviours + .shapes + .iter() + .map(|shape| { + let sizes = shape.sizes(); + let mut occupied = Vec::with_capacity(sizes.iter().product()); + for x in 0..sizes[0] { + for y in 0..sizes[1] { + for z in 0..sizes[2] { + occupied.push(shape.is_full(x as i32, y as i32, z as i32)); + } + } + } + let (min, max) = shape.discrete_bounds(); + Shape { + coords: std::array::from_fn(|axis| { + shape + .coordinates( + [ + horizon_core::geometry::Axis::X, + horizon_core::geometry::Axis::Y, + horizon_core::geometry::Axis::Z, + ][axis], + ) + .to_vec() + }), + occupied, + cube: shape.is_cube(), + coordinate_cubes: shape.cube_coordinate_axes(), + min, + max, + singleton: if shape.same_identity(&VoxelShape::block()) { + 1 + } else if shape.same_identity(&VoxelShape::empty()) { + 2 + } else { + 0 + }, + } + }) + .collect(); + let shape_info = behaviours + .shape_info + .iter() + .map(|info| [info.full_faces, info.nonempty_faces, info.wall_cover]) + .collect(); + let tags = tags; + let f = behaviours.fluid_tags; + let fluid_tags = [ + f.water, + f.lava, + f.supports_frogspawn, + f.supports_lily_pad, + f.supports_sugar_cane_adjacently, + f.bubble_column_can_occupy, + ]; + let blocks = behaviours + .blocks + .iter() + .map(|block| Block { + chain: block.chain.iter().map(|class| *class as u16).collect(), + interfaces: block.interfaces, + set_type: block + .set_type + .as_ref() + .map(|value| SetTypeSnapshot::from(value.as_ref())), + gate_open: block.gate_open.as_ref().map(|v| v.to_string()), + gate_close: block.gate_close.as_ref().map(|v| v.to_string()), + open_sound: block.open_sound.as_ref().map(|v| v.to_string()), + close_sound: block.close_sound.as_ref().map(|v| v.to_string()), + ticks_to_stay_pressed: block.ticks_to_stay_pressed, + max_weight: block.max_weight, + link: block.link.map(|v| v.0), + link2: block.link2.map(|v| v.0), + support_tag: block.support_tag.as_ref().map(|v| v.0.clone()), + support_tag2: block.support_tag2.as_ref().map(|v| v.0.clone()), + feature: block.feature.as_ref().map(|v| v.to_string()), + grow_probability: block.grow_probability, + growth_direction: direction_index(block.growth_direction), + schedule_fluid_ticks: block.schedule_fluid_ticks, + weather: block.weather, + ignite_odds: block.ignite_odds, + burn_odds: block.burn_odds, + sounds: SoundsSnapshot::from(block.sounds.as_ref()), + item: block.item.to_string(), + dynamic_shape: block.dynamic_shape, + }) + .collect(); + let items = behaviours + .items + .iter() + .map(|(name, item)| { + ( + name.clone(), + Item { + block: item.block.0, + wall_block: item.wall_block.map(|v| v.0), + attachment: item.attachment.map(direction_index), + kind: kind_index(item.kind), + game_master: item.game_master, + }, + ) + }) + .collect(); + Self { + tags, + facts, + shapes, + shape_info, + fluid_tags, + blocks, + items, + } + } + + fn restore(self, registry: &BlockRegistry) -> io::Result { + let mut table = StateTable::new(registry)?; + let props = Props::resolve(&mut table); + let named = Named::resolve(&table)?; + if self.facts.len() != table.state_count() + || self.blocks.len() != table.block_count() + || self.shape_info.len() != self.shapes.len() + { + return Err(invalid("cached behaviour table size mismatch")); + } + let all_tags: HashMap> = self + .tags + .into_iter() + .map(|(key, value)| (key, Arc::new(BlockSet(value)))) + .collect(); + let tags = Tags::resolve(&all_tags); + let shapes = self + .shapes + .into_iter() + .map(|wire| { + let shape = match wire.singleton { + 1 => VoxelShape::block(), + 2 => VoxelShape::empty(), + 0 => { + if wire.cube { + let sizes = std::array::from_fn(|axis| { + wire.coords[axis].len().saturating_sub(1) + }); + VoxelShape::from_cube(sizes, &wire.occupied) + .map_err(|e| invalid(e.to_string()))? + } else { + VoxelShape::from_mixed_grid( + wire.coords, + &wire.occupied, + wire.coordinate_cubes, + ) + .map_err(|e| invalid(e.to_string()))? + } + } + _ => return Err(invalid("invalid cached shape identity")), + }; + shape + .with_discrete_bounds(wire.min, wire.max) + .map_err(|e| invalid(e.to_string())) + }) + .collect::>>()?; + let shape_info = self + .shape_info + .into_iter() + .map(|row| ShapeInfo { + full_faces: row[0], + nonempty_faces: row[1], + wall_cover: row[2], + }) + .collect(); + let facts = self + .facts + .into_iter() + .map(|wire| { + if wire.shape < -1 || wire.shape >= shapes.len() as i32 { + return Err(invalid("cached shape index out of range")); + } + let fluid_kind = FluidKind::ALL + .get(wire.fluid_kind as usize) + .copied() + .ok_or_else(|| invalid("cached fluid kind out of range"))?; + Ok(StateFacts { + flags: wire.flags, + sturdy: wire.sturdy, + weak: wire.weak, + strong: wire.strong, + fluid: FluidState::new(fluid_kind, wire.fluid_amount, wire.fluid_falling), + emission: wire.emission, + dampening: wire.dampening, + hardness: wire.hardness, + push: push(wire.push)?, + instrument: wire.instrument, + shape: wire.shape, + }) + }) + .collect::>>()?; + let f = self.fluid_tags; + let fluid_tags = FluidTags { + water: f[0], + lava: f[1], + supports_frogspawn: f[2], + supports_lily_pad: f[3], + supports_sugar_cane_adjacently: f[4], + bubble_column_can_occupy: f[5], + }; + let blocks = self + .blocks + .into_iter() + .map(|wire| { + let chain = wire + .chain + .into_iter() + .map(class) + .collect::>>()?; + let mut classes = ClassSet::default(); + for class in &chain { + classes.insert(*class); + } + let class = chain.first().copied().unwrap_or(Class::Block); + for link in [wire.link, wire.link2].into_iter().flatten() { + if link as usize >= table.block_count() { + return Err(invalid("cached block link out of range")); + } + } + Ok(BlockData { + class, + chain, + classes, + interfaces: wire.interfaces, + set_type: wire.set_type.map(|v| Arc::new(SetType::from(v))), + gate_open: wire.gate_open.map(Arc::from), + gate_close: wire.gate_close.map(Arc::from), + open_sound: wire.open_sound.map(Arc::from), + close_sound: wire.close_sound.map(Arc::from), + ticks_to_stay_pressed: wire.ticks_to_stay_pressed, + max_weight: wire.max_weight, + link: wire.link.map(BlockId), + link2: wire.link2.map(BlockId), + support_tag: wire.support_tag.map(|v| Arc::new(BlockSet(v))), + support_tag2: wire.support_tag2.map(|v| Arc::new(BlockSet(v))), + feature: wire.feature.map(Arc::from), + grow_probability: wire.grow_probability, + growth_direction: direction(wire.growth_direction)?, + schedule_fluid_ticks: wire.schedule_fluid_ticks, + weather: wire.weather, + ignite_odds: wire.ignite_odds, + burn_odds: wire.burn_odds, + sounds: Arc::new(Sounds::from(wire.sounds)), + item: Arc::from(wire.item), + dynamic_shape: wire.dynamic_shape, + }) + }) + .collect::>>()?; + let items = self + .items + .into_iter() + .map(|(name, wire)| { + if wire.block as usize >= table.block_count() + || wire + .wall_block + .is_some_and(|id| id as usize >= table.block_count()) + { + return Err(invalid("cached item block out of range")); + } + Ok(( + name, + ItemBinding { + block: BlockId(wire.block), + wall_block: wire.wall_block.map(BlockId), + attachment: wire.attachment.map(direction).transpose()?, + kind: kind(wire.kind)?, + game_master: wire.game_master, + }, + )) + }) + .collect::>>()?; + let liquid_blocks = FluidBlockBindings::new(registry)?; + let mut dynamic = HashMap::new(); + for (id, fact) in facts.iter().enumerate() { + if fact.shape < 0 { + let state = BlockStateId(id as u32); + if let Some(support) = crate::dynamic_support::DynamicSupport::from_state( + registry.state(state).unwrap(), + )? { + dynamic.insert(state, support); + } + } + } + Ok(Behaviours { + table, + props, + named, + tags, + all_tags, + facts, + shapes, + shape_info, + fluid_tags, + blocks, + items, + liquid_blocks, + dynamic, + occlusion_cache: Default::default(), + growth: Default::default(), + }) + } +} + +pub(super) fn load(registry: &BlockRegistry, root: &Path) -> Option { + let fingerprint = fingerprint(registry, root).ok()?; + let bytes = fs::read(root.join(FILE_NAME)).ok()?; + // Validate bounds before decoding untrusted cache contents. + if bytes.len() < 8 + 4 + 32 + 32 || bytes.len() > MAX_FILE_BYTES { + return None; + } + if &bytes[..8] != MAGIC + || u32::from_le_bytes(bytes[8..12].try_into().ok()?) != VERSION + || bytes[12..44] != fingerprint + { + return None; + } + let body = &bytes[76..]; + if Sha256::digest(body).as_slice() != &bytes[44..76] { + return None; + } + let expanded_len = u32::from_le_bytes(body.get(..4)?.try_into().ok()?) as usize; + if expanded_len > MAX_DECODED_BYTES { + return None; + } + let expanded = lz4_flex::decompress_size_prepended(body).ok()?; + let snapshot: Snapshot = postcard::from_bytes(&expanded).ok()?; + snapshot.restore(registry).ok() +} + +pub(super) fn store(registry: &BlockRegistry, root: &Path, behaviours: &Behaviours) { + let _ = write(registry, root, behaviours); +} + +fn write(registry: &BlockRegistry, root: &Path, behaviours: &Behaviours) -> io::Result<()> { + let fingerprint = fingerprint(registry, root)?; + let snapshot = Snapshot::capture(behaviours); + let serialized = postcard::to_allocvec(&snapshot).map_err(|e| invalid(e.to_string()))?; + let body = lz4_flex::compress_prepend_size(&serialized); + if body.len() + 76 > MAX_FILE_BYTES { + return Err(invalid("behaviour cache too large")); + } + let mut bytes = Vec::with_capacity(76 + body.len()); + bytes.extend_from_slice(MAGIC); + bytes.extend_from_slice(&VERSION.to_le_bytes()); + bytes.extend_from_slice(&fingerprint); + bytes.extend_from_slice(&Sha256::digest(&body)); + bytes.extend_from_slice(&body); + let path = root.join(FILE_NAME); + let tmp = root.join(format!( + "{FILE_NAME}.tmp-{}-{}", + std::process::id(), + NEXT_TEMP.fetch_add(1, Ordering::Relaxed) + )); + let result = (|| { + let mut file = fs::OpenOptions::new() + .write(true) + .create_new(true) + .open(&tmp)?; + file.write_all(&bytes)?; + file.sync_all()?; + fs::rename(&tmp, &path) + })(); + if result.is_err() { + let _ = fs::remove_file(&tmp); + } + result +} + +#[cfg(test)] +mod tests { + use super::*; + use std::sync::atomic::AtomicU64; + + static NEXT_FIXTURE: AtomicU64 = AtomicU64::new(0); + + struct FixtureDir(PathBuf); + impl Drop for FixtureDir { + fn drop(&mut self) { + let _ = fs::remove_dir_all(&self.0); + } + } + + fn fixture() -> Option { + let source = std::env::var_os("HORIZON_RESOURCES") + .map(PathBuf::from) + .unwrap_or_else(|| { + Path::new(env!("CARGO_MANIFEST_DIR")).join("../../.local/horizon-client/26.3") + }); + if !source.join("block-behaviours.json").exists() { + eprintln!("skipping behaviour cache tests: no client resources"); + return None; + } + let dir = std::env::temp_dir().join(format!( + "horizon-behaviour-cache-test-{}-{}", + std::process::id(), + NEXT_FIXTURE.fetch_add(1, Ordering::Relaxed), + )); + fs::create_dir_all(dir.join("data/minecraft/tags/fluid")).unwrap(); + for file in [ + "facts.json", + "block-behaviours.json", + "gameplay-facts.json", + "block-tags.json", + "cached-collision.nbt", + ] { + fs::copy(source.join(file), dir.join(file)).unwrap(); + } + for entry in fs::read_dir(source.join("data/minecraft/tags/fluid")).unwrap() { + let entry = entry.unwrap(); + if entry.file_type().unwrap().is_file() { + fs::copy( + entry.path(), + dir.join("data/minecraft/tags/fluid") + .join(entry.file_name()), + ) + .unwrap(); + } + } + Some(FixtureDir(dir)) + } + + #[test] + fn resolved_snapshot_roundtrips_all_fields() { + let Some(root) = fixture() else { + return; + }; + let registry = super::super::load_registry(&root.0).unwrap(); + let original = super::super::load_uncached(®istry, &root.0).unwrap(); + let captured = Snapshot::capture(&original); + let restored = captured.restore(®istry).unwrap(); + assert_eq!( + serde_json::to_value(Snapshot::capture(&original)).unwrap(), + serde_json::to_value(Snapshot::capture(&restored)).unwrap(), + "all resolved fields, shape grids and identities should roundtrip", + ); + } + + #[test] + fn cache_invalidates_sources_and_recovers_from_corruption() { + let Some(root) = fixture() else { + return; + }; + let registry = super::super::load_registry(&root.0).unwrap(); + assert!(load(®istry, &root.0).is_none()); + let initial = super::super::load(®istry, &root.0).unwrap(); + assert!(root.0.join(FILE_NAME).is_file()); + let hit = load(®istry, &root.0).expect("cache hit"); + assert_eq!(initial.table.state_count(), hit.table.state_count()); + let tags = root.0.join("block-tags.json"); + fs::OpenOptions::new() + .append(true) + .open(&tags) + .unwrap() + .write_all(b"\n") + .unwrap(); + assert!( + load(®istry, &root.0).is_none(), + "changed resource must invalidate" + ); + super::super::load(®istry, &root.0).expect("source fallback"); + assert!( + load(®istry, &root.0).is_some(), + "fallback should replace cache" + ); + let cache_file = root.0.join(FILE_NAME); + let mut bytes = fs::read(&cache_file).unwrap(); + bytes[80] ^= 0x80; + fs::write(&cache_file, bytes).unwrap(); + assert!( + load(®istry, &root.0).is_none(), + "checksum failure must invalidate" + ); + super::super::load(®istry, &root.0).expect("corrupt cache fallback"); + assert!(load(®istry, &root.0).is_some()); + } +} diff --git a/tools/profile_client_startup.py b/tools/profile_client_startup.py new file mode 100644 index 000000000..76ad9002c --- /dev/null +++ b/tools/profile_client_startup.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +"""Measure the resource-dependent Behaviours::load portion of client startup. + +Build the behaviour_load_profile example in the checkout to be measured first: + cargo build --release -p horizon-world --example behaviour_load_profile + +Run the profiler from the repository root with the matching example binary. +This measures behaviour loading, not time to first rendered frame. +""" +import argparse +import json +import re +import statistics +import subprocess +from pathlib import Path + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--binary", type=Path, default=Path("target/release/examples/behaviour_load_profile")) + parser.add_argument("--resources", type=Path, default=Path(".local/horizon-client/26.3")) + parser.add_argument("--repeats", type=int, default=5) + parser.add_argument("--output", type=Path) + args = parser.parse_args() + if args.repeats < 1: + parser.error("--repeats must be at least one") + samples = [] + for _ in range(args.repeats): + run = subprocess.run([str(args.binary.resolve()), str(args.resources.resolve())], + text=True, capture_output=True, check=True) + values = {key: float(value) for key, value in + re.findall(r"^(registry_ms|behaviours_[0-2]_ms)=([\d.]+)$", run.stderr, re.M)} + if len(values) != 4: + raise RuntimeError(f"incomplete profile output: {run.stderr}") + samples.append(values) + summary = {key: {"median_ms": round(statistics.median(row[key] for row in samples), 3), + "samples_ms": [row[key] for row in samples]} + for key in samples[0]} + result = {"scope": "behaviour loader only; not full client startup", + "binary": str(args.binary), "resources": str(args.resources), "repeats": args.repeats, + "metrics": summary} + print(json.dumps(result, indent=2)) + if args.output: + args.output.parent.mkdir(parents=True, exist_ok=True) + args.output.write_text(json.dumps(result, indent=2) + "\n") + + +if __name__ == "__main__": + main() From 1d3759bb77dd7e9e6d08c689834001fbee4b3929 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 02:40:33 +0200 Subject: [PATCH 03/46] Drop a redundant binding flagged by clippy Co-Authored-By: Claude Opus 5.5 --- crates/horizon-world/src/level/data/cache.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/horizon-world/src/level/data/cache.rs b/crates/horizon-world/src/level/data/cache.rs index 3a18a7131..f143cf6cd 100644 --- a/crates/horizon-world/src/level/data/cache.rs +++ b/crates/horizon-world/src/level/data/cache.rs @@ -373,7 +373,6 @@ impl Snapshot { .iter() .map(|info| [info.full_faces, info.nonempty_faces, info.wall_cover]) .collect(); - let tags = tags; let f = behaviours.fluid_tags; let fluid_tags = [ f.water, From 943dd210d7369ba75456d4df7b76e6fd76f41126 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 02:59:37 +0200 Subject: [PATCH 04/46] Dedicated server: encode each chunk section once, not once per player Chunk packets took nearly all of the server's tick with players moving about: every send re-encoded the column for that player (each section unpacked and re-paletted with linear searches, light layers packed a nibble at a time, heightmaps primed again) and unpacked all 9 x 24 sections around it to find which light layers exist. At 50 walking bots that was ~85 % of the tick, 280-470 ms ticks against vanilla's 33 ms on the benchmark machine. The encoder now keeps what a resident section gives the wire (its bytes, whether it holds block entity blocks, whether it is all air) by the section's address. Sections are immutable behind Arc and edits go through Arc::make_mut, so an edited section moves to a new address, and the cache's Weak keeps an old address from being reused: the same address is the same unchanged section. Heightmaps are kept per column the same way. Block entity tags are still read for every packet. The bytes sent don't change. Also: Paletted::from_values uses an index table instead of linear palette searches (the same palette order and bits), the all-air check reads the palette first and stops at the first block, uniform sections skip unpacking, and light layers pack two blocks per byte in one pass. On a busy Mac mini with 50 walking bots (`tick query`): about 400 ms ticks with the faster palette and air checks alone, 14 ms with the caches. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/chunks.rs | 241 ++++++++++++++++++++---- crates/horizon-protocol/src/chunk.rs | 84 +++++++++ 2 files changed, 289 insertions(+), 36 deletions(-) diff --git a/crates/horizon-client/src/lan/chunks.rs b/crates/horizon-client/src/lan/chunks.rs index 6ca321edd..71e0c889b 100644 --- a/crates/horizon-client/src/lan/chunks.rs +++ b/crates/horizon-client/src/lan/chunks.rs @@ -90,7 +90,32 @@ pub struct ChunkEncoder { pub block_ids: Vec, /// The save's tables, for the heightmaps. pub tables: Option>, + /// Sections already looked at, by address (see `Encoded`). + cache: std::sync::Mutex>, + /// Each column's heightmaps, with the sections they were made from. + heights: std::sync::Mutex>, } + +/// A column's client heightmaps, valid while it holds the same sections. +struct Heights { + sections: Vec>, + maps: Vec<(i32, Vec)>, +} + +/// What a resident section gives the wire, kept while the section is +/// unchanged. Resident sections are immutable behind `Arc` (edits go through +/// `Arc::make_mut`, which moves an edited section to a new address while a +/// `Weak` points at the old one), and the `Weak` keeps the old address from +/// being reused: the same address is the same, unchanged section. +struct Encoded { + section: std::sync::Weak
, + non_air: bool, + /// LevelChunkSection.write, and whether it holds block entity blocks. + wire: Option<(Arc<[u8]>, bool)>, +} + +/// Sections kept before the ones no longer resident are dropped. +const CACHE_SWEEP: usize = 1 << 15; impl ChunkEncoder { /// `biome_names`: the internal biome list in order; `biome_registry`: /// the synchronized biome entries in network order. @@ -143,8 +168,89 @@ impl ChunkEncoder { biome_bits: ceil_log2(biome_registry.len()), block_ids, tables: None, + cache: Default::default(), + heights: Default::default(), } } + + /// The client heightmaps (Heightmap.prime over the column), from the + /// cache while the column's sections are unchanged. + fn heightmaps(&self, chunk: &Chunk, tables: &crate::save::SaveTables) -> Vec<(i32, Vec)> { + let same = |h: &Heights| { + h.sections.len() == chunk.sections.len() + && h.sections + .iter() + .zip(&chunk.sections) + .all(|(w, s)| std::ptr::eq(w.as_ptr(), Arc::as_ptr(s))) + }; + let mut heights = self.heights.lock().unwrap(); + if let Some(h) = heights.get(&(chunk.x, chunk.z)) + && same(h) + { + return h.maps.clone(); + } + if heights.len() >= CACHE_SWEEP / 4 { + heights.retain(|_, h| h.sections.iter().all(|w| w.strong_count() > 0)); + if heights.len() >= CACHE_SWEEP / 8 { + heights.clear(); + } + } + let maps = crate::save::client_heightmaps(chunk, tables); + heights.insert( + (chunk.x, chunk.z), + Heights { + sections: chunk.sections.iter().map(Arc::downgrade).collect(), + maps: maps.clone(), + }, + ); + maps + } + + /// The cached entry for a section, made with `non_air` when missing. + fn cached(&self, section: &Arc
, read: impl FnOnce(&mut Encoded) -> T) -> T { + let mut cache = self.cache.lock().unwrap(); + if cache.len() >= CACHE_SWEEP { + cache.retain(|_, e| e.section.strong_count() > 0); + if cache.len() >= CACHE_SWEEP / 2 { + cache.clear(); + } + } + let entry = cache + .entry(Arc::as_ptr(section) as usize) + .or_insert_with(|| Encoded { + section: Arc::downgrade(section), + non_air: self.non_air(section), + wire: None, + }); + read(entry) + } + + /// LevelChunkSection.hasOnlyAir, negated. + fn non_air(&self, section: &Section) -> bool { + let non_air = |v: u32| self.flags.get(v as usize).copied().unwrap_or(0) & NON_AIR != 0; + // The palette first: most sections are all air, or one block. + if !section.blocks.maybe_has(non_air) { + false + } else if let Some(v) = section.blocks.uniform() { + non_air(v) + } else { + // Stops at the first block, usually near the bottom. + (0..BLOCKS).any(|i| non_air(section.blocks.get(i))) + } + } + + /// A section on the wire, from the cache or encoded now. + fn section_wire(&self, section: &Arc
) -> (Arc<[u8]>, bool) { + if let Some(wire) = self.cached(section, |e| e.wire.clone()) { + return wire; + } + let (encoded, entities) = self.section(section); + let mut w = horizon_protocol::buf::Writer::new(); + encoded.write(&mut w); + let wire: (Arc<[u8]>, bool) = (w.data.into(), entities); + self.cached(section, |e| e.wire = Some(wire.clone())); + wire + } pub fn entity_type(&self, state: u16) -> Option { self.entity_types .get(usize::from(state)) @@ -170,11 +276,17 @@ impl ChunkEncoder { } f & ENTITY != 0 }; - let mut unpacked = [0u16; BLOCKS]; - section.unpack(&mut unpacked); - for &v in &unpacked { - entities |= count(v, 1); - values.push(i32::from(v)); + // One block everywhere (all air, mostly): what from_values would give. + let uniform = section.blocks.uniform(); + if let Some(v) = uniform { + entities = count(v as u16, BLOCKS as i16); + } else { + let mut unpacked = [0u16; BLOCKS]; + section.unpack(&mut unpacked); + for &v in &unpacked { + entities |= count(v, 1); + values.push(i32::from(v)); + } } let biome_values: Vec = (0..BIOMES) .map(|j| { @@ -189,7 +301,14 @@ impl ChunkEncoder { horizon_protocol::chunk::Section { non_empty, fluids, - states: Paletted::from_values(&values, Strategy::Blocks, 16), + states: match uniform { + Some(v) => Paletted { + bits: 0, + palette: vec![v as i32], + data: Vec::new(), + }, + None => Paletted::from_values(&values, Strategy::Blocks, 16), + }, biomes: Paletted::from_values(&biome_values, Strategy::Biomes, self.biome_bits), }, entities, @@ -201,12 +320,7 @@ impl ChunkEncoder { fn occupied(&self, chunk: &Chunk) -> u64 { let mut bits = 0u64; for (i, s) in chunk.sections.iter().enumerate() { - let mut unpacked = [0u16; BLOCKS]; - s.unpack(&mut unpacked); - let any = unpacked - .iter() - .any(|&v| self.flags.get(usize::from(v)).copied().unwrap_or(0) & NON_AIR != 0); - if any { + if self.cached(s, |e| e.non_air) { bits |= 1 << i; } } @@ -234,10 +348,10 @@ impl ChunkEncoder { chunk: &Chunk, block_entities: &HashMap<(i32, i32, i32), BlockEntity>, ) -> LevelChunkWithLight { - let mut sections = Vec::with_capacity(SECTIONS); + let mut buffer = Vec::new(); let mut entity_infos = Vec::new(); for (i, s) in chunk.sections.iter().enumerate() { - let (encoded, has_entities) = self.section(s); + let (encoded, has_entities) = self.section_wire(s); if has_entities { for y in 0..16 { for z in 0..16 { @@ -261,7 +375,7 @@ impl ChunkEncoder { } } } - sections.push(encoded); + buffer.extend_from_slice(&encoded); } // A loaded chunk's block entities enter its maps in the save's order // (ChunkAccess.pendingBlockEntities, then LevelChunk.blockEntities): @@ -293,9 +407,9 @@ impl ChunkEncoder { heightmaps: self .tables .as_ref() - .map(|t| crate::save::client_heightmaps(chunk, t)) + .map(|t| self.heightmaps(chunk, t)) .unwrap_or_default(), - buffer: ChunkData::from_sections(§ions), + buffer, block_entities: entity_infos, }, light: light_data(chunk, u64::MAX), @@ -398,31 +512,26 @@ fn light_data(chunk: &Chunk, around: u64) -> LightData { _ => &chunk.sections[b - 1].light, }; let (mut sky, mut block) = (vec![0u8; 2048], vec![0u8; 2048]); - let (mut sky_any, mut block_any) = (false, false); - match light { + let (sky_any, block_any) = match light { Light::Uniform(v) => { let (sk, bl) = (v >> 4, v & 15); - sky_any = sk != 0; - block_any = bl != 0; - let (sb, bb) = (sk | sk << 4, bl | bl << 4); - sky.fill(sb); - block.fill(bb); + sky.fill(sk | sk << 4); + block.fill(bl | bl << 4); + (sk != 0, bl != 0) } Light::Full(a) => { - for (j, &v) in a.iter().enumerate() { - let (sk, bl) = (v >> 4, v & 15); - sky_any |= sk != 0; - block_any |= bl != 0; - if j & 1 == 0 { - sky[j >> 1] |= sk; - block[j >> 1] |= bl; - } else { - sky[j >> 1] |= sk << 4; - block[j >> 1] |= bl << 4; - } + // Two blocks per byte, the even one in the low nibble. + for ((pair, sky), block) in + a.as_chunks::<2>().0.iter().zip(&mut sky).zip(&mut block) + { + let [even, odd] = *pair; + *sky = even >> 4 | (odd & 0xF0); + *block = (even & 15) | odd << 4; } + let all = a.iter().fold(0u8, |acc, &v| acc | v); + (all & 0xF0 != 0, all & 15 != 0) } - } + }; if sky_any { set_bit(&mut data.sky_mask, b); data.sky.push(sky); @@ -460,6 +569,66 @@ mod tests { assert_eq!(block_entity_type("minecraft:stone"), None); } + fn encoder() -> ChunkEncoder { + let states = ["minecraft:air", "minecraft:stone", "minecraft:water"] + .map(|n| (Arc::::from(n), n.ends_with("water"))); + ChunkEncoder::new(states, &Builtin::default(), &[], &[]) + } + + /// The bytes on the wire for a section, encoded afresh. + fn fresh(encoder: &ChunkEncoder, section: &Section) -> Vec { + let mut w = horizon_protocol::buf::Writer::new(); + encoder.section(section).0.write(&mut w); + w.data + } + + #[test] + fn cached_sections_follow_edits() { + let encoder = encoder(); + let mut chunk = Chunk::empty(0, 0); + chunk.set(1, MIN_Y + 2, 3, 1); + let before = encoder.encode(&chunk, &HashMap::new()); + assert_eq!(encoder.occupied(&chunk), 1); + assert_eq!( + &*encoder.section_wire(&chunk.sections[0]).0, + fresh(&encoder, &chunk.sections[0]) + ); + // An edit moves the section: the cache sees a new one. + chunk.set(4, MIN_Y + 20, 4, 2); + chunk.set(1, MIN_Y + 2, 3, 0); + assert_eq!(encoder.occupied(&chunk), 2); + let after = encoder.encode(&chunk, &HashMap::new()); + assert_ne!(before.chunk.buffer, after.chunk.buffer); + let mut expected = Vec::new(); + for s in &chunk.sections { + expected.extend(fresh(&encoder, s)); + } + assert_eq!(after.chunk.buffer, expected); + } + + #[test] + fn light_layers_pack_two_blocks_per_byte() { + let mut chunk = Chunk::empty(0, 0); + let mut light = Box::new([0u8; 4096]); + for (i, v) in light.iter_mut().enumerate() { + *v = (i * 37 % 251) as u8; + } + Arc::make_mut(&mut chunk.sections[3]).light = Light::Full(light.clone()); + let data = light_data(&chunk, u64::MAX); + // Layer 4 holds section 3. Below the world (layer 0) there is no sky + // light, so the sky layers listed start at layer 1; section 3 has the + // only block light. + let (sky, block) = (&data.sky[3], &data.block[0]); + for j in 0..4096 { + let (s, b) = if j & 1 == 0 { + (sky[j >> 1] & 15, block[j >> 1] & 15) + } else { + (sky[j >> 1] >> 4, block[j >> 1] >> 4) + }; + assert_eq!((s, b), (light[j] >> 4, light[j] & 15), "block {j}"); + } + } + #[test] fn light_masks_cover_the_world_plus_borders() { let chunk = Chunk::empty(0, 0); diff --git a/crates/horizon-protocol/src/chunk.rs b/crates/horizon-protocol/src/chunk.rs index 3343eacf5..32d7f98b6 100644 --- a/crates/horizon-protocol/src/chunk.rs +++ b/crates/horizon-protocol/src/chunk.rs @@ -114,6 +114,67 @@ impl Paletted { /// Pack values the way the server's container would have grown: /// the smallest configuration for the number of distinct values. pub fn from_values(values: &[i32], strategy: Strategy, global_bits: u8) -> Self { + // Palette indices by value, in first-seen order: a table over the + // value range (registry ids are small), kept per thread and cleared + // after use, with the previous value remembered, since neighbouring + // blocks repeat. + thread_local! { + static INDEX: std::cell::RefCell> = const { std::cell::RefCell::new(Vec::new()) }; + } + let max = values.iter().copied().max().unwrap_or(0); + if values.iter().any(|&v| v < 0) || max >= 1 << 20 { + return Self::from_values_slow(values, strategy, global_bits); + } + let mut palette: Vec = Vec::new(); + let mut ids = Vec::with_capacity(values.len()); + INDEX.with_borrow_mut(|index| { + if index.len() <= max as usize { + index.resize(max as usize + 1, u32::MAX); + } + let (mut last, mut last_id) = (-1i32, 0u32); + for &v in values { + if v != last { + let slot = &mut index[v as usize]; + if *slot == u32::MAX { + *slot = palette.len() as u32; + palette.push(v); + } + (last, last_id) = (v, *slot); + } + ids.push(last_id); + } + for &v in &palette { + index[v as usize] = u32::MAX; + } + }); + let needed = if palette.len() <= 1 { + 0 + } else { + (usize::BITS - (palette.len() - 1).leading_zeros()) as u8 + }; + let (has_palette, bits) = strategy.configuration(needed, global_bits); + if bits == 0 { + return Self { + bits: 0, + palette: vec![palette.first().copied().unwrap_or(0)], + data: Vec::new(), + }; + } + let mut data = vec![0i64; storage_len(bits, values.len())]; + let per = 64 / bits as usize; + for (i, (&v, &id)) in values.iter().zip(&ids).enumerate() { + let id = if has_palette { u64::from(id) } else { v as u64 }; + data[i / per] |= (id << ((i % per) * bits as usize)) as i64; + } + Self { + bits, + palette: if has_palette { palette } else { Vec::new() }, + data, + } + } + + /// `from_values` for any values: linear palette searches. + fn from_values_slow(values: &[i32], strategy: Strategy, global_bits: u8) -> Self { let mut palette: Vec = Vec::new(); for &v in values { if !palette.contains(&v) { @@ -290,6 +351,29 @@ pub fn nibble(layer: &[u8], i: usize) -> u8 { mod tests { use super::*; + #[test] + fn from_values_matches_the_linear_search() { + let mut seed = 12345u64; + let mut next = |n: u64| { + seed = seed + .wrapping_mul(6364136223846793005) + .wrapping_add(1442695040888963407); + ((seed >> 33) % n) as i32 + }; + for distinct in [1u64, 2, 16, 17, 200, 300, 5000] { + let values: Vec = (0..BLOCKS).map(|_| next(distinct) * 7).collect(); + assert_eq!( + Paletted::from_values(&values, Strategy::Blocks, 16), + Paletted::from_values_slow(&values, Strategy::Blocks, 16) + ); + let biomes: Vec = values[..BIOMES].to_vec(); + assert_eq!( + Paletted::from_values(&biomes, Strategy::Biomes, 7), + Paletted::from_values_slow(&biomes, Strategy::Biomes, 7) + ); + } + } + #[test] fn bit_storage_matches_simple_bit_storage() { // 5 bits: 12 values per long, the top 4 bits of each long unused. From 0789bf071926d6cf9ced552f916f1d4bc712f9c7 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:06:23 +0200 Subject: [PATCH 05/46] Keep the behaviours snapshot in the game folder, keyed to the build The resource folder is shared: worktrees and parity harnesses link one copy, and the launcher copies a prepared folder to each new compatible version. A snapshot there would be read by builds that resolve the tables differently while the VERSION constant stays the same. Keep it in the game's own .horizon-cache (set by the client; tools, tests and servers don't cache), add the running executable to its key, and skip hashing the resources when there is no snapshot. Postcard without default features drops heapless and the unmaintained atomic-polyfill from the lockfile. Co-Authored-By: Claude Opus 5.5 --- .gitignore | 1 + Cargo.lock | 54 ----------- crates/horizon-client/src/game.rs | 3 + crates/horizon-world/Cargo.toml | 2 +- crates/horizon-world/src/level/data.rs | 1 + crates/horizon-world/src/level/data/cache.rs | 94 ++++++++++++++++---- crates/horizon-world/src/level/mod.rs | 6 ++ 7 files changed, 88 insertions(+), 73 deletions(-) diff --git a/.gitignore b/.gitignore index eb29ad10d..7fffd6a99 100644 --- a/.gitignore +++ b/.gitignore @@ -28,5 +28,6 @@ /horizon-player.txt /servers.dat /screenshots/ +/.horizon-cache/ /crash-reports/ /debug/ diff --git a/Cargo.lock b/Cargo.lock index 9726316b6..ea6681a2c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -196,15 +196,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "atomic-polyfill" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" -dependencies = [ - "critical-section", -] - [[package]] name = "atomic-waker" version = "1.1.2" @@ -331,12 +322,6 @@ dependencies = [ "syn 3.0.6", ] -[[package]] -name = "byteorder" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" - [[package]] name = "bytes" version = "1.12.1" @@ -757,12 +742,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "critical-section" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" - [[package]] name = "crossbeam-utils" version = "0.8.23" @@ -1328,15 +1307,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "hash32" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" -dependencies = [ - "byteorder", -] - [[package]] name = "hashbrown" version = "0.15.5" @@ -1367,20 +1337,6 @@ dependencies = [ "foldhash 0.2.0", ] -[[package]] -name = "heapless" -version = "0.7.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" -dependencies = [ - "atomic-polyfill", - "hash32", - "rustc_version", - "serde", - "spin", - "stable_deref_trait", -] - [[package]] name = "heck" version = "0.5.0" @@ -2919,7 +2875,6 @@ dependencies = [ "cobs", "embedded-io 0.4.0", "embedded-io 0.6.1", - "heapless", "serde", ] @@ -3506,15 +3461,6 @@ dependencies = [ "sha2", ] -[[package]] -name = "spin" -version = "0.9.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3763264f6b73151db08c50ff20d7d8a0b8796e021cdea7ceedad07b80155fa0e" -dependencies = [ - "lock_api", -] - [[package]] name = "spirv" version = "0.4.0+sdk-1.4.341.0" diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index e552eb118..6dbaba66d 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -10144,6 +10144,9 @@ pub fn run() -> Result<()> { horizon_client::spans::enable(options.spikes.is_some()); let vanilla_root = options.resources.clone(); let early_settings = Settings::load(&std::env::current_dir()?.join("options.txt")); + // Snapshots of derived tables live in the game folder, never beside the + // shared resources. + Behaviours::set_cache_dir(std::env::current_dir()?.join(".horizon-cache")); options.resources = packs::startup_root(&vanilla_root, &early_settings.resource_packs); options.resources = mods::content_root( &options.resources, diff --git a/crates/horizon-world/Cargo.toml b/crates/horizon-world/Cargo.toml index 3e5f9466d..737edd289 100644 --- a/crates/horizon-world/Cargo.toml +++ b/crates/horizon-world/Cargo.toml @@ -11,7 +11,7 @@ libm = "=0.2.16" serde_json = { version = "1.0.151", features = ["raw_value"] } serde = { version = "1", features = ["derive"] } sha2 = "0.10" -postcard = { version = "=1.1.3", features = ["alloc"] } +postcard = { version = "=1.1.3", default-features = false, features = ["alloc"] } horizon-core = { path = "../horizon-core" } flate2 = { version = "1.1.10", default-features = false, features = ["rust_backend"] } lz4_flex = { version = "0.14", default-features = false, features = ["std", "safe-encode", "safe-decode", "checked-decode"] } diff --git a/crates/horizon-world/src/level/data.rs b/crates/horizon-world/src/level/data.rs index 83349232c..ef47294a8 100644 --- a/crates/horizon-world/src/level/data.rs +++ b/crates/horizon-world/src/level/data.rs @@ -23,6 +23,7 @@ use std::{ }; #[path = "data/cache.rs"] mod cache; +pub(super) use cache::set_dir as set_cache_dir; /// Per-state flags read from vanilla accessors over an empty level. pub mod state_flags { diff --git a/crates/horizon-world/src/level/data/cache.rs b/crates/horizon-world/src/level/data/cache.rs index f143cf6cd..59bc1f8d8 100644 --- a/crates/horizon-world/src/level/data/cache.rs +++ b/crates/horizon-world/src/level/data/cache.rs @@ -2,21 +2,36 @@ //! //! The source resources remain authoritative. Failed reads, unsupported //! versions, corrupt payloads and write failures always use the normal loader. +//! The snapshot lives in the game's own cache folder ([`set_dir`]), never in the +//! resource folder: that one is shared by worktrees and copied between installed +//! versions by the launcher. Its key includes the running executable, so a build +//! that resolves the tables differently never reads another build's snapshot. use super::*; use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; use std::{ io::Write, path::PathBuf, - sync::atomic::{AtomicU64, Ordering}, + sync::{ + OnceLock, + atomic::{AtomicU64, Ordering}, + }, + time::UNIX_EPOCH, }; const MAGIC: &[u8; 8] = b"HZBEHAV\0"; const VERSION: u32 = 2; -const FILE_NAME: &str = ".horizon-behaviours-v2.bin"; +const FILE_NAME: &str = "behaviours-v2.bin"; const MAX_FILE_BYTES: usize = 128 * 1024 * 1024; const MAX_DECODED_BYTES: usize = 256 * 1024 * 1024; static NEXT_TEMP: AtomicU64 = AtomicU64::new(0); +static DIR: OnceLock = OnceLock::new(); + +/// Keep snapshots in `dir` (the client passes `/.horizon-cache`). +/// Without it (tests, tools, servers), `Behaviours::load` always uses the source loader. +pub(in crate::level) fn set_dir(dir: PathBuf) { + let _ = DIR.set(dir); +} #[derive(Serialize, Deserialize)] struct Snapshot { @@ -123,6 +138,17 @@ struct Item { fn fingerprint(registry: &BlockRegistry, root: &Path) -> io::Result<[u8; 32]> { let mut hasher = Sha256::new(); hasher.update(b"horizon resolved behaviours 2"); + // The build that resolved the tables: the version constant alone misses + // loader changes that keep the snapshot layout. + let exe = std::env::current_exe()?; + let built = fs::metadata(&exe)?; + hash_str(&mut hasher, &exe.to_string_lossy()); + hasher.update(built.len().to_le_bytes()); + let modified = built + .modified()? + .duration_since(UNIX_EPOCH) + .map_err(|e| invalid(e.to_string()))?; + hasher.update(modified.as_nanos().to_le_bytes()); for relative in [ "facts.json", "block-behaviours.json", @@ -635,8 +661,12 @@ impl Snapshot { } pub(super) fn load(registry: &BlockRegistry, root: &Path) -> Option { + load_from(DIR.get()?, registry, root) +} + +fn load_from(dir: &Path, registry: &BlockRegistry, root: &Path) -> Option { + let bytes = fs::read(dir.join(FILE_NAME)).ok()?; let fingerprint = fingerprint(registry, root).ok()?; - let bytes = fs::read(root.join(FILE_NAME)).ok()?; // Validate bounds before decoding untrusted cache contents. if bytes.len() < 8 + 4 + 32 + 32 || bytes.len() > MAX_FILE_BYTES { return None; @@ -661,10 +691,17 @@ pub(super) fn load(registry: &BlockRegistry, root: &Path) -> Option } pub(super) fn store(registry: &BlockRegistry, root: &Path, behaviours: &Behaviours) { - let _ = write(registry, root, behaviours); + if let Some(dir) = DIR.get() { + let _ = write(dir, registry, root, behaviours); + } } -fn write(registry: &BlockRegistry, root: &Path, behaviours: &Behaviours) -> io::Result<()> { +fn write( + dir: &Path, + registry: &BlockRegistry, + root: &Path, + behaviours: &Behaviours, +) -> io::Result<()> { let fingerprint = fingerprint(registry, root)?; let snapshot = Snapshot::capture(behaviours); let serialized = postcard::to_allocvec(&snapshot).map_err(|e| invalid(e.to_string()))?; @@ -678,8 +715,9 @@ fn write(registry: &BlockRegistry, root: &Path, behaviours: &Behaviours) -> io:: bytes.extend_from_slice(&fingerprint); bytes.extend_from_slice(&Sha256::digest(&body)); bytes.extend_from_slice(&body); - let path = root.join(FILE_NAME); - let tmp = root.join(format!( + fs::create_dir_all(dir)?; + let path = dir.join(FILE_NAME); + let tmp = dir.join(format!( "{FILE_NAME}.tmp-{}-{}", std::process::id(), NEXT_TEMP.fetch_add(1, Ordering::Relaxed) @@ -773,11 +811,25 @@ mod tests { let Some(root) = fixture() else { return; }; + // The game's cache folder, apart from the resources. + let dir = root.0.join("game/.horizon-cache"); let registry = super::super::load_registry(&root.0).unwrap(); - assert!(load(®istry, &root.0).is_none()); - let initial = super::super::load(®istry, &root.0).unwrap(); - assert!(root.0.join(FILE_NAME).is_file()); - let hit = load(®istry, &root.0).expect("cache hit"); + // What `data::load` does once `set_dir` gave it a folder. + let load_or_build = || { + load_from(&dir, ®istry, &root.0).unwrap_or_else(|| { + let built = super::super::load_uncached(®istry, &root.0).unwrap(); + write(&dir, ®istry, &root.0, &built).unwrap(); + built + }) + }; + assert!(load_from(&dir, ®istry, &root.0).is_none()); + let initial = load_or_build(); + assert!(dir.join(FILE_NAME).is_file()); + assert!( + !root.0.join(FILE_NAME).exists(), + "the resource folder stays untouched" + ); + let hit = load_from(&dir, ®istry, &root.0).expect("cache hit"); assert_eq!(initial.table.state_count(), hit.table.state_count()); let tags = root.0.join("block-tags.json"); fs::OpenOptions::new() @@ -787,23 +839,29 @@ mod tests { .write_all(b"\n") .unwrap(); assert!( - load(®istry, &root.0).is_none(), + load_from(&dir, ®istry, &root.0).is_none(), "changed resource must invalidate" ); - super::super::load(®istry, &root.0).expect("source fallback"); + load_or_build(); assert!( - load(®istry, &root.0).is_some(), + load_from(&dir, ®istry, &root.0).is_some(), "fallback should replace cache" ); - let cache_file = root.0.join(FILE_NAME); + let cache_file = dir.join(FILE_NAME); let mut bytes = fs::read(&cache_file).unwrap(); bytes[80] ^= 0x80; fs::write(&cache_file, bytes).unwrap(); assert!( - load(®istry, &root.0).is_none(), + load_from(&dir, ®istry, &root.0).is_none(), "checksum failure must invalidate" ); - super::super::load(®istry, &root.0).expect("corrupt cache fallback"); - assert!(load(®istry, &root.0).is_some()); + load_or_build(); + assert!(load_from(&dir, ®istry, &root.0).is_some()); + // A snapshot written under another key (another build of the game, + // other resources) is never trusted. + let mut other = fs::read(&cache_file).unwrap(); + other[12] ^= 1; + fs::write(&cache_file, other).unwrap(); + assert!(load_from(&dir, ®istry, &root.0).is_none()); } } diff --git a/crates/horizon-world/src/level/mod.rs b/crates/horizon-world/src/level/mod.rs index 00dd115db..cc561993a 100644 --- a/crates/horizon-world/src/level/mod.rs +++ b/crates/horizon-world/src/level/mod.rs @@ -456,6 +456,12 @@ impl Behaviours { pub fn load(registry: &BlockRegistry, resources_dir: &Path) -> io::Result { data::load(registry, resources_dir) } + /// Keep a snapshot of the resolved tables in `dir` (a game folder's + /// `.horizon-cache`), so later launches of the same build restore it instead + /// of resolving the resources again. Without it, [`Self::load`] never caches. + pub fn set_cache_dir(dir: std::path::PathBuf) { + data::set_cache_dir(dir); + } pub fn facts(&self, state: BlockStateId) -> &StateFacts { &self.facts[state.0 as usize] } From 2e98f6a18a8977f5a5c567f731370dbb4b2d197c Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:25:02 +0200 Subject: [PATCH 06/46] Let the behaviour profiler use a snapshot folder Co-Authored-By: Claude Opus 5.5 --- crates/horizon-world/examples/behaviour_load_profile.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/horizon-world/examples/behaviour_load_profile.rs b/crates/horizon-world/examples/behaviour_load_profile.rs index e6619afa1..d9d7a1147 100644 --- a/crates/horizon-world/examples/behaviour_load_profile.rs +++ b/crates/horizon-world/examples/behaviour_load_profile.rs @@ -1,4 +1,6 @@ //! Measure registry and behaviour load times using prepared client resources. +//! `behaviour_load_profile RESOURCES [CACHE_DIR]`: with CACHE_DIR, loads use and +//! refresh the snapshot there, as the client does with its `.horizon-cache`. use horizon_world::level::{Behaviours, data::load_registry}; use std::{path::Path, time::Instant}; @@ -7,6 +9,9 @@ fn main() -> Result<(), Box> { .nth(1) .expect("resource directory argument"); let root = Path::new(&root); + if let Some(dir) = std::env::args().nth(2) { + Behaviours::set_cache_dir(dir.into()); + } let started = Instant::now(); let registry = load_registry(root)?; eprintln!( From 02dce1093be2cbb0dcfc3f8bfd3267030facf176 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:58:28 +0200 Subject: [PATCH 07/46] Give the behaviour profiler its own name Every PR of the startup batch adds a different tools/profile_client_startup.py, so any two of them conflict. This one measures only Behaviours::load, so it becomes tools/profile_behaviour_cache.py, and --cache-dir passes the snapshot folder to the example so warm loads can be measured. Co-Authored-By: Claude Opus 5.5 --- ...lient_startup.py => profile_behaviour_cache.py} | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) rename tools/{profile_client_startup.py => profile_behaviour_cache.py} (74%) diff --git a/tools/profile_client_startup.py b/tools/profile_behaviour_cache.py similarity index 74% rename from tools/profile_client_startup.py rename to tools/profile_behaviour_cache.py index 76ad9002c..00ba65a6d 100644 --- a/tools/profile_client_startup.py +++ b/tools/profile_behaviour_cache.py @@ -5,7 +5,10 @@ Build the behaviour_load_profile example in the checkout to be measured first: cargo build --release -p horizon-world --example behaviour_load_profile Run the profiler from the repository root with the matching example binary. -This measures behaviour loading, not time to first rendered frame. +This measures behaviour loading, not time to first rendered frame. With +--cache-dir, the example reads and refreshes the resolved snapshot there, as the +client does with its .horizon-cache folder: the first load of a run builds it +when it is missing, the next loads restore it. """ import argparse import json @@ -19,6 +22,8 @@ def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--binary", type=Path, default=Path("target/release/examples/behaviour_load_profile")) parser.add_argument("--resources", type=Path, default=Path(".local/horizon-client/26.3")) + parser.add_argument("--cache-dir", type=Path, + help="snapshot folder (default: no snapshot, every load is uncached)") parser.add_argument("--repeats", type=int, default=5) parser.add_argument("--output", type=Path) args = parser.parse_args() @@ -26,8 +31,10 @@ def main(): parser.error("--repeats must be at least one") samples = [] for _ in range(args.repeats): - run = subprocess.run([str(args.binary.resolve()), str(args.resources.resolve())], - text=True, capture_output=True, check=True) + command = [str(args.binary.resolve()), str(args.resources.resolve())] + if args.cache_dir: + command.append(str(args.cache_dir.resolve())) + run = subprocess.run(command, text=True, capture_output=True, check=True) values = {key: float(value) for key, value in re.findall(r"^(registry_ms|behaviours_[0-2]_ms)=([\d.]+)$", run.stderr, re.M)} if len(values) != 4: @@ -38,6 +45,7 @@ def main(): for key in samples[0]} result = {"scope": "behaviour loader only; not full client startup", "binary": str(args.binary), "resources": str(args.resources), "repeats": args.repeats, + "cache_dir": str(args.cache_dir) if args.cache_dir else None, "metrics": summary} print(json.dumps(result, indent=2)) if args.output: From b347ceb19511017831a268667c2a320794502333 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:45:46 +0200 Subject: [PATCH 08/46] Dedicated server: vanilla's chunk pacing and movement checks PlayerChunkSender: one unacknowledged batch until the client's first acknowledgement and ten after it, batches capped at the client's desired chunks per tick (not twice that), and the quota reset to one chunk whenever every batch is acknowledged. ServerGamePacketListenerImpl.handleMovePlayer: a move further from where the tick began (firstGood) than 100 blocks squared per move packet (300 while gliding; the count falls back to 1 past 5 packets) logs " moved too quickly!" and pulls the player back, as the player_movement_check and elytra_movement_check game rules allow. NaN coordinates or non-finite angles and two position moves in one client tick disconnect with invalid_player_movement, positions are clamped to the world's limits, an unanswered teleport is sent again after 20 ticks, and accepting a teleport runs the move it carries. The move is then replayed against the blocks: a survival or adventure player who ends more than 0.25 blocks short of the target (horizontally; vanilla drops the vertical part) logs " moved wrongly!" and is sent back unless they were already stuck, and any move into a block the old box did not touch (isEntityCollidingWithAnythingNew) is sent back silently. Spectators and sleepers skip both. Angles wrap as Mth.wrapDegrees does. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/examples/lan_flat.rs | 3 +- crates/horizon-client/src/game/lan.rs | 10 + crates/horizon-client/src/lan/guest.rs | 26 +- crates/horizon-client/src/lan/hub.rs | 299 ++++++++++++++++++--- crates/horizon-client/tests/lan_bot.rs | 1 + 5 files changed, 297 insertions(+), 42 deletions(-) diff --git a/crates/horizon-client/examples/lan_flat.rs b/crates/horizon-client/examples/lan_flat.rs index 16fc36b95..d1a492edf 100644 --- a/crates/horizon-client/examples/lan_flat.rs +++ b/crates/horizon-client/examples/lan_flat.rs @@ -121,6 +121,7 @@ fn main() -> Result<(), Box> { clock_rate: 1.0, tick_rate: 20.0, tick_frozen: false, + collision: None, }; for event in hub.tick(&mut ctx) { match event { @@ -132,7 +133,7 @@ fn main() -> Result<(), Box> { eprintln!("[lan] {packet:?}"); } } - HostEvent::Chat(line) => println!("{line}"), + HostEvent::Chat(line) | HostEvent::Warn(line) => println!("{line}"), HostEvent::Left(_) => {} } } diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index 1d00134e4..ad30dd813 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -710,7 +710,12 @@ impl Game<'_> { }, tick_rate: self.clock.rate(), tick_frozen: self.clock.frozen(), + collision: Some(self.collision), }; + host.hub.movement_checks = ( + self.ui.rules.bool("player_movement_check"), + self.ui.rules.bool("elytra_movement_check"), + ); host.hub.tick(&mut ctx) }; if let Some(state) = &state @@ -772,6 +777,10 @@ impl Game<'_> { super::dedicated::log("INFO", &format!("[Not Secure] {line}")); } HostEvent::Chat(line) => self.system_message(Text::literal(line)), + HostEvent::Warn(line) if self.options.dedicated.is_some() => { + super::dedicated::log("WARN", &line); + } + HostEvent::Warn(line) => log::warn!("{line}"), HostEvent::Packet(conn, packet) => { self.lan_guest_packet(&mut host, conn, *packet); } @@ -831,6 +840,7 @@ impl Game<'_> { clock_rate: self.ui.clock.rate, tick_rate: self.clock.rate(), tick_frozen: self.clock.frozen(), + collision: Some(self.collision), }; host.hub.place_new_player(conn, &mut ctx); } diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs index 243c90d18..28b833d3c 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -71,15 +71,31 @@ pub struct Guest { /// the client accepts it (ServerGamePacketListenerImpl.awaitingPositionFromClient). pub awaiting_teleport: Option<(i32, [f64; 3])>, pub teleport_counter: i32, + /// The hub tick the pending teleport was (re)sent on (awaitingTeleportTime). + pub teleport_tick: u64, + /// Where the player was when this tick's packets began (firstGoodX/Y/Z), + /// for the moved-too-quickly check. + pub first_good: [f64; 3], + /// Position moves received in all and by the start of this tick + /// (receivedMovePacketCount, knownMovePacketCount). + pub received_moves: i32, + pub known_moves: i32, + /// A position move arrived since the client's last ClientTickEnd + /// (receivedPositionThisTick): a second one is a protocol error. + pub position_this_tick: bool, /// The client finished loading terrain (ServerboundPlayerLoadedPacket). pub loaded: bool, // Chunks. pub center: Option<(i32, i32)>, pub sent_chunks: HashSet<(i32, i32)>, pub chunk_queue: Vec<(i32, i32)>, + /// PlayerChunkSender: batches sent but not yet acknowledged, how many + /// may be (1 until the client's first acknowledgement, then 10), the + /// rate the client asks for and the chunks the next batch may hold. pub unacknowledged: u32, + pub max_unacknowledged: u32, pub chunks_per_tick: f32, - pub chunk_credit: f32, + pub batch_quota: f32, // Entities. pub tracker: Tracker, // Player state the gameplay code reads and writes. @@ -167,13 +183,19 @@ impl Guest { sleeping: false, awaiting_teleport: None, teleport_counter: 0, + teleport_tick: 0, + first_good: position, + received_moves: 0, + known_moves: 0, + position_this_tick: false, loaded: false, center: None, sent_chunks: HashSet::new(), chunk_queue: Vec::new(), unacknowledged: 0, + max_unacknowledged: 1, chunks_per_tick: 9.0, - chunk_credit: 0.0, + batch_quota: 0.0, tracker: Tracker::default(), motion: None, inventory: vec![None; 36], diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index cb438508e..b0e30c664 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -12,17 +12,24 @@ use super::{ guest::{Guest, SentEffect, stack_to_network}, }; use crate::{ + collisions::SceneCollisions, effects::{EffectInstance, PlayerEffects}, items::ItemStack, world::World, }; +use horizon_core::geometry::{Aabb, ShapeOp, Vec3, VoxelShape}; use horizon_protocol::ids::play::clientbound as ids; use horizon_protocol::{ entity_data::{Value, serializer}, packets::play::{self, Clientbound as C, Serverbound as S}, text::{literal, translatable}, }; -use horizon_world::nbt::{JavaString, Tag}; +use horizon_world::{ + block_collision::BlockCollisionRegistry, + block_collision_scan::BlockCollisionScan, + collision_context::CollisionContext, + nbt::{JavaString, Tag}, +}; use std::sync::{Arc, atomic::Ordering}; /// GameEvent types (ClientboundGameEventPacket). @@ -88,6 +95,9 @@ pub struct TickCtx<'a> { /// TickRateManager: the tick rate and whether the game is frozen. pub tick_rate: f32, pub tick_frozen: bool, + /// Block collisions, for ServerGamePacketListenerImpl's moved-wrongly + /// check (none: moves are not checked against blocks). + pub collision: Option<&'a BlockCollisionRegistry<'a>>, } /// What the gameplay code has to do for a guest. @@ -99,6 +109,8 @@ pub enum HostEvent { Packet(u32, Box), /// A chat line to show on the host (already broadcast to the guests). Chat(String), + /// A server log warning (ServerGamePacketListenerImpl's LOGGER.warn). + Warn(String), } pub struct Hub { @@ -108,6 +120,9 @@ pub struct Hub { pub guests: Vec, pub(super) sync: Arc, pub ticks: u64, + /// The `player_movement_check` and `elytra_movement_check` game rules, + /// set by the game before each tick. + pub movement_checks: (bool, bool), last_clock: i64, last_rate: f32, ticking: (f32, bool), @@ -196,6 +211,7 @@ impl Hub { guests: Vec::new(), sync, ticks: 0, + movement_checks: (true, true), last_clock: i64::MIN, last_rate: 0.0, ticking: (20.0, false), @@ -713,7 +729,9 @@ impl Hub { /// ServerGamePacketListenerImpl.teleport: move the client and wait for its confirmation. pub fn teleport(&mut self, i: usize, position: Option<[f64; 3]>) { + let ticks = self.ticks; let g = &mut self.guests[i]; + g.teleport_tick = ticks; if let Some(p) = position { g.position = p; g.previous_position = p; @@ -1051,15 +1069,16 @@ impl Hub { g.chunk_queue .sort_by_key(|&(x, z)| i64::from(x - cx).pow(2) + i64::from(z - cz).pow(2)); } - // Send ready chunks, closest first, in batches. - if g.chunk_queue.is_empty() || g.unacknowledged >= 10 || self.ticks <= g.placed_at + 1 { + // PlayerChunkSender.sendNextChunks: ready chunks, closest first, in + // batches the client's acknowledgements pace. + if self.ticks <= g.placed_at + 1 || g.unacknowledged >= g.max_unacknowledged { return; } - g.chunk_credit = (g.chunk_credit + g.chunks_per_tick).min(g.chunks_per_tick.max(1.0) * 2.0); - let budget = g.chunk_credit.floor() as usize; - if budget == 0 { + g.batch_quota = (g.batch_quota + g.chunks_per_tick).min(g.chunks_per_tick.max(1.0)); + if g.batch_quota < 1.0 || g.chunk_queue.is_empty() { return; } + let budget = g.batch_quota.floor() as usize; let mut packets = Vec::new(); let mut taken = Vec::new(); for (idx, key) in g.chunk_queue.iter().enumerate() { @@ -1080,7 +1099,7 @@ impl Hub { if packets.is_empty() { return; } - g.chunk_credit -= packets.len() as f32; + g.batch_quota -= packets.len() as f32; g.send(&C::ChunkBatchStart(horizon_protocol::packets::Empty)); for p in &packets { g.send(p); @@ -1462,6 +1481,11 @@ impl Hub { } fn process_inbox(&mut self, i: usize, ctx: &mut TickCtx, events: &mut Vec) { + // ServerGamePacketListenerImpl.tickPlayer ran between the last + // tick's packets and these: resetPosition, and the moves it counted. + let g = &mut self.guests[i]; + g.first_good = g.position; + g.known_moves = g.received_moves; let mut budget = 400; while budget > 0 { let Some(packet) = self.guests[i].inbox.pop_front() else { @@ -1490,23 +1514,42 @@ impl Hub { self.guests[i].last_action_tick = self.ticks; } match packet { + // handleAcceptTeleportPacket. S::AcceptTeleportation(p) => { let g = &mut self.guests[i]; - if g.awaiting_teleport.is_some_and(|(id, _)| id == p.id) { + if let Some((id, at)) = g.awaiting_teleport + && id == p.id + { + if p.x.is_nan() + || p.y.is_nan() + || p.z.is_nan() + || !p.yaw.is_finite() + || !p.pitch.is_finite() + { + self.kick(conn, invalid_movement()); + continue; + } + g.position = at; g.awaiting_teleport = None; + let rot = (p.yaw, p.pitch); + self.position_change(i, [p.x, p.y, p.z], rot, 0, ctx, events); } } S::MovePlayerPos(p) => { - self.move_player(i, Some([p.x, p.y, p.z]), None, p.flags); + self.move_player(i, Some([p.x, p.y, p.z]), None, p.flags, ctx, events); } S::MovePlayerPosRot(p) => { - self.move_player(i, Some([p.x, p.y, p.z]), Some((p.yaw, p.pitch)), p.flags); + let (pos, rot) = ([p.x, p.y, p.z], (p.yaw, p.pitch)); + self.move_player(i, Some(pos), Some(rot), p.flags, ctx, events); } S::MovePlayerRot(p) => { - self.move_player(i, None, Some((p.yaw, p.pitch)), p.flags); + self.move_player(i, None, Some((p.yaw, p.pitch)), p.flags, ctx, events); + } + S::MovePlayerStatus(p) => { + self.move_player(i, None, None, p.flags, ctx, events); } - S::MovePlayerStatus(p) => self.move_player(i, None, None, p.flags), S::PlayerLoaded(_) => self.guests[i].loaded = true, + // PlayerChunkSender.onChunkBatchReceivedByClient. S::ChunkBatchReceived(p) => { let g = &mut self.guests[i]; g.unacknowledged = g.unacknowledged.saturating_sub(1); @@ -1515,7 +1558,12 @@ impl Hub { } else { p.chunks_per_tick.clamp(0.01, 64.0) }; + if g.unacknowledged == 0 { + g.batch_quota = 1.0; + } + g.max_unacknowledged = 10; } + S::ClientTickEnd(_) => self.guests[i].position_this_tick = false, S::ClientInformation(info) => { let g = &mut self.guests[i]; g.view_distance = @@ -1534,7 +1582,6 @@ impl Hub { 0 => self.guests[i].sleeping = false, _ => {} }, - S::ClientTickEnd(_) => {} S::Chat(c) => { let text: String = c.message.chars().filter(|c| !c.is_control()).collect(); if !text.is_empty() { @@ -1546,48 +1593,205 @@ impl Hub { other => events.push(HostEvent::Packet(conn, Box::new(other))), } } - let _ = ctx; } /// ServerGamePacketListenerImpl.handleMovePlayer. - fn move_player(&mut self, i: usize, pos: Option<[f64; 3]>, rot: Option<(f32, f32)>, flags: u8) { - let g = &mut self.guests[i]; - if g.awaiting_teleport.is_some() || !g.loaded && g.ticks == 0 && pos.is_none() { + fn move_player( + &mut self, + i: usize, + pos: Option<[f64; 3]>, + rot: Option<(f32, f32)>, + flags: u8, + ctx: &TickCtx, + events: &mut Vec, + ) { + let conn = self.guests[i].conn; + // containsInvalidValues, on the packet's values (0 where it has none). + let (yaw, pitch) = rot.unwrap_or_default(); + if pos.is_some_and(|p| p.iter().any(|v| v.is_nan())) + || !yaw.is_finite() + || !pitch.is_finite() + { + self.kick(conn, invalid_movement()); return; } - if let Some(p) = pos { - if p.iter().any(|v| !v.is_finite() || v.abs() > 3.0e7) { + let g = &mut self.guests[i]; + if pos.is_some() { + if g.position_this_tick { + self.kick(conn, invalid_movement()); return; } - // A jump of more than a hundred blocks is a rejected move. - let d2: f64 = (0..3).map(|k| (p[k] - g.position[k]).powi(2)).sum(); - if d2 > 100.0 * 100.0 { - let at = g.position; - self.teleport(i, Some(at)); - return; - } - g.previous_position = g.position; - g.position = p; + g.position_this_tick = true; } - let moved = pos.map_or([0.0; 3], |_| { - [0, 1, 2].map(|k| g.position[k] - g.previous_position[k]) - }); + if !g.loaded && g.ticks == 0 && pos.is_none() { + return; + } + // updateAwaitingTeleport: moves wait for the client to accept the + // teleport, which is sent again after 20 ticks without an answer. + if let Some((_, at)) = g.awaiting_teleport { + if self.ticks - g.teleport_tick > 20 { + self.teleport(i, Some(at)); + } + return; + } + let to = pos.unwrap_or(g.position); + let rot = rot.unwrap_or((g.yaw, g.pitch)); + self.position_change(i, to, rot, flags, ctx, events); + } + + /// ServerGamePacketListenerImpl.handlePlayerPositionChange. + fn position_change( + &mut self, + i: usize, + to: [f64; 3], + (yaw, pitch): (f32, f32), + flags: u8, + ctx: &TickCtx, + events: &mut Vec, + ) { + let (frozen, (check, elytra_check)) = (self.ticking.1, self.movement_checks); + let g = &mut self.guests[i]; + let to = [ + to[0].clamp(-3.0E7, 3.0E7), + to[1].clamp(-2.0E7, 2.0E7), + to[2].clamp(-3.0E7, 3.0E7), + ]; + let (yaw, pitch) = (wrap_degrees(yaw), wrap_degrees(pitch)); + let d = [0, 1, 2].map(|k| to[k] - g.first_good[k]); + let moved = d[0] * d[0] + d[1] * d[1] + d[2] * d[2]; + if g.sleeping { + if moved > 1.0 { + (g.yaw, g.pitch) = (yaw, pitch); + self.teleport(i, None); + } + return; + } + // TickRateManager.runsNormally: not frozen (a frozen game's steps + // are not counted either; Horizon's hub does not see them). + if !frozen { + g.received_moves += 1; + let mut packets = g.received_moves - g.known_moves; + if packets > 5 { + packets = 1; + } + // shouldCheckPlayerMovement. The server holds no velocity for a + // guest (getDeltaMovement), so nothing is expected. + if check && (!g.fall_flying || elytra_check) { + let limit = if g.fall_flying { 300.0 } else { 100.0 }; + if moved > limit * f64::from(packets) { + events.push(HostEvent::Warn(format!( + "{} moved too quickly! {},{},{}", + g.name, + crate::java_text::double_to_string(d[0]), + crate::java_text::double_to_string(d[1]), + crate::java_text::double_to_string(d[2]) + ))); + self.teleport(i, None); + return; + } + } + } + let start = g.position; + let (wrongly, refused) = self.collide(i, to, ctx); + if wrongly { + let line = format!("{} moved wrongly!", self.guests[i].name); + events.push(HostEvent::Warn(line)); + } + if refused { + let g = &mut self.guests[i]; + (g.yaw, g.pitch) = (yaw, pitch); + self.teleport(i, Some(start)); + return; + } + let g = &mut self.guests[i]; + g.previous_position = g.position; + g.position = to; + let moved = [0, 1, 2].map(|k| g.position[k] - g.previous_position[k]); if g.moves.is_empty() { g.moves_from_ground = g.on_ground; } g.moves.push((moved, flags & 1 != 0)); - if let Some((yaw, pitch)) = rot - && yaw.is_finite() - && pitch.is_finite() - { - g.yaw = yaw % 360.0; - g.pitch = pitch.clamp(-90.0, 90.0); - g.head_yaw = g.yaw; - } + g.yaw = yaw; + g.pitch = pitch.clamp(-90.0, 90.0); + g.head_yaw = g.yaw; g.on_ground = flags & 1 != 0; g.ticks = g.ticks.max(1); } + /// The collision part of handlePlayerPositionChange: whether the move + /// counts as moved wrongly (logged), and whether it is refused (the + /// player is sent back where they were). + fn collide(&self, i: usize, to: [f64; 3], ctx: &TickCtx) -> (bool, bool) { + let g = &self.guests[i]; + // noPhysics (spectators) and sleepers move freely. + let Some(binding) = ctx.collision else { + return (false, false); + }; + if g.spectator() || g.sleeping { + return (false, false); + } + let height = if g.fall_flying { + 0.6 + } else if g.sneaking { + 1.5 + } else { + 1.8 + }; + let at = |p: [f64; 3]| { + Aabb::new( + Vec3::new(p[0] - 0.3, p[1], p[2] - 0.3), + Vec3::new(p[0] + 0.3, p[1] + height, p[2] + 0.3), + ) + }; + let (old, new) = (at(g.position), at(to)); + let mut scene = SceneCollisions { + world: ctx.world, + binding, + subject: None, + }; + // player.move, then how far from the target it ended (vanilla drops + // the vertical part: `yDist > -0.5 || yDist < 0.5` always holds). + let movement = Vec3::new( + to[0] - g.position[0], + to[1] - g.position[1], + to[2] - g.position[2], + ); + let fail = !g.creative() + && scene + .resolve(old, movement, 0.6, g.on_ground) + .is_ok_and(|done| { + let (dx, dz) = (movement.x - done.x, movement.z - done.z); + dx * dx + dz * dz > 0.0625 + }); + if fail && scene.unobstructed(old).unwrap_or(true) { + return (true, true); + } + // isEntityCollidingWithAnythingNew: a block the old box did not + // already touch. + let shrink = f64::from(1.0E-5_f32); + let shrink = Vec3::new(shrink, shrink, shrink); + let Ok(old_shape) = VoxelShape::from_box(old.deflate(shrink)) else { + return (fail, false); + }; + let context = CollisionContext::position(g.position[1]); + let Ok(scan) = + BlockCollisionScan::new(&mut scene, context, new.deflate(shrink), false, 1 << 20) + else { + return (fail, false); + }; + for hit in scan { + let Ok(hit) = hit else { break }; + if !hit + .shape + .join_is_not_empty(&old_shape, ShapeOp::AND) + .unwrap_or(true) + { + return (fail, true); + } + } + (fail, false) + } + /// Acknowledge a block interaction (ClientboundBlockChangedAckPacket). pub fn ack(&self, conn: u32, sequence: i32) { if sequence >= 0 @@ -1684,6 +1888,23 @@ impl Hub { } /// A packet Horizon sends as raw bytes (no fields worth a type). +/// multiplayer.disconnect.invalid_player_movement. +/// Mth.wrapDegrees. +fn wrap_degrees(degrees: f32) -> f32 { + let mut wrapped = degrees % 360.0; + if wrapped >= 180.0 { + wrapped -= 360.0; + } + if wrapped < -180.0 { + wrapped += 360.0; + } + wrapped +} + +fn invalid_movement() -> Tag { + translatable("multiplayer.disconnect.invalid_player_movement", &[]) +} + fn raw(id: i32, payload: Vec) -> C { C::Unknown(id, payload) } diff --git a/crates/horizon-client/tests/lan_bot.rs b/crates/horizon-client/tests/lan_bot.rs index 36f53444c..6b1d6bd5b 100644 --- a/crates/horizon-client/tests/lan_bot.rs +++ b/crates/horizon-client/tests/lan_bot.rs @@ -193,6 +193,7 @@ impl Server { clock_rate: 1.0, tick_rate: 20.0, tick_frozen: false, + collision: None, }; let events = self.hub.tick(&mut ctx); for event in events { From c8003301bcab7ada444666edb09949fe9975eb99 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:45:46 +0200 Subject: [PATCH 09/46] horizon-bots: vanilla's chunk batch sizing, chunk-gated movement and chunk accounting The bots acknowledge chunk batches with ChunkBatchSizeCalculator's desired chunks per tick, from how long each batch takes to arrive, instead of a fixed 25. A bot moves only while it holds the chunk it stands in, as vanilla's client stops ticking its player in a chunk it hasn't received, so no bot outruns a server's chunk sending. Each bot keeps the chunks it holds, so the report separates chunks that entered its view from chunks sent again while it still held them, and counts the moves the server refused and the ticks it waited for its chunk. server_bench.py runs one pass per behaviour (walk, explore), spawns every bot on the world spawn itself (respawn_radius 0) so both servers see the same paths, can run the bots on another machine (--bots-via, --bots-bin, --connect) and the servers under nice, and reports new, dropped and re-sent chunks per second, pull-backs and the server's "moved too quickly" lines. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-bots/src/main.rs | 117 +++++++++++++++++++++++++++++--- tools/server_bench.py | 104 +++++++++++++++++++++------- 2 files changed, 188 insertions(+), 33 deletions(-) diff --git a/crates/horizon-bots/src/main.rs b/crates/horizon-bots/src/main.rs index d76da5e84..3eb15beec 100644 --- a/crates/horizon-bots/src/main.rs +++ b/crates/horizon-bots/src/main.rs @@ -9,6 +9,11 @@ //! horizon-bots --server 127.0.0.1:25565 --bots 25 --behaviour mixed --seconds 360 --report bots.json //! //! It prints one JSON line a second (bots online, chunks received) and writes a summary with `--report`. +//! A bot moves only while it holds the chunk it stands in: vanilla's client stops ticking its player in a chunk +//! it hasn't received, so a player can't outrun the server's chunk sending, on any server. +//! Each bot also keeps the chunks it holds, as a client's chunk cache does, so the report tells chunks that +//! entered the view apart from chunks sent again while the bot still held them (`resent`), and counts the +//! times the server pulled a bot back (`pulled_back`: a teleport after the first, as for "moved too quickly"). use horizon_protocol::{ PROTOCOL_VERSION, @@ -25,6 +30,7 @@ use horizon_protocol::{ }; use serde_json::json; use std::{ + collections::HashSet, sync::{ Arc, Mutex, atomic::{AtomicBool, AtomicU64, Ordering}, @@ -44,7 +50,7 @@ horizon-bots: load-test bots for a Minecraft Java Edition 26.3 server (offline m --view-distance N what the bots ask for; default 10 --seed N default 12345 --name PREFIX bot names: PREFIX0, PREFIX1...; default Bot - --report FILE a JSON summary at the end + --report FILE a JSON summary at the end (- prints it after the per-second lines) "; #[derive(Clone, Copy, Debug, PartialEq)] @@ -129,6 +135,17 @@ fn options() -> Result { struct Bot { online: AtomicBool, chunks: AtomicU64, + /// Chunks received while the bot already held them (no ForgetLevelChunk in between). + resent: AtomicU64, + /// Different chunks received over the run. + unique: AtomicU64, + forgotten: AtomicU64, + /// Teleports after the spawn one: the server refused a move. + pulled_back: AtomicU64, + /// Ticks the bot couldn't move because it didn't hold its chunk yet. + waited: AtomicU64, + /// The chunks the bot holds (ClientChunkCache). + held: Mutex>, /// Where the server last put the bot (a teleport), to start from. teleport: Mutex>, error: Mutex>, @@ -268,6 +285,36 @@ fn join(o: &Options, name: &str) -> Result { } } +/// ChunkBatchSizeCalculator: the chunks per tick a vanilla client asks for, from how long its batches take +/// to arrive. +struct BatchSize { + nanos_per_chunk: f64, + old_samples_weight: u32, + started: Instant, +} + +impl BatchSize { + fn new() -> Self { + Self { + nanos_per_chunk: 2_000_000.0, + old_samples_weight: 1, + started: Instant::now(), + } + } + fn finished(&mut self, size: i32) { + if size > 0 { + let per_chunk = self.started.elapsed().as_nanos() as f64 / f64::from(size); + let clamped = per_chunk.clamp(self.nanos_per_chunk / 3.0, self.nanos_per_chunk * 3.0); + let weight = f64::from(self.old_samples_weight); + self.nanos_per_chunk = (self.nanos_per_chunk * weight + clamped) / (weight + 1.0); + self.old_samples_weight = (self.old_samples_weight + 1).min(49); + } + } + fn desired_chunks_per_tick(&self) -> f32 { + (7_000_000.0 / self.nanos_per_chunk) as f32 + } +} + /// Reads the play state: answers what a client must answer, counts chunks, records teleports. fn read( mut reader: horizon_protocol::connection::ConnReader, @@ -277,6 +324,9 @@ fn read( use ids::play::clientbound as cb; use ids::play::serverbound as sb; let send = |body: Vec| writer.lock().unwrap().send(&body); + let mut seen = HashSet::new(); + let mut batch = BatchSize::new(); + let mut teleports = 0u64; loop { let (id, body) = match reader.recv() { Ok(packet) => packet, @@ -299,14 +349,38 @@ fn read( }, cb::LEVEL_CHUNK_WITH_LIGHT => { bot.chunks.fetch_add(1, Ordering::Relaxed); + if let (Ok(x), Ok(z)) = (r.i32(), r.i32()) { + if !bot.held.lock().unwrap().insert((x, z)) { + bot.resent.fetch_add(1, Ordering::Relaxed); + } + if seen.insert((x, z)) { + bot.unique.fetch_add(1, Ordering::Relaxed); + } + } Ok(()) } - cb::CHUNK_BATCH_FINISHED => send( - play::Serverbound::ChunkBatchReceived(play::ChunkBatchReceived { - chunks_per_tick: 25.0, - }) - .encode(), - ), + cb::FORGET_LEVEL_CHUNK => { + if let Ok(play::Clientbound::ForgetLevelChunk(p)) = + play::Clientbound::decode(id, &body) + && bot.held.lock().unwrap().remove(&(p.pos[0], p.pos[1])) + { + bot.forgotten.fetch_add(1, Ordering::Relaxed); + } + Ok(()) + } + cb::CHUNK_BATCH_START => { + batch.started = Instant::now(); + Ok(()) + } + cb::CHUNK_BATCH_FINISHED => { + batch.finished(r.varint().unwrap_or(0)); + send( + play::Serverbound::ChunkBatchReceived(play::ChunkBatchReceived { + chunks_per_tick: batch.desired_chunks_per_tick(), + }) + .encode(), + ) + } cb::PLAYER_POSITION => match play::Clientbound::decode(id, &body) { Ok(play::Clientbound::PlayerPosition(p)) => { let mut at = bot.teleport.lock().unwrap(); @@ -320,6 +394,10 @@ fn read( } }); *at = Some(pos); + teleports += 1; + if teleports > 1 { + bot.pulled_back.fetch_add(1, Ordering::Relaxed); + } send( play::Serverbound::AcceptTeleportation(play::AcceptTeleportation { id: p.teleport, @@ -416,7 +494,10 @@ fn run_bot( if let Some(at) = bot.teleport.lock().unwrap().take() { pos = at; } - if pos[1] < cruise { + let here = ((pos[0].floor() as i32) >> 4, (pos[2].floor() as i32) >> 4); + if !bot.held.lock().unwrap().contains(&here) { + bot.waited.fetch_add(1, Ordering::Relaxed); + } else if pos[1] < cruise { pos[1] = (pos[1] + 0.5).min(cruise); } else { match behaviour { @@ -520,6 +601,9 @@ fn main() { .filter(|b| b.online.load(Ordering::SeqCst)) .count(); let chunks: u64 = bots.iter().map(|b| b.chunks.load(Ordering::Relaxed)).sum(); + let total = |f: fn(&Bot) -> &AtomicU64| -> u64 { + bots.iter().map(|b| f(b).load(Ordering::Relaxed)).sum() + }; let failed = bots .iter() .filter(|b| b.error.lock().unwrap().is_some()) @@ -536,6 +620,11 @@ fn main() { "failed": failed, "chunks": chunks, "chunks_per_second": chunks - previous_chunks, + "unique": total(|b| &b.unique), + "forgotten": total(|b| &b.forgotten), + "resent": total(|b| &b.resent), + "pulled_back": total(|b| &b.pulled_back), + "waited_ticks": total(|b| &b.waited), }) ); previous_chunks = chunks; @@ -558,15 +647,25 @@ fn main() { "seconds": o.seconds, "joined": bots.iter().filter(|b| b.joined_after_ms.load(Ordering::SeqCst) > 0).count(), "chunks": bots.iter().map(|b| b.chunks.load(Ordering::Relaxed)).sum::(), + "resent": bots.iter().map(|b| b.resent.load(Ordering::Relaxed)).sum::(), + "pulled_back": bots.iter().map(|b| b.pulled_back.load(Ordering::Relaxed)).sum::(), + "waited_ticks": bots.iter().map(|b| b.waited.load(Ordering::Relaxed)).sum::(), "per_bot": bots.iter().enumerate().map(|(i, b)| json!({ "name": format!("{}{i}", o.name), "behaviour": behaviour_of(&o.behaviour, i).name(), "joined_after_ms": b.joined_after_ms.load(Ordering::SeqCst), "chunks": b.chunks.load(Ordering::Relaxed), + "unique_chunks": b.unique.load(Ordering::Relaxed), + "resent": b.resent.load(Ordering::Relaxed), + "forgotten": b.forgotten.load(Ordering::Relaxed), + "pulled_back": b.pulled_back.load(Ordering::Relaxed), + "waited_ticks": b.waited.load(Ordering::Relaxed), "error": *b.error.lock().unwrap(), })).collect::>(), }); - if let Some(path) = &o.report { + if o.report.as_deref() == Some("-") { + println!("{summary:#}"); + } else if let Some(path) = &o.report { if let Err(e) = std::fs::write(path, format!("{summary:#}\n")) { eprintln!("horizon-bots: {path}: {e}"); } diff --git a/tools/server_bench.py b/tools/server_bench.py index 5a64c80cf..91f11a7ad 100755 --- a/tools/server_bench.py +++ b/tools/server_bench.py @@ -8,10 +8,16 @@ then measures for a while: - MSPT (average, P50, P95, P99) from each server's own `/tick query`, asked every 5 seconds on the console: vanilla's ServerTickRateManager numbers, which Horizon reproduces, so both measure themselves the same way; - RSS and CPU of the server's whole process tree, once a second; -- chunks the bots receive per second (new terrain while the `explore` bots fly outwards); +- chunks the bots receive per second (new terrain while the `explore` bots fly outwards), chunks sent again + while a bot still held them, and the moves the server refused (pull-backs; "moved too quickly" and + "moved wrongly" lines); - the start time to `Done`, and every bot that failed to join or was dropped. - python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25 --seconds 120 + python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25 --behaviour walk,explore + +The bots can run on another machine, so they don't take the server's CPU: `--bots-via 'ssh macmini'` with +`--bots-bin` naming horizon-bots there and `--connect` the address it reaches this machine at. `--nice 19` +runs every server at the lowest priority (a shared machine). The vanilla side runs the pinned server jar from tools/lab.py prepare (your own copy). It needs Java 25. The Horizon side runs target/release/horizon-server with the engine beside it; build both first: @@ -186,8 +192,16 @@ def server_command(kind, directory, args): return [server, '--dir', directory, 'run'] -def run_once(kind, bots, args, out): - directory = out / f'{kind}-{bots}' +def bots_command(args): + """horizon-bots here, or through `--bots-via` (for example `ssh macmini`) on another machine.""" + if args.bots_via: + return [*args.bots_via.split(), args.bots_bin or 'horizon-bots'] + return [args.bots_bin or BIN / f'horizon-bots{EXE}'] + + +def run_once(kind, bots, behaviour, args, out): + name = f'{kind}-{behaviour}-{bots}' + directory = out / name shutil.rmtree(directory, ignore_errors=True) directory.mkdir(parents=True) port = free_port() @@ -195,19 +209,24 @@ def run_once(kind, bots, args, out): (directory / 'server.properties').write_text(''.join(f'{k}={v}\n' for k, v in props.items())) (directory / 'eula.txt').write_text('eula=true\n') command = server_command(kind, directory, args) + if args.nice: + command = ['nice', '-n', str(args.nice), *command] started = time.time() - server = Server(command, directory, out / f'{kind}-{bots}.log') - result = {'server': kind, 'bots': bots} + server = Server(command, directory, out / f'{name}.log') + result = {'server': kind, 'bots': bots, 'behaviour': behaviour} try: server.wait_for(r'/INFO\]: Done \(', 600) result['start_seconds'] = round(time.time() - started, 2) + # Every bot appears on the world spawn itself, not spread around it, so both servers see the same paths. + server.console('gamerule respawn_radius 0') time.sleep(5) - report = out / f'{kind}-{bots}-bots.json' + report = out / f'{name}-bots.json' total = bots * args.join_every + args.warmup + args.seconds + # The summary comes back on stdout after the per-second lines, so it works over ssh too. bot_process = subprocess.Popen( - [BIN / f'horizon-bots{EXE}', '--server', f'127.0.0.1:{port}', '--bots', str(bots), - '--behaviour', args.behaviour, '--join-every', str(args.join_every), '--seconds', str(int(total)), - '--seed', str(args.seed), '--report', report], + [*bots_command(args), '--server', f'{args.connect}:{port}', '--bots', str(bots), + '--behaviour', behaviour, '--join-every', str(args.join_every), '--seconds', str(int(total)), + '--seed', str(args.seed), '--report', '-'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) bot_lines = [] threading.Thread(target=lambda: bot_lines.extend(bot_process.stdout), daemon=True).start() @@ -229,11 +248,27 @@ def run_once(kind, bots, args, out): if (t := tick_query(server)) is not None: ticks.append(t) next_query = now + 5 - measured = [json.loads(l) for l in list(bot_lines) if l.startswith('{')] - window = [l for l in measured if l['t'] >= measured[-1]['t'] - args.seconds] if measured else [] bot_process.wait(timeout=total + 120) - summary = json.loads(report.read_text()) if report.exists() else {} + time.sleep(0.5) + measured, rest = [], [] + for line in list(bot_lines): + try: + sample = json.loads(line) + except ValueError: + sample = None + if isinstance(sample, dict) and 't' in sample: + measured.append(sample) + else: + rest.append(line) + window = [l for l in measured if l['t'] >= measured[-1]['t'] - args.seconds] if measured else [] + summary_text = ''.join(rest) + summary = json.loads(summary_text) if summary_text.strip() else {} + report.write_text(json.dumps(summary, indent=2) + '\n') mean = lambda xs: round(statistics.fmean(xs), 2) if xs else None + per_bot = summary.get('per_bot', []) + by_behaviour = {} + for b in per_bot: + by_behaviour.setdefault(b['behaviour'], []).append(b) result.update({ 'mspt': {k: mean([t[k] for t in ticks]) for k in ('average', 'p50', 'p95', 'p99')}, 'mspt_worst_p99': max((t['p99'] for t in ticks), default=None), @@ -242,6 +277,19 @@ def run_once(kind, bots, args, out): 'rss_mb': {'mean': mean([r / 1e6 for r in rss]), 'max': round(max(rss) / 1e6, 1) if rss else None}, 'cpu_percent': mean(cpu), 'chunks_per_second': mean([l['chunks_per_second'] for l in window]), + # Over the measured window: different chunks reaching the bots, chunks they had dropped and got + # again (walking back), and ticks the bots stood still waiting for their own chunk. + **({k + '_per_second': round((window[-1][k] - window[0][k]) / max(len(window) - 1, 1), 2) + for k in ('unique', 'forgotten', 'waited_ticks')} if len(window) > 1 else {}), + 'chunks_total': summary.get('chunks'), + # Per bot over the whole run: every chunk received, the different ones, and those sent again + # while the bot still held them. + 'chunks_per_bot': {k: mean([b['chunks'] for b in v]) for k, v in by_behaviour.items()}, + 'unique_chunks_per_bot': {k: mean([b['unique_chunks'] for b in v]) for k, v in by_behaviour.items()}, + 'resent': summary.get('resent'), + 'pulled_back': summary.get('pulled_back'), + 'moved_too_quickly': sum('moved too quickly!' in l for l in server.since(0)), + 'moved_wrongly': sum('moved wrongly!' in l for l in server.since(0)), 'bots_joined': summary.get('joined'), 'bots_failed': [b for b in summary.get('per_bot', []) if b.get('error')], 'tick_queries': len(ticks), @@ -257,23 +305,28 @@ def main(): parser = argparse.ArgumentParser(description=__doc__.split('\n\n')[0]) parser.add_argument('--servers', default='horizon,vanilla') parser.add_argument('--bots', default='1,10,25,50') - parser.add_argument('--behaviour', default='mixed') + parser.add_argument('--behaviour', default='walk,explore', help='one pass per behaviour (comma-separated)') parser.add_argument('--join-every', type=float, default=1.0) parser.add_argument('--warmup', type=int, default=60) parser.add_argument('--seconds', type=int, default=300) parser.add_argument('--seed', type=int, default=12345) parser.add_argument('--heap', default='4g', help='the Java heap, -Xms and -Xmx (vanilla)') parser.add_argument('--out', type=Path, default=None, help='the report (JSON)') + parser.add_argument('--nice', type=int, default=0, help='run the servers under nice -n N') + parser.add_argument('--bots-via', default='', help="a command prefix to run the bots elsewhere ('ssh host')") + parser.add_argument('--bots-bin', default='', help='horizon-bots (on the --bots-via machine)') + parser.add_argument('--connect', default='127.0.0.1', help='the address the bots reach the server at') args = parser.parse_args() out = lab.LOCAL / 'server-bench' out.mkdir(parents=True, exist_ok=True) runs = [] - for bots in [int(b) for b in args.bots.split(',')]: - for kind in args.servers.split(','): - print(f'{kind}, {bots} bots...', flush=True) - result = run_once(kind, bots, args, out) - runs.append(result) - print(json.dumps(result), flush=True) + for behaviour in args.behaviour.split(','): + for bots in [int(b) for b in args.bots.split(',')]: + for kind in args.servers.split(','): + print(f'{kind}, {bots} {behaviour} bots...', flush=True) + result = run_once(kind, bots, behaviour, args, out) + runs.append(result) + print(json.dumps(result), flush=True) report = { 'kind': 'horizon-server-benchmark', 'date': datetime.datetime.now(datetime.timezone.utc).isoformat(timespec='seconds'), @@ -286,13 +339,16 @@ def main(): path = args.out or out / 'report.json' path.parent.mkdir(parents=True, exist_ok=True) path.write_text(json.dumps(report, indent=2) + '\n') - print(f'\n{"server":8} {"bots":>4} {"start s":>8} {"MSPT":>6} {"P95":>6} {"P99":>6} {"RSS MB":>7} {"CPU %":>6} {"chunks/s":>8} {"joined":>6}') + print(f'\n{"server":8} {"pass":8} {"bots":>4} {"start s":>8} {"MSPT":>6} {"P95":>6} {"P99":>6} {"RSS MB":>7} ' + f'{"CPU %":>6} {"chunks/s":>8} {"/bot":>6} {"resent":>6} {"pulled":>6} {"joined":>6}') for r in runs: if 'error' in r: - print(f'{r["server"]:8} {r["bots"]:>4} failed: {r["error"].splitlines()[0]}') + print(f'{r["server"]:8} {r["behaviour"]:8} {r["bots"]:>4} failed: {r["error"].splitlines()[0]}') continue - print(f'{r["server"]:8} {r["bots"]:>4} {r["start_seconds"]:>8} {r["mspt"]["average"]!s:>6} {r["mspt"]["p95"]!s:>6} ' - f'{r["mspt"]["p99"]!s:>6} {r["rss_mb"]["mean"]!s:>7} {r["cpu_percent"]!s:>6} {r["chunks_per_second"]!s:>8} ' + per_bot = r['chunks_per_bot'].get(r['behaviour']) + print(f'{r["server"]:8} {r["behaviour"]:8} {r["bots"]:>4} {r["start_seconds"]:>8} {r["mspt"]["average"]!s:>6} ' + f'{r["mspt"]["p95"]!s:>6} {r["mspt"]["p99"]!s:>6} {r["rss_mb"]["mean"]!s:>7} {r["cpu_percent"]!s:>6} ' + f'{r["chunks_per_second"]!s:>8} {per_bot!s:>6} {r["resent"]!s:>6} {r["pulled_back"]!s:>6} ' f'{r["bots_joined"]!s:>6}') print(f'\nWrote {path}') From 3cd26c6d0b249ca442dd3e2e7fc38cbcd70cf862 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:24:30 +0200 Subject: [PATCH 10/46] server_bench: --gamerule, more game rules for both servers Horizon has no locator bar yet, so equal-work runs turn vanilla's off (--gamerule locator_bar=false): its waypoint updates cost every move a pass over every other player. Co-Authored-By: Claude Opus 5.5 --- tools/server_bench.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/server_bench.py b/tools/server_bench.py index 91f11a7ad..e50a49e64 100755 --- a/tools/server_bench.py +++ b/tools/server_bench.py @@ -219,6 +219,8 @@ def run_once(kind, bots, behaviour, args, out): result['start_seconds'] = round(time.time() - started, 2) # Every bot appears on the world spawn itself, not spread around it, so both servers see the same paths. server.console('gamerule respawn_radius 0') + for rule in filter(None, args.gamerule.split(',')): + server.console('gamerule ' + rule.replace('=', ' ')) time.sleep(5) report = out / f'{name}-bots.json' total = bots * args.join_every + args.warmup + args.seconds @@ -310,6 +312,9 @@ def main(): parser.add_argument('--warmup', type=int, default=60) parser.add_argument('--seconds', type=int, default=300) parser.add_argument('--seed', type=int, default=12345) + parser.add_argument('--gamerule', default='', + help="more game rules for both servers, 'name=value,...' (locator_bar=false: Horizon has " + "no locator bar yet)") parser.add_argument('--heap', default='4g', help='the Java heap, -Xms and -Xmx (vanilla)') parser.add_argument('--out', type=Path, default=None, help='the report (JSON)') parser.add_argument('--nice', type=int, default=0, help='run the servers under nice -n N') From 75ee9a3299cb76a80325f0481690ef48eec93ccd Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 05:35:24 +0200 Subject: [PATCH 11/46] Build a saved chunk's structure starts when it loads, not on the game thread A loaded world had none of its structure starts in the generator's cache. The first time natural spawning (or anything else) asked which structures hold a position in a chunk referencing a village, the game thread built the village start: 60 to 120 ms in one tick, once right after the world opened and again a few ticks later for the next start (#489). Vanilla reads the starts with the chunk. The streaming worker that loads a saved chunk now builds the starts it references into the same cache, so the game thread finds them there. The starts are the same: the same function builds them from the same seed and chunk, only earlier and on a worker. The cache now keeps the first starts built for a chunk when two threads build them at once, so every user shares one start and its pieces' placement state, as vanilla's single StructureStart does. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/save.rs | 3 +++ crates/horizon-client/src/streaming.rs | 8 +++++++- crates/horizon-client/src/vanillagen.rs | 13 +++++++++++++ .../src/worldgen/generator_structures.rs | 5 +++-- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index a8553e276..79e0ec396 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -2784,6 +2784,9 @@ impl ChunkGenerator for Persistent { chunk.entities = self.save.load_entities(x, z); Some(chunk) } + fn prepare_loaded(&self, worker: &mut G::Worker, chunk: &Chunk) { + self.inner.prepare_loaded(worker, chunk); + } fn proto(&self, worker: &mut G::Worker, x: i32, z: i32) -> crate::streaming::Proto { let mut proto = self.inner.proto(worker, x, z); if let Some(saved) = self diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 994316324..1754f1550 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -36,6 +36,9 @@ pub trait ChunkGenerator: Send + Sync + 'static { fn load(&self, _x: i32, _z: i32) -> Option { None } + /// What a loaded chunk needs from the generator before the game uses it, + /// on the worker that loaded it. + fn prepare_loaded(&self, _worker: &mut Self::Worker, _chunk: &Chunk) {} fn proto(&self, worker: &mut Self::Worker, x: i32, z: i32) -> Proto; fn decorates(&self) -> bool { false @@ -369,7 +372,10 @@ impl Streaming { }; let done = match job { Job::Generate(x, z) => match generator.load(x, z) { - Some(chunk) => Done::Generated(chunk), + Some(chunk) => { + generator.prepare_loaded(&mut worker, &chunk); + Done::Generated(chunk) + } None => { let proto = generator.proto(&mut worker, x, z); let decorated = generator.is_decorated(&proto); diff --git a/crates/horizon-client/src/vanillagen.rs b/crates/horizon-client/src/vanillagen.rs index fc18e8404..6f0c4edaf 100644 --- a/crates/horizon-client/src/vanillagen.rs +++ b/crates/horizon-client/src/vanillagen.rs @@ -265,6 +265,19 @@ impl ChunkGenerator for VanillaTerrain { fn worker(&self) -> GeneratorWorker { self.generator.worker() } + /// The structure starts a saved chunk references, as vanilla reads them + /// with the chunk: built here, on the loading worker, into the + /// generator's cache, rather than on the game thread the first time + /// spawning or a mob asks which structures hold a position (a village + /// start took 70 to 110 ms there, one tick each, after a world loaded). + fn prepare_loaded(&self, worker: &mut GeneratorWorker, chunk: &Chunk) { + let mut starts: Vec<(i32, i32)> = chunk.structure_refs.iter().map(|(_, at)| *at).collect(); + starts.sort_unstable(); + starts.dedup(); + for (x, z) in starts { + worker.structure_starts(ChunkPos::new(x, z)); + } + } fn proto(&self, worker: &mut GeneratorWorker, x: i32, z: i32) -> Proto { match worker.generate_proto(ChunkPos::new(x, z)) { Ok(chunk) => Box::new(VanillaProto::Ready(Box::new(chunk))), diff --git a/crates/horizon-world/src/worldgen/generator_structures.rs b/crates/horizon-world/src/worldgen/generator_structures.rs index f5487dc33..e78ce0772 100644 --- a/crates/horizon-world/src/worldgen/generator_structures.rs +++ b/crates/horizon-world/src/worldgen/generator_structures.rs @@ -229,8 +229,9 @@ impl StructureState { if cache.len() >= START_CACHE_LIMIT { cache.clear(); } - cache.insert((chunk.x, chunk.z), starts.clone()); - starts + // Another thread may have built the same starts meanwhile: everyone + // keeps the first, so placement state on its pieces is shared. + cache.entry((chunk.x, chunk.z)).or_insert(starts).clone() } /// ChunkGenerator.findNearestMapStructure: the nearest start of one of /// `names` from block `from` (rings: every ring chunk; random spreads: From c5851e77aa6bab2850e3f4692980e1b5ac3d564c Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 05:42:27 +0200 Subject: [PATCH 12/46] horizon-bots: --explore-speed, for an explore pass with equal work Co-Authored-By: Claude Opus 5.5 --- crates/horizon-bots/src/main.rs | 15 ++++++++++++--- tools/server_bench.py | 10 ++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/horizon-bots/src/main.rs b/crates/horizon-bots/src/main.rs index 3eb15beec..090daeb4e 100644 --- a/crates/horizon-bots/src/main.rs +++ b/crates/horizon-bots/src/main.rs @@ -49,6 +49,7 @@ horizon-bots: load-test bots for a Minecraft Java Edition 26.3 server (offline m --seconds N how long to run after the first bot joins; default 60 --view-distance N what the bots ask for; default 10 --seed N default 12345 + --explore-speed B blocks a second an explore bot flies; default 22 (as fast as chunks come) --name PREFIX bot names: PREFIX0, PREFIX1...; default Bot --report FILE a JSON summary at the end (- prints it after the per-second lines) "; @@ -79,6 +80,7 @@ struct Options { seconds: u64, view_distance: i8, seed: u64, + explore_speed: f64, name: String, report: Option, } @@ -93,6 +95,7 @@ fn options() -> Result { seconds: 60, view_distance: 10, seed: 12345, + explore_speed: 22.0, name: "Bot".into(), report: None, }; @@ -116,6 +119,9 @@ fn options() -> Result { "--seconds" => o.seconds = value.parse().map_err(|_| number("seconds"))?, "--view-distance" => o.view_distance = value.parse().map_err(|_| number("2 to 32"))?, "--seed" => o.seed = value.parse().map_err(|_| number("a number"))?, + "--explore-speed" => { + o.explore_speed = value.parse().map_err(|_| number("blocks a second"))?; + } "--name" => o.name = value, "--report" => o.report = Some(value), _ => return Err(format!("unknown option {arg}; --help lists them")), @@ -521,9 +527,11 @@ fn run_bot( } } Behaviour::Explore => { - // Flying fast in creative: about 22 blocks a second, which keeps new chunks coming. - pos[0] += heading.cos() * 1.1; - pos[2] += heading.sin() * 1.1; + // Flying in creative, by default about 22 blocks a second, which keeps new + // chunks coming as fast as the server sends them. + let step = o.explore_speed / 20.0; + pos[0] += heading.cos() * step; + pos[2] += heading.sin() * step; } } } @@ -643,6 +651,7 @@ fn main() { "bots": o.bots, "behaviour": o.behaviour, "seed": o.seed, + "explore_speed": o.explore_speed, "view_distance": o.view_distance, "seconds": o.seconds, "joined": bots.iter().filter(|b| b.joined_after_ms.load(Ordering::SeqCst) > 0).count(), diff --git a/tools/server_bench.py b/tools/server_bench.py index e50a49e64..c79d6aab1 100755 --- a/tools/server_bench.py +++ b/tools/server_bench.py @@ -17,7 +17,9 @@ then measures for a while: The bots can run on another machine, so they don't take the server's CPU: `--bots-via 'ssh macmini'` with `--bots-bin` naming horizon-bots there and `--connect` the address it reaches this machine at. `--nice 19` -runs every server at the lowest priority (a shared machine). +runs every server at the lowest priority (a shared machine). The explore bots fly as fast as each server +sends them chunks, so a faster server gets more terrain to generate; `--explore-speed` slows them to a rate +both servers keep up with, for equal work. The vanilla side runs the pinned server jar from tools/lab.py prepare (your own copy). It needs Java 25. The Horizon side runs target/release/horizon-server with the engine beside it; build both first: @@ -228,7 +230,8 @@ def run_once(kind, bots, behaviour, args, out): bot_process = subprocess.Popen( [*bots_command(args), '--server', f'{args.connect}:{port}', '--bots', str(bots), '--behaviour', behaviour, '--join-every', str(args.join_every), '--seconds', str(int(total)), - '--seed', str(args.seed), '--report', '-'], + '--seed', str(args.seed), '--report', '-', + *(['--explore-speed', str(args.explore_speed)] if args.explore_speed else [])], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) bot_lines = [] threading.Thread(target=lambda: bot_lines.extend(bot_process.stdout), daemon=True).start() @@ -312,6 +315,9 @@ def main(): parser.add_argument('--warmup', type=int, default=60) parser.add_argument('--seconds', type=int, default=300) parser.add_argument('--seed', type=int, default=12345) + parser.add_argument('--explore-speed', type=float, default=0, + help='blocks a second the explore bots fly (default: the bots\' 22, as fast as chunks ' + 'come); a speed both servers keep up with makes the explore pass equal work') parser.add_argument('--gamerule', default='', help="more game rules for both servers, 'name=value,...' (locator_bar=false: Horizon has " "no locator bar yet)") From 1efc7f83d180f43838b8295c24ec5a28a83778b8 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 05:55:41 +0200 Subject: [PATCH 13/46] Entity portal checks: skip the sweep where no section holds a portal Every tick, each item and mob that can use a portal sweeps the blocks its box passed through since the last tick, looking for a nether portal block (`Entity.checkInsideBlocks` reaching `NetherPortalBlock.entityInside`). Each sweep allocated a visited set and read every block of the path. Every block a sweep visits lies in the box covering the entity's box at both ends. When no section that box touches has a nether portal state in its palette, no visited block is a portal: the sweep is skipped. Sections are checked once per tick, and a box over more than 64 sections (an entity teleported far) is swept as before. Co-Authored-By: Claude Opus 5.5 --- .../horizon-client/src/game/nether_portal.rs | 67 ++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/game/nether_portal.rs b/crates/horizon-client/src/game/nether_portal.rs index 01a657b0b..b40960712 100644 --- a/crates/horizon-client/src/game/nether_portal.rs +++ b/crates/horizon-client/src/game/nether_portal.rs @@ -481,9 +481,10 @@ impl Game<'_> { .filter(|m| self.mob_can_use_portal(m)) .map(|m| (m.id, m.position, m.width(), m.height())) .collect(); + let mut portal_sections = horizon_client::fast_hash::FxHashMap::default(); for (id, to, width, height) in items.into_iter().chain(mobs) { let from = self.portals.before.get(&id).copied().unwrap_or(to); - if let Some(pos) = self.swept_portal(from, to, width, height) { + if let Some(pos) = self.swept_portal(from, to, width, height, &mut portal_sections) { inside.push((id, pos)); } } @@ -497,7 +498,14 @@ impl Game<'_> { } /// The first nether portal block an entity box swept through /// (`Entity.checkInsideBlocks`, whose first portal sets the entry). - fn swept_portal(&self, from: Vec3, to: Vec3, width: f32, height: f32) -> Option { + fn swept_portal( + &self, + from: Vec3, + to: Vec3, + width: f32, + height: f32, + portal_sections: &mut horizon_client::fast_hash::FxHashMap<(i32, i32, i32), bool>, + ) -> Option { let half = f64::from(width) / 2.0; let bounds = horizon_core::geometry::Aabb::new( Vec3::new(to.x - half, to.y, to.z - half), @@ -508,6 +516,13 @@ impl Game<'_> { f64::from(1.0e-5_f32), f64::from(1.0e-5_f32), )); + // Every block the sweep visits lies in the box covering both ends. + let reach = bounds + .union_bounds(bounds.move_by(from.subtract(to))) + .inflate(Vec3::new(1.0, 1.0, 1.0)); + if !self.may_hold_portal(reach, portal_sections) { + return None; + } let mut found = None; let _ = horizon_core::geometry::sweep_intersected_blocks( from, @@ -529,6 +544,54 @@ impl Game<'_> { ); found } + /// Whether a section `reach` touches has a nether portal state in its + /// palette: without one, no block there is a portal. Answers are kept + /// per section for the tick; a box over many sections is not checked. + fn may_hold_portal( + &self, + reach: horizon_core::geometry::Aabb, + seen: &mut horizon_client::fast_hash::FxHashMap<(i32, i32, i32), bool>, + ) -> bool { + use horizon_client::chunk::{MIN_Y, SECTIONS}; + let (min, max) = (reach.min_position(), reach.max_position()); + if !min.is_finite() || !max.is_finite() { + return true; + } + let (min, max) = (BlockPos::containing(min), BlockPos::containing(max)); + let top = SECTIONS as i32 - 1; + let (x0, x1) = (min.x >> 4, max.x >> 4); + let (z0, z1) = (min.z >> 4, max.z >> 4); + let (y0, y1) = ( + ((min.y - MIN_Y) >> 4).clamp(0, top), + ((max.y - MIN_Y) >> 4).clamp(0, top), + ); + let count = (i64::from(x1) - i64::from(x0) + 1) + * (i64::from(y1) - i64::from(y0) + 1) + * (i64::from(z1) - i64::from(z0) + 1); + if count > 64 { + return true; + } + let behaviours = &self.res.behaviours; + let chunks = &self.world.chunks; + (x0..=x1).any(|cx| { + (z0..=z1).any(|cz| { + (y0..=y1).any(|sy| { + *seen.entry((cx, sy, cz)).or_insert_with(|| { + chunks + .get(&(cx, cz)) + .and_then(|c| c.sections.get(sy as usize)) + .is_some_and(|s| { + s.blocks.maybe_has(|v| { + behaviours + .portal_axis(horizon_world::registry::BlockStateId(v)) + .is_some() + }) + }) + }) + }) + }) + }) + } /// `Entity.teleportCrossDimension` away from the loaded dimension: the /// entity is saved and removed, and waits for its dimension to load. fn send_through_portal(&mut self, id: u32, entry: BlockPos) { From cceda07476b2b15f7638d5a5b25269dd8611ab86 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 05:57:42 +0200 Subject: [PATCH 14/46] Sculk: find a loaded chunk's sensors from its palettes, not every block When chunks arrive, the sculk index looks through them for sensors, shriekers and catalysts. It unpacked and tested all 4,096 blocks of every section that wasn't uniform: 10 to 18 ms in a tick after a world loaded, more over a larger render distance (#489). A section whose palette holds no sculk state has no sculk block, so it is passed over without reading its blocks; the others are scanned as before, and the same blocks are found. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/sculk.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/horizon-client/src/game/sculk.rs b/crates/horizon-client/src/game/sculk.rs index 6701181e7..6901200f1 100644 --- a/crates/horizon-client/src/game/sculk.rs +++ b/crates/horizon-client/src/game/sculk.rs @@ -373,6 +373,14 @@ impl Game<'_> { let mut found = Vec::new(); for (s, section) in chunk.sections.iter().enumerate() { let y0 = MIN_Y + s as i32 * 16; + // Without a sculk state in its palette, no block of the section + // is one: most sections are passed over without reading a block. + if !section + .blocks + .maybe_has(|v| u16::try_from(v).is_ok_and(|v| self.kind_of_state(v) != 0)) + { + continue; + } if section.blocks.uniform().is_some() { // A uniform section of sculk blocks does not exist. continue; From ed09e757baafff66547f14945f3e7ae46a7e30df Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 05:57:47 +0200 Subject: [PATCH 15/46] Pathfinder: hash nodes with the Fx hasher, and work out each path type once Path searches (vanilla's PathFinder with WalkNodeEvaluator) were 14 % of the world tick with 80 villagers. Two costs vanilla doesn't have: - the node index and the per-query path type and collision caches used the standard SipHash; vanilla keys them by packed position in fastutil maps. They use the Fx hasher now (nothing iterates them, so no order changes); - a position's static path type (its block, the one below and up to 24 neighbours, `getPathTypeStatic`) was worked out again for every mob box that covered it. Vanilla caches the block part level-wide (`PathTypeCache`); the finder now remembers each position's type for the query, during which the world doesn't change. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/mobs/path.rs | 30 +++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/crates/horizon-client/src/mobs/path.rs b/crates/horizon-client/src/mobs/path.rs index 368dead97..abadc9565 100644 --- a/crates/horizon-client/src/mobs/path.rs +++ b/crates/horizon-client/src/mobs/path.rs @@ -4,8 +4,8 @@ //! `AmphibiousNodeEvaluator`), ported rule for rule. use super::{MobWorld, data}; use crate::blocks::Fluid; +use crate::fast_hash::FxHashMap; use horizon_core::geometry::{Aabb, Vec3}; -use std::collections::HashMap; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub enum PathType { @@ -301,10 +301,13 @@ pub struct Finder<'a, 'w> { mob: &'a PathMob, eval: Evaluator, nodes: Vec, - index: HashMap<(i32, i32, i32), u32>, + index: FxHashMap<(i32, i32, i32), u32>, heap: Vec, - types: HashMap<(i32, i32, i32), PathType>, - collisions: HashMap<[u64; 6], bool>, + types: FxHashMap<(i32, i32, i32), PathType>, + /// `path_type` of each position asked during this query: it reads up to + /// 26 blocks, and overlapping mob boxes ask for the same positions. + statics: std::cell::RefCell>, + collisions: FxHashMap<[u64; 6], bool>, entity_width: i32, entity_height: i32, entity_depth: i32, @@ -319,10 +322,11 @@ impl<'a, 'w> Finder<'a, 'w> { mob, eval, nodes: Vec::new(), - index: HashMap::new(), + index: FxHashMap::default(), heap: Vec::new(), - types: HashMap::new(), - collisions: HashMap::new(), + types: FxHashMap::default(), + statics: Default::default(), + collisions: FxHashMap::default(), entity_width: (mob.width + 1.0).floor() as i32, entity_height: (mob.height + 1.0).floor() as i32, entity_depth: (mob.width + 1.0).floor() as i32, @@ -385,7 +389,17 @@ impl<'a, 'w> Finder<'a, 'w> { } // --- path types ----------------------------------------------------- /// WalkNodeEvaluator.getPathTypeStatic (+ the fly/amphibious overrides). + /// The world doesn't change during a query, so each position's type is + /// worked out once. fn path_type(&self, x: i32, y: i32, z: i32) -> PathType { + if let Some(t) = self.statics.borrow().get(&(x, y, z)) { + return *t; + } + let t = self.compute_path_type(x, y, z); + self.statics.borrow_mut().insert((x, y, z), t); + t + } + fn compute_path_type(&self, x: i32, y: i32, z: i32) -> PathType { match self.eval { Evaluator::Fly => self.fly_path_type(x, y, z), Evaluator::Amphibious { .. } => { @@ -991,7 +1005,7 @@ impl<'a, 'w> Finder<'a, 'w> { let malus = |s: &Self, n: Option| n.is_some_and(|n| s.nodes[n as usize].cost_malus >= 0.0); // Direction.values(): down, up, north, south, west, east. - let mut by_dir: HashMap<(i32, i32, i32), Option> = HashMap::new(); + let mut by_dir: FxHashMap<(i32, i32, i32), Option> = FxHashMap::default(); for (dx, dy, dz) in [ (0, -1, 0), (0, 1, 0), From ee104603dde8ebbe5c86efa939de4259f958fd16 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 06:06:02 +0200 Subject: [PATCH 16/46] horizon-port-pack: a library, fetch and port; CurseForge zips name their mods The launcher's "Import modpack" needs the pipeline as a library and a way to get the jars a pack names without redistributing anything. - The steps move into the library (pipeline.rs) with a line callback, so the command line and the launcher run the same code; main.rs is a thin CLI. - fetch: the jars of the portable mods (content, data tier) into /jars/, the player's own downloads: copied from a folder they have (by SHA-1, or a CurseForge app instance's minecraftinstance.json), else from the pack's own link (.mrpack hosts only) or the same file on Modrinth's public CDN found by SHA-1, kept only when the hash matches. What only CurseForge has is listed as needing a CurseForge API key. /fetch.json records each file. - port: every step after the import for the portable mods (fetch, the inventory again with the jars read, carry, report). - A CurseForge zip whose overrides hold Crash Assistant's modlist.json (All the Mods 10 does) takes its jar names, mod ids and SHA-1s instead of bare project ids, so Modrinth answers for most files. - inventory goes on offline when Modrinth cannot be reached. All the Mods 10 8.3's CurseForge zip: 496 files named; of the 54 data-tier content mods 42 download from Modrinth's CDN (84 MB) and 12 need the key or the player's instance; 42 carried over (partial: the harness is a dev step). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-port-pack/src/fetch.rs | 389 +++++++++++++++++++++++ crates/horizon-port-pack/src/import.rs | 59 +++- crates/horizon-port-pack/src/lib.rs | 17 + crates/horizon-port-pack/src/main.rs | 259 +++++---------- crates/horizon-port-pack/src/modrinth.rs | 6 +- crates/horizon-port-pack/src/pipeline.rs | 237 ++++++++++++++ crates/horizon-port-pack/src/report.rs | 2 +- docs/modpacks.md | 20 +- 8 files changed, 793 insertions(+), 196 deletions(-) create mode 100644 crates/horizon-port-pack/src/fetch.rs create mode 100644 crates/horizon-port-pack/src/lib.rs create mode 100644 crates/horizon-port-pack/src/pipeline.rs diff --git a/crates/horizon-port-pack/src/fetch.rs b/crates/horizon-port-pack/src/fetch.rs new file mode 100644 index 000000000..011e99e1f --- /dev/null +++ b/crates/horizon-port-pack/src/fetch.rs @@ -0,0 +1,389 @@ +//! Step 1b, the jars: for the mods the player asked to port, their own +//! download of each jar into `/jars/`. Only from where the pack itself +//! points (a Modrinth pack's download URLs) or the same file on Modrinth's +//! public CDN (found by its SHA-1), and only kept when the hash matches; or +//! copied from a folder the player already has (an installed instance, a +//! downloads folder). CurseForge's own downloads need an API key, so a file +//! only CurseForge has is listed as needing one. `/fetch.json` says +//! what happened to each file. +use crate::{ + import::{Pack, PackFile, sha1_hex}, + inventory::Record, + modrinth::{self, Cache}, + pipeline::{Log, read_json, write_json}, +}; +use serde::{Deserialize, Serialize}; +use serde_json::Value; +use std::{ + collections::HashMap, + fs, + io::Read, + path::{Path, PathBuf}, +}; + +/// Hosts a Modrinth pack may download from (the `.mrpack` format's list). +const HOSTS: [&str; 4] = [ + "https://cdn.modrinth.com/", + "https://github.com/", + "https://raw.githubusercontent.com/", + "https://gitlab.com/", +]; +/// No mod jar is this large; a bigger answer is not one. +const MAX_JAR: u64 = 512 << 20; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "kebab-case")] +pub enum How { + /// Already in `jars/` (or the imported instance). + Present, + /// Downloaded from the pack's URL or Modrinth's CDN, hash checked. + Downloaded, + /// Copied from the player's folder. + Local, + /// Only on CurseForge, whose downloads need an API key. + NeedsKey, + NotFound, + Failed, +} + +impl How { + pub fn label(self) -> &'static str { + match self { + How::Present => "already here", + How::Downloaded => "downloaded", + How::Local => "copied from your folder", + How::NeedsKey => "needs a CurseForge key", + How::NotFound => "not found", + How::Failed => "failed", + } + } +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Outcome { + pub key: String, + pub file: String, + pub how: How, + #[serde(default, skip_serializing_if = "String::is_empty")] + pub detail: String, +} + +#[derive(Debug, Default, Serialize, Deserialize)] +pub struct Fetched { + pub files: Vec, +} + +impl Fetched { + pub fn count(&self, how: How) -> usize { + self.files.iter().filter(|o| o.how == how).count() + } + /// `/fetch.json`, empty when the step has not run. + pub fn load(work: &Path) -> Self { + read_json(&work.join("fetch.json")).unwrap_or_default() + } +} + +/// The jars of the records `want` picks that the work folder lacks. +pub fn fetch( + work: &Path, + records: &[Record], + from: Option<&Path>, + want: &dyn Fn(&Record) -> bool, + log: Log, +) -> Result { + let pack: Pack = read_json(&work.join("pack.json"))?; + let cache = Cache::load(&work.join("modrinth.json")); + let files: HashMap<&str, &PackFile> = pack.files.iter().map(|f| (f.path.as_str(), f)).collect(); + let jars = work.join("jars"); + fs::create_dir_all(&jars).map_err(|e| format!("{}: {e}", jars.display()))?; + let local = from.map(Local::index); + let wanted: Vec<&Record> = records.iter().filter(|r| want(r)).collect(); + let mut fetched = Fetched::default(); + for (i, r) in wanted.iter().enumerate() { + let Some(file) = files.get(r.path.as_str()) else { + continue; + }; + let name = file.file_name(); + let outcome = |how, detail: String| Outcome { + key: r.key.clone(), + file: name.to_owned(), + how, + detail, + }; + let dest = jars.join(name); + let sha1 = file.sha1.as_deref(); + let o = if r.jar.is_some() || matches(&dest, sha1) { + outcome(How::Present, String::new()) + } else if let Some(path) = local.as_ref().and_then(|l| l.find(file)) { + match fs::copy(&path, &dest) { + Ok(_) => outcome(How::Local, path.display().to_string()), + Err(e) => outcome(How::Failed, format!("{}: {e}", path.display())), + } + } else if let Some(url) = url_of(file, &cache) { + log(format!("{}/{} {name}", i + 1, wanted.len())); + match download(&url, sha1, &dest) { + Ok(()) => outcome(How::Downloaded, url), + Err(e) => outcome(How::Failed, e), + } + } else if pack.format == "curseforge" || file.curseforge.is_some() { + outcome( + How::NeedsKey, + "on CurseForge only: choose your installed instance, or put the jar in jars/" + .into(), + ) + } else { + outcome(How::NotFound, "no download link in the pack".into()) + }; + if matches!(o.how, How::Failed | How::NeedsKey | How::NotFound) { + log(format!("{}: {} ({})", o.key, o.how.label(), o.detail)); + } + fetched.files.push(o); + } + write_json(&work.join("fetch.json"), &fetched)?; + log(format!( + "jars: {} downloaded, {} copied, {} already here, {} need a CurseForge key, {} not found, {} failed", + fetched.count(How::Downloaded), + fetched.count(How::Local), + fetched.count(How::Present), + fetched.count(How::NeedsKey), + fetched.count(How::NotFound), + fetched.count(How::Failed) + )); + Ok(fetched) +} + +/// Whether `path` holds the file with this SHA-1 (any file when none is known). +fn matches(path: &Path, sha1: Option<&str>) -> bool { + match (fs::read(path), sha1) { + (Ok(bytes), Some(h)) => sha1_hex(&bytes).eq_ignore_ascii_case(h), + (Ok(_), None) => true, + (Err(_), _) => false, + } +} + +/// The pack's own download link, else the same file on Modrinth. +pub fn url_of(file: &PackFile, cache: &Cache) -> Option { + let allowed = |u: &&str| HOSTS.iter().any(|h| u.starts_with(h)); + if let Some(u) = file.downloads.iter().map(String::as_str).find(allowed) { + return Some(u.to_owned()); + } + let sha1 = file.sha1.as_deref()?; + cache.versions.get(sha1)?["files"] + .as_array()? + .iter() + .find(|f| f["hashes"]["sha1"].as_str() == Some(sha1))?["url"] + .as_str() + .filter(allowed) + .map(str::to_owned) +} + +/// Downloads `url` to `dest`, kept only if its SHA-1 is `sha1`. +fn download(url: &str, sha1: Option<&str>, dest: &Path) -> Result<(), String> { + let response = ureq::get(url) + .set("User-Agent", modrinth::AGENT) + .call() + .map_err(|e| format!("{url}: {e}"))?; + let mut bytes = Vec::new(); + response + .into_reader() + .take(MAX_JAR) + .read_to_end(&mut bytes) + .map_err(|e| format!("{url}: {e}"))?; + let got = sha1_hex(&bytes); + if let Some(want) = sha1.filter(|w| !w.eq_ignore_ascii_case(&got)) { + return Err(format!("{url}: SHA-1 {got}, the pack says {want}")); + } + let part = dest.with_extension("part"); + fs::write(&part, &bytes).map_err(|e| format!("{}: {e}", part.display()))?; + fs::rename(&part, dest).map_err(|e| format!("{}: {e}", dest.display())) +} + +/// The jars in a folder of the player's, by SHA-1 and by name, and what a +/// CurseForge app instance (`minecraftinstance.json`) says each +/// project's file is called. +#[derive(Default)] +struct Local { + by_sha1: HashMap, + by_name: HashMap, + curseforge: HashMap<(u64, u64), String>, +} + +impl Local { + fn index(dir: &Path) -> Local { + let mut local = Local::default(); + local.walk(dir, 3); + if let Ok(text) = fs::read_to_string(dir.join("minecraftinstance.json")) { + if let Ok(v) = serde_json::from_str::(&text) { + local.curseforge = curseforge_names(&v); + } + } + local + } + + fn walk(&mut self, dir: &Path, depth: usize) { + let Ok(entries) = fs::read_dir(dir) else { + return; + }; + for path in entries.flatten().map(|e| e.path()) { + if path.is_dir() { + if depth > 0 { + self.walk(&path, depth - 1); + } + } else if path.extension().is_some_and(|x| x == "jar") { + if let Ok(bytes) = fs::read(&path) { + self.by_sha1.insert(sha1_hex(&bytes), path.clone()); + } + if let Some(n) = path.file_name() { + self.by_name + .insert(n.to_string_lossy().into_owned(), path.clone()); + } + } + } + } + + fn find(&self, file: &PackFile) -> Option { + if let Some(h) = &file.sha1 { + return self.by_sha1.get(&h.to_ascii_lowercase()).cloned(); + } + let name = file + .curseforge + .and_then(|ids| self.curseforge.get(&ids)) + .map_or(file.file_name(), String::as_str); + self.by_name.get(name).cloned() + } +} + +/// `installedAddons[]`: (project, file) → the jar's file name. +pub fn curseforge_names(instance: &Value) -> HashMap<(u64, u64), String> { + instance["installedAddons"] + .as_array() + .into_iter() + .flatten() + .filter_map(|a| { + let file = &a["installedFile"]; + Some(( + (a["addonID"].as_u64()?, file["id"].as_u64()?), + file["fileName"].as_str()?.to_owned(), + )) + }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + fn file(sha1: Option<&str>, downloads: &[&str]) -> PackFile { + PackFile { + path: "mods/a.jar".into(), + sha1: sha1.map(str::to_owned), + downloads: downloads.iter().map(|d| (*d).to_owned()).collect(), + ..PackFile::default() + } + } + + #[test] + fn links_come_from_the_pack_or_modrinth_and_only_allowed_hosts() { + let mut cache = Cache::default(); + cache.versions.insert( + "ab".into(), + json!({"files": [ + {"hashes": {"sha1": "cd"}, "url": "https://cdn.modrinth.com/other.jar"}, + {"hashes": {"sha1": "ab"}, "url": "https://cdn.modrinth.com/a.jar"}]}), + ); + let pack_link = file( + Some("ab"), + &["https://evil.example/a.jar", "https://github.com/a.jar"], + ); + assert_eq!( + url_of(&pack_link, &cache).as_deref(), + Some("https://github.com/a.jar") + ); + let modrinth = file(Some("ab"), &["https://evil.example/a.jar"]); + assert_eq!( + url_of(&modrinth, &cache).as_deref(), + Some("https://cdn.modrinth.com/a.jar") + ); + assert_eq!(url_of(&file(Some("ef"), &[]), &cache), None); + assert_eq!(url_of(&file(None, &[]), &cache), None); + } + + #[test] + fn reads_a_curseforge_instance() { + let instance = json!({"installedAddons": [ + {"addonID": 238222, "installedFile": {"id": 5101366, "fileName": "jei-1.21.1.jar"}}, + {"addonID": 1, "installedFile": {"fileName": "no-id.jar"}}]}); + let names = curseforge_names(&instance); + assert_eq!(names.len(), 1); + assert_eq!(names[&(238222, 5101366)], "jei-1.21.1.jar"); + } + + #[test] + fn copies_the_players_jars_and_lists_what_needs_a_key() { + let root = std::env::temp_dir().join(format!("horizon-fetch-{}", std::process::id())); + let _ = fs::remove_dir_all(&root); + let (work, mine) = (root.join("work"), root.join("instance/mods")); + fs::create_dir_all(&mine).unwrap(); + fs::create_dir_all(&work).unwrap(); + fs::write(mine.join("renamed.jar"), b"jar a").unwrap(); + fs::write(mine.join("cf.jar"), b"jar b").unwrap(); + fs::write( + root.join("instance/minecraftinstance.json"), + json!({"installedAddons": [{"addonID": 7, "installedFile": {"id": 8, "fileName": "cf.jar"}}]}) + .to_string(), + ) + .unwrap(); + let pack = Pack { + format: "curseforge".into(), + files: vec![ + PackFile { + path: "mods/a.jar".into(), + sha1: Some(sha1_hex(b"jar a")), + ..PackFile::default() + }, + PackFile { + path: "mods/curseforge-7-8".into(), + curseforge: Some((7, 8)), + ..PackFile::default() + }, + PackFile { + path: "mods/curseforge-9-9".into(), + curseforge: Some((9, 9)), + ..PackFile::default() + }, + ], + ..Pack::default() + }; + write_json(&work.join("pack.json"), &pack).unwrap(); + let records: Vec = pack + .files + .iter() + .map(|f| Record { + key: f.file_name().into(), + path: f.path.clone(), + ..Record::default() + }) + .collect(); + let fetched = fetch( + &work, + &records, + Some(&root.join("instance")), + &|_| true, + &|_| {}, + ) + .unwrap(); + let hows: Vec = fetched.files.iter().map(|o| o.how).collect(); + assert_eq!(hows, [How::Local, How::Local, How::NeedsKey]); + assert_eq!(fs::read(work.join("jars/a.jar")).unwrap(), b"jar a"); + assert_eq!( + fs::read(work.join("jars/curseforge-7-8")).unwrap(), + b"jar b" + ); + // A second run finds them in place. + let again = fetch(&work, &records, None, &|_| true, &|_| {}).unwrap(); + assert_eq!(again.count(How::Present), 2); + assert_eq!(Fetched::load(&work).count(How::Present), 2); + fs::remove_dir_all(&root).unwrap(); + } +} diff --git a/crates/horizon-port-pack/src/import.rs b/crates/horizon-port-pack/src/import.rs index dd712acf1..0a3aa8d06 100644 --- a/crates/horizon-port-pack/src/import.rs +++ b/crates/horizon-port-pack/src/import.rs @@ -22,8 +22,20 @@ pub struct Pack { pub files: Vec, /// Override files by top folder (`config`, `kubejs`, ...). pub overrides: BTreeMap, + /// A CurseForge zip's files by project and file id only: how many its + /// manifest lists, when the files came from the pack's own mod list. + #[serde(default, skip_serializing_if = "is_zero")] + pub curseforge_files: usize, } +fn is_zero(n: &usize) -> bool { + *n == 0 +} + +/// Where Crash Assistant keeps its list in an instance (and in the +/// overrides of packs that ship it, such as All the Mods 10). +pub const MODLIST: &str = "config/crash_assistant/modlist.json"; + #[derive(Debug, Default, Serialize, Deserialize)] pub struct PackFile { /// Path in the instance (`mods/create-1.21.1-6.0.4.jar`). @@ -83,7 +95,16 @@ pub fn import(path: &Path) -> Result { return Ok(mrpack(&index, &names(&zip))); } if let Some(manifest) = read_json(&mut zip, "manifest.json")? { - return Ok(curseforge(&manifest, &names(&zip))); + let mut pack = curseforge(&manifest, &names(&zip)); + // The manifest names files only by CurseForge ids, which need a key + // to resolve; the pack's own mod list names them and gives their + // SHA-1s, so Modrinth can answer for most. + let root = manifest["overrides"].as_str().unwrap_or("overrides"); + if let Some(list) = read_json(&mut zip, &format!("{root}/{MODLIST}"))? { + pack.curseforge_files = pack.files.len(); + pack.files = modlist(&list)?.files; + } + return Ok(pack); } Err(format!( "{}: neither modrinth.index.json nor manifest.json", @@ -103,7 +124,7 @@ fn read_json(zip: &mut zip::ZipArchive, name: &str) -> Result Pack { names, &["overrides", "client-overrides", "server-overrides"], ), + ..Pack::default() } } @@ -197,6 +219,7 @@ pub fn curseforge(manifest: &Value, names: &[String]) -> Pack { loader_version: loader_version.to_owned(), files, overrides: overrides(names, &[root]), + ..Pack::default() } } @@ -418,4 +441,36 @@ mod tests { assert_eq!(p.files[0].curseforge, Some((238222, 5101366))); assert_eq!(p.overrides["kubejs"], 1); } + + #[test] + fn a_curseforge_zip_takes_names_from_its_mod_list() { + use std::io::Write; + let dir = std::env::temp_dir().join(format!("horizon-cf-zip-{}", std::process::id())); + fs::create_dir_all(&dir).unwrap(); + let path = dir.join("pack.zip"); + let mut zip = zip::ZipWriter::new(fs::File::create(&path).unwrap()); + let opts = zip::write::SimpleFileOptions::default(); + let manifest = json!({"name": "Pack", "overrides": "overrides", + "minecraft": {"version": "1.21.1", "modLoaders": [{"id": "neoforge-21.1.259"}]}, + "files": [{"projectID": 1, "fileID": 2}, {"projectID": 3, "fileID": 4}]}); + zip.start_file("manifest.json", opts).unwrap(); + zip.write_all(manifest.to_string().as_bytes()).unwrap(); + zip.start_file(format!("overrides/{MODLIST}"), opts) + .unwrap(); + let list = json!({"mcw-doors-1.1.2.jar": {"jarName": "mcw-doors-1.1.2.jar", + "modId": "mcwdoors", "modrinthHash": "0123456789abcdef0123456789abcdef01234567"}}); + // Crash Assistant writes a byte order mark. + zip.write_all(format!("\u{feff}{list}").as_bytes()).unwrap(); + zip.finish().unwrap(); + let pack = import(&path).unwrap(); + assert_eq!( + (pack.format.as_str(), pack.name.as_str()), + ("curseforge", "Pack") + ); + assert_eq!(pack.curseforge_files, 2); + assert_eq!(pack.files.len(), 1); + assert_eq!(pack.files[0].path, "mods/mcw-doors-1.1.2.jar"); + assert_eq!(pack.overrides["config"], 1); + fs::remove_dir_all(&dir).unwrap(); + } } diff --git a/crates/horizon-port-pack/src/lib.rs b/crates/horizon-port-pack/src/lib.rs new file mode 100644 index 000000000..ecd61956c --- /dev/null +++ b/crates/horizon-port-pack/src/lib.rs @@ -0,0 +1,17 @@ +//! Port a Java modpack to Horizon (`docs/modpacks.md`): the steps behind the +//! `horizon-port-pack` command, and the launcher's "Import modpack". +//! +//! Every step reads and writes files in a work folder (`pipeline`), so it can +//! be rerun, resumed and inspected. The work folder belongs to the user: the +//! jars they downloaded and what is carried over from them stay there and +//! are never uploaded or committed. +pub mod carry; +pub mod classify; +pub mod fetch; +pub mod import; +pub mod inventory; +pub mod jar; +pub mod modrinth; +pub mod oracle; +pub mod pipeline; +pub mod report; diff --git a/crates/horizon-port-pack/src/main.rs b/crates/horizon-port-pack/src/main.rs index 3e6cdf4d7..e766a442d 100644 --- a/crates/horizon-port-pack/src/main.rs +++ b/crates/horizon-port-pack/src/main.rs @@ -6,57 +6,77 @@ //! `/modrinth.json`), the jars in the instance or `/jars/`, //! classes, tiers and dependency layers in `/inventory.json` and //! `inventory.csv`. +//! - `fetch [--from ] [...]`: the jars of the +//! portable mods (content, data tier; or the ones named) into +//! `/jars/`: copied from the player's folder, or downloaded from the +//! pack's own links or Modrinth's CDN, hash checked. What only CurseForge +//! has needs a key and is listed in `/fetch.json`. //! - `carry [--resources ] [...]`: the content //! mods' data and assets into `/mods//carry/`, a folder mod for //! local use. With the NeoForge oracle's `/oracle/facts.json` //! (`tools/neoforge_oracle.py`), blocks and items come from its facts; //! `--resources` limits templates to the blocks Horizon's tables have. -//! //! - `report `: the coverage report, per mod ported, partial, not yet //! or not needed with the reason, in `/coverage.json` and //! `coverage.md`. +//! - `port [--from ] [--resources ]`: every +//! step for the portable mods, as the launcher's "Import modpack" runs it. //! //! The work folder belongs to the user: jars and carried-over files stay //! there and are never uploaded or committed. -mod carry; -mod classify; -mod import; -mod inventory; -mod jar; -mod modrinth; -mod oracle; -mod report; +use horizon_port_pack::{fetch, inventory::Record, pipeline}; +use std::{ + path::{Path, PathBuf}, + process::ExitCode, +}; -use std::{fs, path::Path, process::ExitCode}; - -const USAGE: &str = "usage: horizon-port-pack import | inventory [--offline] | carry [--resources ] [...] | report "; +const USAGE: &str = "usage: horizon-port-pack import | inventory [--offline] | fetch [--from ] [...] | carry [--resources ] [...] | report | port [--from ] [--resources ]"; fn main() -> ExitCode { - let args: Vec = std::env::args().skip(1).collect(); - let path = |i: usize| args.get(i).map(Path::new).ok_or(USAGE.to_owned()); - let result = match args.first().map(String::as_str) { - Some("import") => path(1) - .and_then(|p| Ok((p, path(2)?))) - .and_then(|(p, w)| import(p, w)), - Some("inventory") => { - path(1).and_then(|w| inventory(w, args.iter().any(|a| a == "--offline"))) + let mut args: Vec = std::env::args().skip(1).collect(); + let result = (|| { + let from = option(&mut args, "--from")?; + let resources = option(&mut args, "--resources")?; + let offline = take_flag(&mut args, "--offline"); + let path = |i: usize| args.get(i).map(Path::new).ok_or(USAGE.to_owned()); + let rest = || args.get(2..).unwrap_or_default().to_vec(); + let log = &|line: String| println!("{line}"); + match args.first().map(String::as_str) { + Some("import") => pipeline::import(path(1)?, path(2)?, log).map(drop), + Some("inventory") => pipeline::inventory(path(1)?, offline, log).map(drop), + Some("fetch") => { + let work = path(1)?; + let records: Vec = pipeline::read_json(&work.join("inventory.json"))?; + let only = rest(); + let want = |r: &Record| { + if only.is_empty() { + pipeline::portable(r) + } else { + only.contains(&r.key) + } + }; + fetch::fetch(work, &records, from.as_deref(), &want, log).map(drop) + } + Some("carry") => { + pipeline::carry(path(1)?, resources.as_deref(), &rest(), log).map(drop) + } + Some("report") => { + let work = path(1)?; + pipeline::report(work, log)?; + println!("{}", work.join("coverage.md").display()); + Ok(()) + } + Some("port") => { + let work = path(2)?; + pipeline::import(path(1)?, work, log)?; + pipeline::inventory(work, offline, log)?; + pipeline::port(work, resources.as_deref(), from.as_deref(), log)?; + println!("{}", work.join("coverage.md").display()); + Ok(()) + } + _ => Err(USAGE.to_owned()), } - Some("carry") => path(1).and_then(|w| { - let mut rest = args[2..].to_vec(); - let resources = match rest.iter().position(|a| a == "--resources") { - Some(i) if i + 1 < rest.len() => { - let r = rest.remove(i + 1); - rest.remove(i); - Some(std::path::PathBuf::from(r)) - } - Some(_) => return Err(USAGE.to_owned()), - None => None, - }; - carry(w, resources.as_deref(), &rest) - }), - Some("report") => path(1).and_then(report), - _ => Err(USAGE.to_owned()), - }; + })(); match result { Ok(()) => ExitCode::SUCCESS, Err(e) => { @@ -66,158 +86,21 @@ fn main() -> ExitCode { } } -fn write_json(path: &Path, value: &impl serde::Serialize) -> Result<(), String> { - let text = serde_json::to_string_pretty(value).map_err(|e| e.to_string())?; - fs::write(path, text).map_err(|e| format!("{}: {e}", path.display())) -} - -fn read_json(path: &Path) -> Result { - let text = fs::read_to_string(path).map_err(|e| format!("{}: {e}", path.display()))?; - serde_json::from_str(&text).map_err(|e| format!("{}: {e}", path.display())) -} - -fn report(work: &Path) -> Result<(), String> { - let pack: import::Pack = read_json(&work.join("pack.json"))?; - let records: Vec = read_json(&work.join("inventory.json"))?; - let rows = report::build(&records, work); - write_json(&work.join("coverage.json"), &rows)?; - let title = format!( - "{} ({} {}, Minecraft {})", - pack.name, pack.loader, pack.loader_version, pack.minecraft - ); - fs::write(work.join("coverage.md"), report::markdown(&title, &rows)) - .map_err(|e| format!("coverage.md: {e}"))?; - println!("{title}: {} files: {:?}", rows.len(), report::counts(&rows)); - println!("{}", work.join("coverage.md").display()); - Ok(()) -} - -fn import(pack: &Path, work: &Path) -> Result<(), String> { - let pack = import::import(pack)?; - fs::create_dir_all(work).map_err(|e| format!("{}: {e}", work.display()))?; - write_json(&work.join("pack.json"), &pack)?; - let mut kinds = std::collections::BTreeMap::<&str, usize>::new(); - for f in &pack.files { - *kinds.entry(f.kind()).or_default() += 1; - } - println!( - "{} ({}): Minecraft {}, {} {}; files {kinds:?}; overrides {:?}", - pack.name, pack.format, pack.minecraft, pack.loader, pack.loader_version, pack.overrides - ); - Ok(()) -} - -fn inventory(work: &Path, offline: bool) -> Result<(), String> { - let pack: import::Pack = read_json(&work.join("pack.json"))?; - let cache_path = work.join("modrinth.json"); - let mut cache = modrinth::Cache::load(&cache_path); - if !offline { - let hashes: Vec = pack.files.iter().filter_map(|f| f.sha1.clone()).collect(); - cache.fetch(&hashes)?; - write_json(&cache_path, &cache)?; - } - let records = inventory::build(&pack, &cache, work); - write_json(&work.join("inventory.json"), &records)?; - fs::write(work.join("inventory.csv"), inventory::csv(&records)) - .map_err(|e| format!("inventory.csv: {e}"))?; - let jars = records.iter().filter(|r| r.jar.is_some()).count(); - println!("{} files, {jars} jars read", records.len()); - for (title, field) in [ - ( - "class", - (|r: &inventory::Record| r.class.as_str()) as fn(&inventory::Record) -> &str, - ), - ("tier", |r| r.tier.as_str()), - ("confidence", |r| r.confidence.as_str()), - ("source", |r| r.source.as_str()), - ] { - println!("{title}: {:?}", inventory::counts(&records, field)); - } - let layers = records.iter().map(|r| r.layer).max().map_or(0, |m| m + 1); - let per_layer: Vec = (0..layers) - .map(|l| records.iter().filter(|r| r.layer == l).count()) - .collect(); - println!("layers: {per_layer:?}"); - let missing: usize = records.iter().map(|r| r.missing.len()).sum(); - if missing > 0 { - println!("{missing} required dependencies are not in the pack (see inventory.json)"); - } - Ok(()) -} - -/// The vanilla blocks a prepared resource root has (`facts.json`'s defaults). -fn vanilla_blocks(resources: &Path) -> Result, String> { - let facts: serde_json::Value = read_json(&resources.join("facts.json"))?; - let defaults = facts["defaults"] - .as_object() - .ok_or("facts.json: no defaults")?; - Ok(defaults.keys().cloned().collect()) -} - -fn carry(work: &Path, resources: Option<&Path>, only: &[String]) -> Result<(), String> { - let records: Vec = read_json(&work.join("inventory.json"))?; - let facts_path = work.join("oracle/facts.json"); - let facts = if facts_path.exists() { - let f = oracle::Facts::read(&facts_path)?; - println!( - "oracle facts: {} blocks, {} items", - f.blocks.len(), - f.items.len() - ); - Some(f) - } else { - None - }; - let vanilla = resources.map(vanilla_blocks).transpose()?; - let allowed = |b: &str| vanilla.as_ref().is_none_or(|v| v.contains(b)); - let mut done = 0; - for r in &records { - let chosen = if only.is_empty() { - r.class == "content" - } else { - only.contains(&r.key) - }; - let (Some(jar), Some(info)) = (&r.jar, &r.info) else { - if chosen && !only.is_empty() { - eprintln!("{}: no jar (put it in {}/jars/)", r.key, work.display()); - } - continue; - }; - if !chosen { - continue; - } - match carry::carry( - jar, - info, - &work.join("mods").join(&r.key), - facts.as_ref(), - &allowed, - ) { - Ok(report) => { - done += 1; - println!( - "{}: {} files, {} recipes upgraded ({} kept), {} loot tables upgraded, {} item definitions added, {} blocks ({} left out, {} with differences), {} items ({} left out), {} convention tags, {} outside", - r.key, - report.copied, - report.recipes_upgraded, - report.recipes_kept.len(), - report.loot_tables_upgraded, - report.item_definitions_added, - report.blocks.len(), - report.blocks_unknown.len(), - report.differences.len(), - report.items, - report.items_unknown.len(), - report.convention_tags, - report.outside.len() - ); - } - Err(e) => eprintln!("{}: {e}", r.key), +/// Removes `--name ` from `args`. +fn option(args: &mut Vec, name: &str) -> Result, String> { + match args.iter().position(|a| a == name) { + Some(i) if i + 1 < args.len() => { + let value = args.remove(i + 1); + args.remove(i); + Ok(Some(PathBuf::from(value))) } + Some(_) => Err(USAGE.to_owned()), + None => Ok(None), } - println!( - "{done} mods carried over into {}", - work.join("mods").display() - ); - Ok(()) +} + +fn take_flag(args: &mut Vec, name: &str) -> bool { + let before = args.len(); + args.retain(|a| a != name); + args.len() != before } diff --git a/crates/horizon-port-pack/src/modrinth.rs b/crates/horizon-port-pack/src/modrinth.rs index 8c34a2004..4e90c871a 100644 --- a/crates/horizon-port-pack/src/modrinth.rs +++ b/crates/horizon-port-pack/src/modrinth.rs @@ -1,13 +1,13 @@ //! Modrinth metadata for the pack's files: the version of each file by -//! SHA-1, and its project (categories, licence, sides). Only metadata: no -//! jar is downloaded. Answers are cached in `/modrinth.json`, so a +//! SHA-1, and its project (categories, licence, sides). Only metadata (the +//! jars are `fetch`'s). Answers are cached in `/modrinth.json`, so a //! rerun works offline. use serde::{Deserialize, Serialize}; use serde_json::Value; use std::{collections::BTreeMap, path::Path}; const API: &str = "https://api.modrinth.com/v2"; -const AGENT: &str = "ludovic111/horizon horizon-port-pack/0.1 (docs/modpacks.md)"; +pub(crate) const AGENT: &str = "ludovic111/horizon horizon-port-pack/0.1 (docs/modpacks.md)"; #[derive(Debug, Default, Serialize, Deserialize)] pub struct Cache { diff --git a/crates/horizon-port-pack/src/pipeline.rs b/crates/horizon-port-pack/src/pipeline.rs new file mode 100644 index 000000000..ddb39bf66 --- /dev/null +++ b/crates/horizon-port-pack/src/pipeline.rs @@ -0,0 +1,237 @@ +//! The steps on a work folder, as the command line and the launcher run +//! them. Each one reads what the earlier steps wrote and says what it did +//! through `log`, one line at a time. +use crate::{carry, fetch, import, inventory, modrinth, oracle, report}; +use std::{ + collections::{BTreeMap, BTreeSet}, + fs, + path::Path, +}; + +/// Where a step's lines go: the terminal, or the launcher's log. +pub type Log<'a> = &'a dyn Fn(String); + +pub fn write_json(path: &Path, value: &impl serde::Serialize) -> Result<(), String> { + let text = serde_json::to_string_pretty(value).map_err(|e| e.to_string())?; + fs::write(path, text).map_err(|e| format!("{}: {e}", path.display())) +} + +pub fn read_json(path: &Path) -> Result { + let text = fs::read_to_string(path).map_err(|e| format!("{}: {e}", path.display()))?; + serde_json::from_str(&text).map_err(|e| format!("{}: {e}", path.display())) +} + +/// Step 1: the pack at `pack` to `/pack.json`. +pub fn import(pack: &Path, work: &Path, log: Log) -> Result { + let pack = import::import(pack)?; + fs::create_dir_all(work).map_err(|e| format!("{}: {e}", work.display()))?; + write_json(&work.join("pack.json"), &pack)?; + let mut kinds = BTreeMap::<&str, usize>::new(); + for f in &pack.files { + *kinds.entry(f.kind()).or_default() += 1; + } + log(format!( + "{} ({}): Minecraft {}, {} {}; files {kinds:?}; overrides {:?}", + pack.name, pack.format, pack.minecraft, pack.loader, pack.loader_version, pack.overrides + )); + Ok(pack) +} + +/// Step 2: `/inventory.json` and `inventory.csv`. Online, Modrinth is +/// asked about the files it has not answered for yet; when it cannot be +/// reached, the cached answers and the reviewed table classify alone. +pub fn inventory(work: &Path, offline: bool, log: Log) -> Result, String> { + let pack: import::Pack = read_json(&work.join("pack.json"))?; + let cache_path = work.join("modrinth.json"); + let mut cache = modrinth::Cache::load(&cache_path); + if !offline { + let hashes: Vec = pack.files.iter().filter_map(|f| f.sha1.clone()).collect(); + match cache.fetch(&hashes) { + Ok(()) => write_json(&cache_path, &cache)?, + Err(e) => log(format!("Modrinth not reached, classifying offline: {e}")), + } + } + let records = inventory::build(&pack, &cache, work); + write_json(&work.join("inventory.json"), &records)?; + fs::write(work.join("inventory.csv"), inventory::csv(&records)) + .map_err(|e| format!("inventory.csv: {e}"))?; + let jars = records.iter().filter(|r| r.jar.is_some()).count(); + log(format!("{} files, {jars} jars read", records.len())); + for (title, field) in [ + ( + "class", + (|r: &inventory::Record| r.class.as_str()) as fn(&inventory::Record) -> &str, + ), + ("tier", |r| r.tier.as_str()), + ("confidence", |r| r.confidence.as_str()), + ("source", |r| r.source.as_str()), + ] { + log(format!("{title}: {:?}", inventory::counts(&records, field))); + } + let layers = records.iter().map(|r| r.layer).max().map_or(0, |m| m + 1); + let per_layer: Vec = (0..layers) + .map(|l| records.iter().filter(|r| r.layer == l).count()) + .collect(); + log(format!("layers: {per_layer:?}")); + let missing: usize = records.iter().map(|r| r.missing.len()).sum(); + if missing > 0 { + log(format!( + "{missing} required dependencies are not in the pack (see inventory.json)" + )); + } + Ok(records) +} + +/// The vanilla blocks a prepared resource root has (`facts.json`'s defaults). +fn vanilla_blocks(resources: &Path) -> Result, String> { + let facts: serde_json::Value = read_json(&resources.join("facts.json"))?; + let defaults = facts["defaults"] + .as_object() + .ok_or("facts.json: no defaults")?; + Ok(defaults.keys().cloned().collect()) +} + +/// Step 4: the content mods with a jar (or the ones in `only`) carried over +/// into `/mods//carry/`. Returns how many were. +pub fn carry( + work: &Path, + resources: Option<&Path>, + only: &[String], + log: Log, +) -> Result { + let records: Vec = read_json(&work.join("inventory.json"))?; + let facts_path = work.join("oracle/facts.json"); + let facts = if facts_path.exists() { + let f = oracle::Facts::read(&facts_path)?; + log(format!( + "oracle facts: {} blocks, {} items", + f.blocks.len(), + f.items.len() + )); + Some(f) + } else { + None + }; + // Without the prepared tables, templates are not limited to what the game has. + let vanilla = resources.and_then(|r| { + vanilla_blocks(r) + .inspect_err(|e| log(format!("templates not limited to the game's blocks: {e}"))) + .ok() + }); + let allowed = |b: &str| vanilla.as_ref().is_none_or(|v| v.contains(b)); + let mut done = 0; + for r in &records { + let chosen = if only.is_empty() { + r.class == "content" + } else { + only.contains(&r.key) + }; + let (Some(jar), Some(info)) = (&r.jar, &r.info) else { + if chosen && !only.is_empty() { + log(format!( + "{}: no jar (put it in {}/jars/)", + r.key, + work.display() + )); + } + continue; + }; + if !chosen { + continue; + } + match carry::carry( + jar, + info, + &work.join("mods").join(&r.key), + facts.as_ref(), + &allowed, + ) { + Ok(report) => { + done += 1; + log(format!( + "{}: {} files, {} recipes upgraded ({} kept), {} loot tables upgraded, {} item definitions added, {} blocks ({} left out, {} with differences), {} items ({} left out), {} convention tags, {} outside", + r.key, + report.copied, + report.recipes_upgraded, + report.recipes_kept.len(), + report.loot_tables_upgraded, + report.item_definitions_added, + report.blocks.len(), + report.blocks_unknown.len(), + report.differences.len(), + report.items, + report.items_unknown.len(), + report.convention_tags, + report.outside.len() + )); + } + Err(e) => log(format!("{}: {e}", r.key)), + } + } + log(format!( + "{done} mods carried over into {}", + work.join("mods").display() + )); + Ok(done) +} + +/// The pack's title as the report heads it. +pub fn title(pack: &import::Pack) -> String { + format!( + "{} ({} {}, Minecraft {})", + pack.name, pack.loader, pack.loader_version, pack.minecraft + ) +} + +/// Step 7: `/coverage.json` and `coverage.md`. +pub fn report(work: &Path, log: Log) -> Result, String> { + let pack: import::Pack = read_json(&work.join("pack.json"))?; + let records: Vec = read_json(&work.join("inventory.json"))?; + let rows = report::build(&records, work); + write_json(&work.join("coverage.json"), &rows)?; + let title = title(&pack); + fs::write(work.join("coverage.md"), report::markdown(&title, &rows)) + .map_err(|e| format!("coverage.md: {e}"))?; + log(format!( + "{title}: {} files: {:?}", + rows.len(), + report::counts(&rows) + )); + Ok(rows) +} + +/// What a player's machine can port today without an agent: content mods +/// of the data tier (carry-over only). +pub fn portable(r: &inventory::Record) -> bool { + r.class == "content" && r.tier == "data" +} + +/// Everything after the import, for the portable mods: their jars (`fetch`, +/// from `from` when the player has them), the inventory again with the jars +/// read, the carry-over and the report. `resources` is the prepared +/// version the ports will play on. +pub fn port( + work: &Path, + resources: Option<&Path>, + from: Option<&Path>, + log: Log, +) -> Result<(fetch::Fetched, Vec), String> { + let records = match read_json::>(&work.join("inventory.json")) { + Ok(r) => r, + Err(_) => inventory(work, false, log)?, + }; + let fetched = fetch::fetch(work, &records, from, &portable, log)?; + // The jars tell classes and tiers better than metadata alone. + let records = inventory(work, true, log)?; + let only: Vec = records + .iter() + .filter(|r| portable(r) && r.jar.is_some()) + .map(|r| r.key.clone()) + .collect(); + if only.is_empty() { + log("no portable mod has its jar: nothing to carry over".into()); + } else { + carry(work, resources, &only, log)?; + } + Ok((fetched, report(work, log)?)) +} diff --git a/crates/horizon-port-pack/src/report.rs b/crates/horizon-port-pack/src/report.rs index ffa025c79..a98dd0432 100644 --- a/crates/horizon-port-pack/src/report.rs +++ b/crates/horizon-port-pack/src/report.rs @@ -83,7 +83,7 @@ pub fn license_kind(license: &str) -> &'static str { /// What still blocks a mod of this tier that has not been carried over. fn not_yet(tier: &str) -> &'static str { match tier { - "data" => "data tier: carry-over only, no agent; its jar is not in the work folder", + "data" => "data tier: carry-over only, no agent; its jar is not here yet (fetch gets it)", "logic" => { "needs mod API 0.3: behaviour callbacks (use, place, break, ticks) and server events" } diff --git a/docs/modpacks.md b/docs/modpacks.md index 1d8609cef..fb9bca5f4 100644 --- a/docs/modpacks.md +++ b/docs/modpacks.md @@ -267,16 +267,32 @@ inspected: └── coverage.json, coverage.md ``` -**Status.** `import`, `inventory`, `carry` and `report` run today: +**Status.** `import`, `inventory`, `fetch`, `carry` and `report` run today, and `port` runs +them all for what a player's machine can port (content mods of the data tier), as the +launcher's "Import modpack" does: ``` cargo run -p horizon-port-pack -- import ~/Downloads/pack.mrpack ~/.horizon/ports/pack cargo run -p horizon-port-pack -- inventory ~/.horizon/ports/pack # --offline reuses modrinth.json +cargo run -p horizon-port-pack -- fetch ~/.horizon/ports/pack # the portable mods' jars, or name them +# --from : copy the player's own jars (an installed instance, a downloads folder) cargo run -p horizon-port-pack -- carry ~/.horizon/ports/pack # content mods with a jar, or name them # --resources : only templates Horizon's tables have cargo run -p horizon-port-pack -- report ~/.horizon/ports/pack # coverage.json and coverage.md +cargo run -p horizon-port-pack -- port ~/Downloads/pack.zip ~/.horizon/ports/pack [--from ] [--resources ] ``` +`fetch` gets each jar the player's way, never from us: copied from a folder they have (matched +by SHA-1, or through a CurseForge app instance's `minecraftinstance.json`), else downloaded from +the link the pack itself gives (a `.mrpack`'s, on the format's hosts only) or, for a CurseForge +pack, the same file on Modrinth's public CDN, found by its SHA-1. A jar is kept only when its +hash matches. A file only CurseForge has is listed as needing a CurseForge API key (Ludovic's +decision; open question below), with the player's installed instance as the way round it. +`/fetch.json` says what happened to each file. On All the Mods 10 8.3's CurseForge zip +(2026-10-17): of the 54 data-tier content mods, 42 come from Modrinth's CDN (84 MB) and 12 need +the key or the instance; `port` then carries the 42 over (0 ported, 42 partial: the harness is a +dev step). + `inventory` reads metadata only: Modrinth answers by file hash, and the jars only if the user's instance has them (an imported instance folder, or jars put in `/jars/`). Without jars, classes come from the reviewed table, Modrinth categories and sides; with jars, from their @@ -310,7 +326,7 @@ block's name breaking ties (`_pane`, `_gate`, `_trapdoor`). | Format | Read | Jars come from | |---|---|---| | Modrinth `.mrpack` | `modrinth.index.json`: `dependencies` (minecraft, neoforge / fabric-loader / forge / quilt-loader), `files[]` with path, sha1/sha512, `env` (client/server), download URLs; `overrides/`, `client-overrides/`, `server-overrides/` | downloaded from the listed Modrinth URLs, hash-checked | -| CurseForge zip | `manifest.json`: `minecraft.version`, `modLoaders[]`, `files[]` (`projectID`, `fileID`, `required`), `overrides` | the user's installed instance (CurseForge app `minecraftinstance.json` + `mods/`). CurseForge's API needs a key, so we take what the user already downloaded | +| CurseForge zip | `manifest.json`: `minecraft.version`, `modLoaders[]`, `files[]` (`projectID`, `fileID`, `required`), `overrides`. When the overrides hold Crash Assistant's `config/crash_assistant/modlist.json` (All the Mods 10 does), its jar names, mod ids and SHA-1s replace the bare ids | the user's installed instance (CurseForge app `minecraftinstance.json` + `mods/`), or the same file on Modrinth by SHA-1. CurseForge's API needs a key, so we take what the user already downloaded | | Prism / MultiMC instance | `mmc-pack.json` components (`net.minecraft`, `net.neoforged`, `net.fabricmc.fabric-loader`), `instance.cfg`, `.minecraft/mods/*.jar`, packwiz `.pw.toml` files if present | the instance folder | | packwiz | `pack.toml`, `index.toml`, `mods/*.pw.toml` | as listed | | Crash Assistant `modlist.json` | jar name → mod id, name, version, Modrinth SHA-1; the loader entry (NeoForge `21.1.x` is Minecraft 1.21.1). Packs such as ATM10 publish it in their repository | metadata only; jars put in `/jars/` | From 206b91e8aa6576c2a5e5d7e0ed3695d33920c7e3 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 07:00:45 +0200 Subject: [PATCH 17/46] Launcher: Import modpack, its coverage report, port and play it as a profile A Modpacks page between Versions and Patch notes (docs/modpacks.md, the working version's launcher step): - Import a pack file (.mrpack, CurseForge zip) or an instance folder (Prism, MultiMC, CurseForge): horizon-port-pack's import, inventory (Modrinth by file hash) and report into ports// in the game's home. - The coverage report: ported, partial, not yet and not needed, with every mod's class, tier, licence and reason, filtered by status. - Port: the portable mods' jars (content, data tier) the player's own way (their folder, the pack's links, Modrinth's CDN; what only CurseForge has needs its key and is said so), carried over for the selected version's prepared tables; the pipeline's log shows while it runs. - Play: the game as the pack's own profile, ports//home/ (its saves, options.txt copied from the player's the first time) with the carried-over mods as dev mods. The session flow is shared with Play (start_client). - The same from the command line: horizon-launcher modpack list | import | port | play | remove. Nothing is uploaded or shared; jars and ports stay in the game's home. Co-Authored-By: Claude Opus 5.5 --- launcher/Cargo.lock | 13 ++ launcher/Cargo.toml | 2 + launcher/README.md | 18 +- launcher/docs/modpacks.png | Bin 0 -> 113972 bytes launcher/src/backend.rs | 4 + launcher/src/cli.rs | 104 +++++++++ launcher/src/lib.rs | 1 + launcher/src/main.rs | 105 ++++++--- launcher/src/modpacks.rs | 249 ++++++++++++++++++++ launcher/src/modpacks_page.rs | 412 ++++++++++++++++++++++++++++++++++ 10 files changed, 875 insertions(+), 33 deletions(-) create mode 100644 launcher/docs/modpacks.png create mode 100644 launcher/src/modpacks.rs create mode 100644 launcher/src/modpacks_page.rs diff --git a/launcher/Cargo.lock b/launcher/Cargo.lock index 4a281729d..af0588af6 100644 --- a/launcher/Cargo.lock +++ b/launcher/Cargo.lock @@ -2664,6 +2664,7 @@ dependencies = [ "gpui", "horizon-bench", "horizon-friends", + "horizon-port-pack", "horizon-prepare", "horizon-telemetry", "horizon-theme", @@ -2680,6 +2681,18 @@ dependencies = [ "zip", ] +[[package]] +name = "horizon-port-pack" +version = "0.1.0" +dependencies = [ + "serde", + "serde_json", + "sha1", + "toml 1.1.8+spec-1.1.0", + "ureq", + "zip", +] + [[package]] name = "horizon-prepare" version = "0.1.0" diff --git a/launcher/Cargo.toml b/launcher/Cargo.toml index 8f5873f87..34af6e2a1 100644 --- a/launcher/Cargo.toml +++ b/launcher/Cargo.toml @@ -26,6 +26,8 @@ horizon-prepare = { path = "../crates/horizon-prepare" } # Join a friend: invite codes (the game does the joining). horizon-friends = { path = "../crates/horizon-friends" } horizon-bench = { path = "../crates/horizon-bench" } +# Import modpack: the porting pipeline, run on the player's own files (docs/modpacks.md). +horizon-port-pack = { path = "../crates/horizon-port-pack" } # Opt-in data collection: the consent, the outbox and its upload (docs/telemetry.md). horizon-telemetry = { path = "../crates/horizon-telemetry" } # The session file's random name. diff --git a/launcher/README.md b/launcher/README.md index e5edba182..b3dff7fde 100644 --- a/launcher/README.md +++ b/launcher/README.md @@ -25,6 +25,16 @@ The opening, then Play ([clip](docs/opening.webm)): preparation reuses checksum-verified game jars and libraries from the current or another installed Horizon version, so the original Minecraft install is only required when no valid imported copy exists. +- **Modpacks**: import a Java modpack (a Modrinth `.mrpack`, a CurseForge zip, or a Prism, + MultiMC or CurseForge instance folder) and see its coverage report: per mod, ported, partial, + not yet or not needed, with the reason ([docs/modpacks.md](../docs/modpacks.md)). **Port** + gets the jars of what this computer can port today (content mods with data and assets only) + the player's own way: copied from a folder they have, or downloaded from the pack's own links + or the same file on Modrinth's CDN, hash checked; files only CurseForge has need its API key, so + they come from your installed instance. It carries them over for the selected version, and + **Play** starts the game as the pack's own profile (`ports//home/` in the game's home: + its own saves and options) with those mods. Nothing is uploaded or shared: mod jars and ports + stay on this computer. - **Patch notes**: each release's notes, newest first, with a link to GitHub Sponsors. Quiet "Discord" and "Website" links sit in the footer. Data lives in the platform's data directory (`~/.local/share/horizon-launcher` on Linux, @@ -83,6 +93,11 @@ The same binary is a command-line tool; without a subcommand it opens the window horizon-launcher account sign-out horizon-launcher account select play as this account horizon-launcher account offline play without an account + horizon-launcher modpack [list] the imported packs and their coverage + horizon-launcher modpack import a .mrpack, CurseForge zip or instance folder + horizon-launcher modpack port [--from ] [--version ] get the jars and carry them over + horizon-launcher modpack play [--version ] play it as its own profile + horizon-launcher modpack remove horizon-launcher benchmark [--repeats N] measure the launcher (see Performance log) horizon-launcher data [status] what data collection is allowed, the install ID, what waits horizon-launcher data allow|deny performance, crashes, bugs, benchmarks @@ -92,7 +107,7 @@ The same binary is a command-line tool; without a subcommand it opens the window horizon-launcher data benchmark upload a benchmark report, printed first `--json` prints JSON where there is something to report (`versions`, `install`, `notes`, -`next`, `links`, `menu-style`, `update --check`, `logs`, `account`, `benchmark`, `data`). Errors go to stderr with exit code 1. `server` runs in the terminal, +`next`, `links`, `menu-style`, `update --check`, `logs`, `account`, `benchmark`, `data`, `modpack`). Errors go to stderr with exit code 1. `server` runs in the terminal, so lines you type reach its console. `HORIZON_LAUNCHER_HOME` replaces the data folder (for scripts and tests). @@ -192,6 +207,7 @@ bundled so the type is the same on every platform. ## Screenshots ![Server](docs/server.png) +![Modpacks](docs/modpacks.png) ![Versions](docs/versions.png) ![Patch notes](docs/patch-notes.png) ![Settings](docs/settings.png) diff --git a/launcher/docs/modpacks.png b/launcher/docs/modpacks.png new file mode 100644 index 0000000000000000000000000000000000000000..9abe41c64a59ff5e837c8768f56eb4aa2671a38a GIT binary patch literal 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*VjPtBi>vEUWNPfl$}W$13yj zt@omA+hPG&+ zaO>*?Ej1O#?Y`^g`v>CUPoxIz@7ERCIiG%cRVBFLlX5ikIHPDd4+hXZccs47rGH3q z7}f7{aG1cMO=bOz0c2wOctqx5MHqN}x)=jMSd1 zt9~--yo)ed^qqe$TuV1>lOmIth*4HBGRj53ZAeUDOfT7kJh)@E z78(wq1J%9b{KBCU*`}C4LwB$#*-@hole^0<;r`?w>lAS~tQlu_UnQ+@buEB{oK@Y> z%jU&%hc9E{oeH|*y2Sz$Jt{pOM~GI5rns(jrI05?C4j0j%JAtb zZ-a^S>^mr;!ja5(S+n=m&*B|UaS;*{YQ}LY?7v(&jHoEUCQd24S2qt@c&R#%_U8@; zEj~AxrVR^`cypYa+eM~q^olsb0&Lsw0^8cyx(4;PHyw_MUB8T@GujvTxL`sb*J~-# zy3ftd%p*k`8lDVyyGEPb_+D)bUa-TX0n3NL-d)}AUaj+RXX5slVlYrWf%c?fpW{I}fw-B3{ z;pEi|iwFx2N;x=*@C0gfa{g`(c}S=xlGj2?3Fw8>9@cL?DmiL7(mIZF#r{Dx(WiU!o+?2vAqM@QC1KZf^=vht1B`0NqNlFd zT5K!tjeLVb&$%+f5_5So11hL)BMqMx&yDLM6`lkpMOS*BHlvZx?$D>8;o zLweb2rGG!8yUL9WTHB!4LTyRT^Az2*Jq%Y6xrceCin^s`Rd$j8&x3O2OnfO`-G$$_ jI+#pC&;GwtC1X)`AuS_6?WY%i&5}, String>), + /// A modpack step's line (`modpacks`). + PackLine(String), + /// A modpack step ended: the pack as it now is. + PackDone(Result, String>), } /// A running process; its output arrives as `Msg::Line`, its end as `Msg::Exit`. diff --git a/launcher/src/cli.rs b/launcher/src/cli.rs index df9cfc6b1..b140979b3 100644 --- a/launcher/src/cli.rs +++ b/launcher/src/cli.rs @@ -76,6 +76,33 @@ enum DataCmd { }, } +#[derive(Subcommand)] +enum ModpackCmd { + /// The imported packs and their coverage (the default) + List, + /// Import a .mrpack, a CurseForge zip or an instance folder, and write its coverage report + Import { path: PathBuf }, + /// Get the jars of what this computer can port and carry them over + Port { + /// The pack's folder name, as list shows it + pack: String, + /// A folder with your own jars (an installed instance, a downloads folder) + #[arg(long)] + from: Option, + /// The installed version the ports are for (default: the selected one) + #[arg(long)] + version: Option, + }, + /// Play a ported pack as its own profile + Play { + pack: String, + #[arg(long)] + version: Option, + }, + /// Remove an imported pack: its jars, ports and the profile's saves + Remove { pack: String }, +} + #[derive(Subcommand)] enum Cmd { /// List Horizon releases, or the installed versions @@ -161,6 +188,12 @@ enum Cmd { #[command(subcommand)] action: Option, }, + /// Modpacks: import a Java pack, see its coverage report, port what this computer can and + /// play it as its own profile (docs/modpacks.md) + Modpack { + #[command(subcommand)] + action: Option, + }, /// Serve the Model Context Protocol on stdin and stdout, for AI agents Mcp, /// Measure the launcher: starts (the first is the cold one), page switching, idle CPU and @@ -400,6 +433,7 @@ fn execute(command: Cmd, as_json: bool) -> Result<(), String> { println!("Horizon is in the applications menu."); } } + Cmd::Modpack { action } => modpack(action.unwrap_or(ModpackCmd::List), as_json)?, Cmd::Mcp => unreachable!(), } Ok(()) @@ -591,3 +625,73 @@ fn data(action: DataCmd, as_json: bool) -> Result<(), String> { } Ok(()) } + +fn modpack(action: ModpackCmd, as_json: bool) -> Result<(), String> { + use horizon_launcher::modpacks::{self, Imported}; + use horizon_port_pack::report::Status; + let log = &|line: String| eprintln!("{line}"); + let work = |pack: &str| { + let work = modpacks::ports_dir().join(pack); + modpacks::load(&work).map(|_| work) + }; + let show = |p: &Imported| { + let counts: Vec = Status::ALL + .iter() + .map(|s| format!("{} {}", p.count(*s), s.label())) + .collect(); + if as_json { + json(serde_json::json!({ + "pack": p.slug, "name": p.title(), "summary": p.summary(), + "counts": Status::ALL.iter().map(|s| (s.label(), p.count(*s))).collect::>(), + "portable": p.portable, "ported_mods": p.mods.len(), "jars": p.jars(), + "report": p.work.join("coverage.md"), + })); + } else { + println!( + "{} ({})\n {}\n {}", + p.title(), + p.slug, + p.summary(), + counts.join(", ") + ); + println!(" {} portable, {} carried over", p.portable, p.mods.len()); + if let Some(jars) = p.jars() { + println!(" {jars}"); + } + println!(" {}", p.work.join("coverage.md").display()); + } + }; + match action { + ModpackCmd::List => { + let packs = modpacks::list(); + if packs.is_empty() && !as_json { + println!("No modpack imported yet: horizon-launcher modpack import "); + } + packs.iter().for_each(show); + } + ModpackCmd::Import { path } => show(&modpacks::import(&path, log)?), + ModpackCmd::Port { + pack, + from, + version, + } => { + let tag = backend::resolve_version(version.as_deref()).ok(); + let resources = tag + .filter(|t| backend::is_prepared(t)) + .map(|t| backend::resources(&t)); + show(&modpacks::port( + &work(&pack)?, + resources.as_deref(), + from.as_deref(), + log, + )?) + } + ModpackCmd::Play { pack, version } => { + let mut cmd = backend::client(&backend::resolve_version(version.as_deref())?)?; + modpacks::apply_profile(&mut cmd, &work(&pack)?)?; + attached(cmd)? + } + ModpackCmd::Remove { pack } => modpacks::remove(&work(&pack)?)?, + } + Ok(()) +} diff --git a/launcher/src/lib.rs b/launcher/src/lib.rs index 5df6a7cbb..11023a46d 100644 --- a/launcher/src/lib.rs +++ b/launcher/src/lib.rs @@ -2,6 +2,7 @@ pub mod account; pub mod backend; pub mod desktop; +pub mod modpacks; pub mod mojang; pub mod sources; pub mod telemetry; diff --git a/launcher/src/main.rs b/launcher/src/main.rs index cc66aa08e..ec1dacf78 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -6,6 +6,7 @@ mod collection; mod game_tools; mod markdown; mod mcp; +mod modpacks_page; mod perf; mod theme; @@ -29,14 +30,16 @@ use theme::Theme; enum Page { Play, Versions, + Modpacks, Notes, Settings, } impl Page { - const ALL: [(Page, &'static str); 4] = [ + const ALL: [(Page, &'static str); 5] = [ (Page::Play, "Play"), (Page::Versions, "Versions"), + (Page::Modpacks, "Modpacks"), (Page::Notes, "Patch notes"), (Page::Settings, "Settings"), ]; @@ -161,6 +164,17 @@ struct Launcher { play_pressed: Option, /// `horizon-launcher benchmark` started this window to measure it. bench: Option, + /// The Modpacks page: the imported packs (read when the page first opens), the one shown, + /// the report's filter, and the pipeline step running now with its log. + packs: Vec, + packs_loaded: Option, + pack_open: Option, + pack_filter: Option, + pack_busy: bool, + pack_log: VecDeque, + pack_error: Option, + /// The game starting now plays this pack's profile (its work folder). + starting_pack: Option, } impl Launcher { @@ -266,6 +280,14 @@ impl Launcher { prepare_started: None, play_pressed: None, bench: perf::Bench::from_env(), + packs: Vec::new(), + packs_loaded: None, + pack_open: None, + pack_filter: None, + pack_busy: false, + pack_log: VecDeque::new(), + pack_error: None, + starting_pack: None, }; if this.bench.is_some() { this.perf.keep_local_log(false); @@ -406,6 +428,14 @@ impl Launcher { Err(e) => self.client_error = Some(format!("Playing offline: {e}")), } self.accounts = Accounts::load(); + if let Some(work) = self.starting_pack.take() { + if let Err(e) = + horizon_launcher::modpacks::apply_profile(&mut cmd, &work) + { + self.client_error = Some(e); + continue; + } + } if let Some(code) = self.joining.take() { if let Err(e) = backend::join_friend(&mut cmd, &code) { self.client_error = Some(e); @@ -473,6 +503,13 @@ impl Launcher { Err(e) => SelfUpdate::Failed(e), }; } + Msg::PackLine(line) => { + self.pack_log.push_back(line); + if self.pack_log.len() > LOG_LINES { + self.pack_log.pop_front(); + } + } + Msg::PackDone(result) => self.pack_done(result), Msg::Line(job, line) => { if job == Job::Client && line.starts_with(perf::GAME_FIRST_FRAME) { if let Some(pressed) = self.play_pressed.take() { @@ -671,37 +708,8 @@ impl Launcher { if self.client.is_some() || self.starting_client.is_some() { return; } - self.client_error = None; - self.crash = None; - self.prepare_log.clear(); - // A little earlier than the spawn: file times can be coarse. - self.client_started = - Some(std::time::SystemTime::now() - std::time::Duration::from_secs(2)); - // The session (a network round trip when the token needs renewing) comes first; - // `drain` starts the game when it arrives. - self.starting_client = Some(tag); - self.play_pressed = Some(Instant::now()); - let tx = self.tx.clone(); - std::thread::spawn(move || { - let session = (|| { - let mut accounts = Accounts::load(); - let Some((a, secrets)) = account::session_for_launch( - &account::Endpoints::live(), - account::store(), - &mut accounts, - )? - else { - return Ok(None); - }; - account::write_session_file( - &backend::game_home().join("sessions"), - &a, - &secrets, - ) - .map(Some) - })(); - let _ = tx.send(Msg::Session(session)); - }); + self.starting_pack = None; + self.start_client(tag); } Mode::Server => { if let Some(server) = &mut self.server { @@ -729,6 +737,38 @@ impl Launcher { } } + /// Starts the game: the session first (a network round trip when the token needs + /// renewing), then `drain` starts the process when it arrives. + fn start_client(&mut self, tag: String) { + self.client_error = None; + self.crash = None; + self.prepare_log.clear(); + // A little earlier than the spawn: file times can be coarse. + self.client_started = + Some(std::time::SystemTime::now() - std::time::Duration::from_secs(2)); + // The session (a network round trip when the token needs renewing) comes first; + // `drain` starts the game when it arrives. + self.starting_client = Some(tag); + self.play_pressed = Some(Instant::now()); + let tx = self.tx.clone(); + std::thread::spawn(move || { + let session = (|| { + let mut accounts = Accounts::load(); + let Some((a, secrets)) = account::session_for_launch( + &account::Endpoints::live(), + account::store(), + &mut accounts, + )? + else { + return Ok(None); + }; + account::write_session_file(&backend::game_home().join("sessions"), &a, &secrets) + .map(Some) + })(); + let _ = tx.send(Msg::Session(session)); + }); + } + fn choose_folder(&mut self, server: bool, cx: &mut Context) { let paths = cx.prompt_for_paths(PathPromptOptions { files: false, @@ -2774,6 +2814,7 @@ impl Render for Launcher { let content = match self.page { Page::Play => self.play_page(cx), Page::Versions => self.versions_page(cx), + Page::Modpacks => self.modpacks_page(cx), Page::Notes => self.notes_page(cx), Page::Settings => self.settings_page(cx), }; diff --git a/launcher/src/modpacks.rs b/launcher/src/modpacks.rs new file mode 100644 index 000000000..6d4553a14 --- /dev/null +++ b/launcher/src/modpacks.rs @@ -0,0 +1,249 @@ +//! Modpacks: import a Java modpack (a Modrinth `.mrpack`, a CurseForge zip, an instance folder), +//! show what Horizon runs of it, port that on this computer from the player's own downloads, and +//! play it as a profile of its own (docs/modpacks.md). +//! +//! Each pack lives in `ports//` in the game's home: the work folder `horizon-port-pack` +//! writes (pack.json, inventory, the jars, the carried-over mods, the coverage report) and +//! `home/`, the profile's own saves and options. Nothing is uploaded or shared: mod jars are +//! often All Rights Reserved, so the ports stay on the player's machine. +use crate::backend; +use horizon_port_pack::{ + fetch::{Fetched, How}, + import::Pack, + pipeline::{self, Log}, + report::{Row, Status}, +}; +use std::fs; +use std::path::{Path, PathBuf}; +use std::process::Command; + +/// Where imported packs live. +pub fn ports_dir() -> PathBuf { + backend::game_home().join("ports") +} + +/// A pack's folder name: its name in lowercase words joined by dashes. +pub fn slug(name: &str) -> String { + let words: Vec = name + .split(|c: char| !c.is_ascii_alphanumeric()) + .filter(|w| !w.is_empty()) + .map(str::to_ascii_lowercase) + .collect(); + if words.is_empty() { + "pack".into() + } else { + words.join("-") + } +} + +/// An imported pack, as its work folder has it. +pub struct Imported { + pub slug: String, + pub work: PathBuf, + pub pack: Pack, + pub rows: Vec, + pub fetched: Fetched, + /// The carried-over mods the profile loads. + pub mods: Vec, + /// The mods the port step gets and carries over (content, data tier). + pub portable: usize, +} + +impl Imported { + pub fn title(&self) -> &str { + if self.pack.name.is_empty() { + &self.slug + } else { + &self.pack.name + } + } + pub fn count(&self, status: Status) -> usize { + self.rows.iter().filter(|r| r.status == status).count() + } + /// "Minecraft 1.21.1 · neoforge 21.1.259 · 496 mods". + pub fn summary(&self) -> String { + let mut parts = Vec::new(); + if !self.pack.minecraft.is_empty() { + parts.push(format!("Minecraft {}", self.pack.minecraft)); + } + if !self.pack.loader.is_empty() { + parts.push(format!("{} {}", self.pack.loader, self.pack.loader_version)); + } + parts.push(format!("{} files", self.pack.files.len())); + parts.join(" · ") + } + /// What getting the jars did, in one line, or None before it ran. + pub fn jars(&self) -> Option { + if self.fetched.files.is_empty() { + return None; + } + let mut parts = Vec::new(); + for (how, what) in [ + (How::Downloaded, "downloaded"), + (How::Local, "copied from your folder"), + (How::Present, "already here"), + ( + How::NeedsKey, + "only on CurseForge (needs its API key: choose your installed instance instead)", + ), + (How::NotFound, "not found"), + (How::Failed, "failed"), + ] { + let n = self.fetched.count(how); + if n > 0 { + parts.push(format!("{n} {what}")); + } + } + Some(format!("Jars: {}.", parts.join(", "))) + } +} + +/// Reads the pack in `work`. +pub fn load(work: &Path) -> Result { + let pack: Pack = pipeline::read_json(&work.join("pack.json"))?; + let rows: Vec = pipeline::read_json(&work.join("coverage.json")).unwrap_or_default(); + let records: Vec = + pipeline::read_json(&work.join("inventory.json")).unwrap_or_default(); + Ok(Imported { + slug: work + .file_name() + .map(|n| n.to_string_lossy().into_owned()) + .unwrap_or_default(), + work: work.to_path_buf(), + pack, + rows, + fetched: Fetched::load(work), + mods: carried(work), + portable: records.iter().filter(|r| pipeline::portable(r)).count(), + }) +} + +/// Every imported pack, by name. +pub fn list() -> Vec { + let mut packs: Vec = fs::read_dir(ports_dir()) + .into_iter() + .flatten() + .flatten() + .filter_map(|e| load(&e.path()).ok()) + .collect(); + packs.sort_by_key(|p| p.title().to_ascii_lowercase()); + packs +} + +/// The carried-over mods in a work folder (`mods//carry/` with its manifest). +pub fn carried(work: &Path) -> Vec { + let mut mods: Vec = fs::read_dir(work.join("mods")) + .into_iter() + .flatten() + .flatten() + .map(|e| e.path().join("carry")) + .filter(|c| c.join("horizon-mod.toml").is_file()) + .collect(); + mods.sort(); + mods +} + +/// Imports the pack at `path` into `ports//` and writes its coverage report from +/// metadata (Modrinth answers by file hash; nothing is downloaded yet). Importing the same pack +/// again keeps the jars and ports it already has. +pub fn import(path: &Path, log: Log) -> Result { + let pack = horizon_port_pack::import::import(path)?; + let name = if pack.name.is_empty() || pack.name == "modlist" { + path.file_stem() + .map(|s| s.to_string_lossy().into_owned()) + .unwrap_or_default() + } else { + pack.name.clone() + }; + let work = ports_dir().join(slug(&name)); + log(format!("Importing {name} into {}", work.display())); + pipeline::import(path, &work, log)?; + pipeline::inventory(&work, false, log)?; + pipeline::report(&work, log)?; + load(&work) +} + +/// Ports what this computer can: the portable mods' jars (from `from` when the player has them, +/// else the pack's links or Modrinth), carried over for `resources`, then the report again. +pub fn port( + work: &Path, + resources: Option<&Path>, + from: Option<&Path>, + log: Log, +) -> Result { + pipeline::port(work, resources, from, log)?; + load(work) +} + +/// Removes an imported pack: its jars, ports and the profile's saves. +pub fn remove(work: &Path) -> Result<(), String> { + if work.parent() != Some(ports_dir().as_path()) { + return Err(format!("{} is not an imported pack", work.display())); + } + fs::remove_dir_all(work).map_err(|e| format!("{}: {e}", work.display())) +} + +/// The profile's own game home: saves, options.txt, logs. +pub fn profile_home(work: &Path) -> PathBuf { + work.join("home") +} + +/// Turns the game's command into this pack's profile: its own home (the player's options.txt +/// copied in the first time, so keys and video settings carry over) and its carried-over mods. +pub fn apply_profile(cmd: &mut Command, work: &Path) -> Result<(), String> { + let mods = carried(work); + if mods.is_empty() { + return Err("Nothing is ported yet: port the pack first.".into()); + } + let home = profile_home(work); + fs::create_dir_all(&home).map_err(|e| format!("{}: {e}", home.display()))?; + let options = home.join("options.txt"); + let own = backend::game_home().join("options.txt"); + if !options.exists() && own.is_file() { + let _ = fs::copy(own, &options); + } + cmd.current_dir(&home).env("HORIZON_HOME", &home); + for m in mods { + cmd.arg("--dev-mod").arg(m); + } + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn slugs() { + assert_eq!(slug("All the Mods 10"), "all-the-mods-10"); + assert_eq!(slug("Create: Above & Beyond!"), "create-above-beyond"); + assert_eq!(slug(" "), "pack"); + } + + #[test] + fn a_profile_has_its_own_home_and_mods() { + let root = + std::env::temp_dir().join(format!("horizon-launcher-pack-{}", std::process::id())); + let _ = fs::remove_dir_all(&root); + let work = root.join("ports/small"); + let mut cmd = Command::new("true"); + assert!(apply_profile(&mut cmd, &work).is_err()); + for id in ["a", "b"] { + let carry = work.join("mods").join(id).join("carry"); + fs::create_dir_all(&carry).unwrap(); + fs::write(carry.join("horizon-mod.toml"), "").unwrap(); + } + // Left out: no manifest. + fs::create_dir_all(work.join("mods/c/carry")).unwrap(); + apply_profile(&mut cmd, &work).unwrap(); + let args: Vec = cmd + .get_args() + .map(|a| a.to_string_lossy().into_owned()) + .collect(); + assert_eq!(args.len(), 4); + assert!(args[1].ends_with("a/carry") && args[3].ends_with("b/carry")); + assert_eq!(cmd.get_current_dir(), Some(profile_home(&work).as_path())); + assert!(profile_home(&work).is_dir()); + fs::remove_dir_all(&root).unwrap(); + } +} diff --git a/launcher/src/modpacks_page.rs b/launcher/src/modpacks_page.rs new file mode 100644 index 000000000..2398421c6 --- /dev/null +++ b/launcher/src/modpacks_page.rs @@ -0,0 +1,412 @@ +//! The Modpacks page: import a pack, read its coverage report, port what this computer can and +//! play it as its own profile (`horizon_launcher::modpacks`). +use super::*; +use horizon_launcher::modpacks::{self, Imported}; +use horizon_port_pack::report::Status; +use std::path::PathBuf; + +/// The report's filter: every row, or one status. +pub(super) const FILTERS: [(Option, &str); 5] = [ + (None, "All"), + (Some(Status::Ported), "Ported"), + (Some(Status::Partial), "Partial"), + (Some(Status::NotYet), "Not yet"), + (Some(Status::NotNeeded), "Not needed"), +]; + +/// Lines of the pipeline's log the page shows while it works. +const LOG_SHOWN: usize = 6; + +impl Launcher { + fn open_pack(&self) -> Option<&Imported> { + let slug = self.pack_open.as_ref()?; + self.packs.iter().find(|p| &p.slug == slug) + } + + /// Runs a pipeline step on a thread; its lines and its end arrive as messages. + fn pack_job( + &mut self, + job: impl FnOnce(&dyn Fn(String)) -> Result + Send + 'static, + ) { + if self.pack_busy { + return; + } + self.pack_busy = true; + self.pack_log.clear(); + self.pack_error = None; + let tx = self.tx.clone(); + std::thread::spawn(move || { + let lines = tx.clone(); + let log = move |line: String| { + let _ = lines.send(Msg::PackLine(line)); + }; + let result = job(&log); + let _ = tx.send(Msg::PackDone(result.map(Box::new))); + }); + } + + /// A finished step: the pack's new state, opened. + pub(super) fn pack_done(&mut self, result: Result, String>) { + self.pack_busy = false; + match result { + Ok(pack) => { + self.pack_open = Some(pack.slug.clone()); + self.packs.retain(|p| p.slug != pack.slug); + self.packs.push(*pack); + self.packs.sort_by_key(|p| p.title().to_ascii_lowercase()); + } + Err(e) => self.pack_error = Some(e), + } + } + + fn choose_pack(&mut self, folder: bool, cx: &mut Context) { + let paths = cx.prompt_for_paths(PathPromptOptions { + files: !folder, + directories: folder, + multiple: false, + prompt: Some("Import".into()), + }); + cx.spawn(async move |this, cx| { + if let Ok(Ok(Some(mut paths))) = paths.await { + if let Some(path) = paths.pop() { + let _ = this.update(cx, |this, cx| { + this.pack_job(move |log| modpacks::import(&path, log)); + cx.notify(); + }); + } + } + }) + .detach(); + } + + /// Ports the open pack; `from` is a folder of the player's jars, chosen when `ask`. + fn port_pack(&mut self, ask: bool, cx: &mut Context) { + let Some(work) = self.open_pack().map(|p| p.work.clone()) else { + return; + }; + let resources = self + .selected() + .filter(|tag| backend::is_prepared(tag)) + .map(|tag| backend::resources(tag)); + if !ask { + self.pack_job(move |log| modpacks::port(&work, resources.as_deref(), None, log)); + return; + } + let paths = cx.prompt_for_paths(PathPromptOptions { + files: false, + directories: true, + multiple: false, + prompt: Some("Use these jars".into()), + }); + cx.spawn(async move |this, cx| { + if let Ok(Ok(Some(mut paths))) = paths.await { + if let Some(from) = paths.pop() { + let _ = this.update(cx, |this, cx| { + this.pack_job(move |log| { + modpacks::port(&work, resources.as_deref(), Some(&from), log) + }); + cx.notify(); + }); + } + } + }) + .detach(); + } + + fn play_pack(&mut self, work: PathBuf) { + let Some(tag) = self.selected().cloned() else { + return; + }; + if self.client.is_some() || self.starting_client.is_some() { + return; + } + self.starting_pack = Some(work); + self.start_client(tag); + } + + pub(super) fn modpacks_page(&mut self, cx: &mut Context) -> Div { + let t = self.theme; + if self.packs_loaded.is_none() { + self.packs = modpacks::list(); + if self.pack_open.is_none() { + self.pack_open = self.packs.first().map(|p| p.slug.clone()); + } + self.packs_loaded = Some(Instant::now()); + } + let header = page_header( + "Modpacks", + "Bring a Java modpack: see what Horizon runs of it, port that on this computer from \ + your own downloads, and play it as its own profile. Nothing is uploaded or shared.", + &t, + ); + let busy = self.pack_busy; + let pick = |id: &'static str, label: &'static str, folder: bool| { + let b = button(id, label, Kind::Secondary, &t); + if busy { + disabled(b) + } else { + b.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.choose_pack(folder, cx); + cx.notify(); + })) + } + }; + let actions = div() + .flex() + .flex_wrap() + .items_center() + .gap(px(8.)) + .child(pick("import-file", "Import a pack file…", false)) + .child(pick("import-folder", "Import an instance folder…", true)) + .child(text(theme::CAPTION).text_color(t.muted).child( + ".mrpack (Modrinth), .zip (CurseForge), or a Prism, MultiMC or CurseForge instance", + )); + let mut page = div() + .flex() + .flex_col() + .gap(px(32.)) + .child(header) + .child(actions); + if busy || !self.pack_log.is_empty() { + page = page.child(self.pack_log_plate(&t)); + } + if let Some(e) = &self.pack_error { + page = page.child(notice(e.clone(), &t)); + } + if self.packs.is_empty() { + return page.child(centered( + "No modpack yet. Import one to see what Horizon can run of it.", + &t, + )); + } + if self.packs.len() > 1 { + let mut list = div().flex().flex_col().border_t_1().border_color(t.rule); + for (i, p) in self.packs.iter().enumerate() { + let open = self.pack_open.as_ref() == Some(&p.slug); + let slug = p.slug.clone(); + let right = if open { + caps("Open").text_color(t.accent).into_any_element() + } else { + button(format!("open-{slug}"), "Open", Kind::Ghost, &t) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.pack_open = Some(slug.clone()); + cx.notify(); + })) + .into_any_element() + }; + list = list.child(index_row( + i + 1, + p.title().to_string(), + Some(p.summary().into_any_element()), + Some(right), + &t, + )); + } + page = page.child(list); + } + match self.pack_detail(cx) { + Some(detail) => page.child(detail), + None => page, + } + } + + fn pack_log_plate(&self, t: &Theme) -> Div { + let start = self.pack_log.len().saturating_sub(LOG_SHOWN); + plate(t) + .flex() + .flex_col() + .gap(px(4.)) + .p(px(16.)) + .child( + caps(if self.pack_busy { "Working" } else { "Done" }) + .text_color(if self.pack_busy { t.accent } else { t.muted }), + ) + .children(self.pack_log.iter().skip(start).map(|line| { + text(theme::CAPTION) + .font_family(theme::MONO) + .text_color(t.ink_soft) + .truncate() + .child(line.clone()) + })) + } + + fn pack_detail(&self, cx: &mut Context) -> Option

{ + let t = self.theme; + let p = self.open_pack()?; + let mut counts = div().flex().gap(px(12.)); + for (status, label) in FILTERS.iter().skip(1) { + let status = status.expect("the first filter is All"); + let color = match status { + Status::Ported => t.success, + Status::Partial => t.accent, + _ => t.ink, + }; + counts = counts.child( + plate(&t) + .flex() + .flex_col() + .flex_1() + .gap(px(4.)) + .p(px(16.)) + .child( + text(theme::DISPLAY) + .text_color(color) + .child(p.count(status).to_string()), + ) + .child(caps(*label).text_color(t.muted)), + ); + } + let can_play = self.selected().is_some_and(|tag| backend::is_prepared(tag)); + let running = self.client.is_some() || self.starting_client.is_some(); + let mut buttons = div().flex().flex_wrap().items_center().gap(px(8.)); + let play_label = if p.mods.is_empty() { + "Play".to_string() + } else { + format!("Play with {} mods", p.mods.len()) + }; + let mut play = button("pack-play", play_label, Kind::Primary, &t); + if p.mods.is_empty() || !can_play || running || self.pack_busy { + play = disabled(play); + } else { + let work = p.work.clone(); + play = play.on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.play_pack(work.clone()); + cx.notify(); + })); + } + let port_label = format!("Port {} mods", p.portable); + let mut port = button("pack-port", port_label, Kind::Secondary, &t); + let mut from = button("pack-from", "Use jars from my instance…", Kind::Ghost, &t); + if self.pack_busy || p.portable == 0 { + port = disabled(port); + from = disabled(from); + } else { + port = port.on_click(cx.listener(|this, _: &ClickEvent, _, cx| { + this.port_pack(false, cx); + cx.notify(); + })); + from = from.on_click(cx.listener(|this, _: &ClickEvent, _, cx| { + this.port_pack(true, cx); + cx.notify(); + })); + } + let confirming = self.confirm_remove.as_deref() == Some(p.slug.as_str()); + let slug = p.slug.clone(); + let work = p.work.clone(); + let remove = button( + "pack-remove", + if confirming { + "Remove for good" + } else { + "Remove" + }, + if confirming { + Kind::Secondary + } else { + Kind::Ghost + }, + &t, + ) + .when(confirming, |b| b.text_color(t.danger)) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + if this.confirm_remove.as_ref() == Some(&slug) { + match modpacks::remove(&work) { + Ok(()) => { + this.packs.retain(|p| p.slug != slug); + this.pack_open = this.packs.first().map(|p| p.slug.clone()); + } + Err(e) => this.pack_error = Some(e), + } + this.confirm_remove = None; + } else { + this.confirm_remove = Some(slug.clone()); + } + cx.notify(); + })); + buttons = buttons.child(play).child(port).child(from).child(remove); + let mut notes = vec![format!( + "Port gets the jars of the {} mods this computer can port today (content with data \ + and assets only) from the pack's own links, Modrinth, or your folder, and carries \ + them over. The ports stay here, in {}.", + p.portable, + short(&p.work) + )]; + if let Some(jars) = p.jars() { + notes.push(jars); + } + if !can_play { + notes.push("Playing needs a prepared Horizon version (Play page).".into()); + } + let mut rows: Vec<&horizon_port_pack::report::Row> = p + .rows + .iter() + .filter(|r| self.pack_filter.is_none_or(|s| r.status == s)) + .collect(); + rows.sort_by(|a, b| (a.status, &a.key).cmp(&(b.status, &b.key))); + let filter = segments("pack-filter", &FILTERS, self.pack_filter, &t, { + let this = cx.entity().downgrade(); + move |value, _, cx| { + let _ = this.update(cx, |this, cx| { + this.pack_filter = value; + cx.notify(); + }); + } + }); + let mut list = div().flex().flex_col().border_t_1().border_color(t.rule); + for (i, r) in rows.iter().enumerate() { + let color = match r.status { + Status::Ported => t.success, + Status::Partial => t.accent, + Status::NotYet => t.ink_soft, + Status::NotNeeded => t.muted, + }; + let name = if r.name.is_empty() || r.name == r.key { + r.key.clone() + } else { + format!("{} ({})", r.name, r.key) + }; + let detail = format!("{} · {} · {}: {}", r.class, r.tier, r.license, r.reason); + list = list.child(index_row( + i + 1, + name, + Some(detail.into_any_element()), + Some( + caps(r.status.label()) + .flex_none() + .text_color(color) + .into_any_element(), + ), + &t, + )); + } + Some( + div() + .flex() + .flex_col() + .gap(px(24.)) + .child( + div() + .flex() + .flex_col() + .gap(px(4.)) + .child( + text(theme::TITLE) + .text_color(t.ink) + .child(p.title().to_string()), + ) + .child(text(theme::UI).text_color(t.muted).child(p.summary())), + ) + .child(counts) + .child(buttons) + .children(self.client_error.clone().map(|e| notice(e, &t))) + .children(notes.into_iter().map(|n| { + text(theme::CAPTION) + .max_w(px(720.)) + .text_color(t.muted) + .child(n) + })) + .child(div().flex().child(filter)) + .child(list), + ) + } +} From edffb857e116389b399822def3a768d997b15221 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 07:56:06 +0200 Subject: [PATCH 18/46] LAN chunks: compute a column's light once, and keep sections' light layers encode_in built the light layers twice (encode filled them for every section, then encode_in replaced them with the ones that exist around the column). On the ThinkPad at 25 walking bots light_data was 8 % of the server thread. The light is now built once, and a section's packed DataLayers stay in the section cache while the section is unchanged (relighting moves it to a new address, as an edit does). Uniform light is filled directly, not kept. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/chunks.rs | 148 ++++++++++++++++++------ 1 file changed, 115 insertions(+), 33 deletions(-) diff --git a/crates/horizon-client/src/lan/chunks.rs b/crates/horizon-client/src/lan/chunks.rs index 71e0c889b..32d38efe9 100644 --- a/crates/horizon-client/src/lan/chunks.rs +++ b/crates/horizon-client/src/lan/chunks.rs @@ -112,6 +112,47 @@ struct Encoded { non_air: bool, /// LevelChunkSection.write, and whether it holds block entity blocks. wire: Option<(Arc<[u8]>, bool)>, + /// The section's light as the wire's two DataLayers, when not uniform. + light: Option>, +} + +/// One section's light as DataLayers (two blocks per byte, the even one in +/// the low nibble), and whether each holds any light. +struct Layers { + sky: Vec, + block: Vec, + sky_any: bool, + block_any: bool, +} +impl Layers { + fn of(light: &Light) -> Self { + let (mut sky, mut block) = (vec![0u8; 2048], vec![0u8; 2048]); + let (sky_any, block_any) = match light { + Light::Uniform(v) => { + let (sk, bl) = (v >> 4, v & 15); + sky.fill(sk | sk << 4); + block.fill(bl | bl << 4); + (sk != 0, bl != 0) + } + Light::Full(a) => { + for ((pair, sky), block) in + a.as_chunks::<2>().0.iter().zip(&mut sky).zip(&mut block) + { + let [even, odd] = *pair; + *sky = even >> 4 | (odd & 0xF0); + *block = (even & 15) | odd << 4; + } + let all = a.iter().fold(0u8, |acc, &v| acc | v); + (all & 0xF0 != 0, all & 15 != 0) + } + }; + Self { + sky, + block, + sky_any, + block_any, + } + } } /// Sections kept before the ones no longer resident are dropped. @@ -221,6 +262,7 @@ impl ChunkEncoder { section: Arc::downgrade(section), non_air: self.non_air(section), wire: None, + light: None, }); read(entry) } @@ -338,8 +380,8 @@ impl ChunkEncoder { } } } - let mut packet = self.encode(chunk, &world.block_entities); - packet.light = light_data(chunk, around); + let mut packet = self.encode_blocks(chunk, &world.block_entities); + packet.light = self.light_data(chunk, around); packet } @@ -347,6 +389,17 @@ impl ChunkEncoder { &self, chunk: &Chunk, block_entities: &HashMap<(i32, i32, i32), BlockEntity>, + ) -> LevelChunkWithLight { + let mut packet = self.encode_blocks(chunk, block_entities); + packet.light = self.light_data(chunk, u64::MAX); + packet + } + + /// The packet without its light. + fn encode_blocks( + &self, + chunk: &Chunk, + block_entities: &HashMap<(i32, i32, i32), BlockEntity>, ) -> LevelChunkWithLight { let mut buffer = Vec::new(); let mut entity_infos = Vec::new(); @@ -412,9 +465,34 @@ impl ChunkEncoder { buffer, block_entities: entity_infos, }, - light: light_data(chunk, u64::MAX), + light: LightData { + sky_mask: Vec::new(), + block_mask: Vec::new(), + empty_sky_mask: Vec::new(), + empty_block_mask: Vec::new(), + sky: Vec::new(), + block: Vec::new(), + }, } } + + /// ClientboundLightUpdatePacketData: the light layers of the sections + /// that exist around the column (`around`: the non-air sections of it + /// and its neighbours, as bits). A resident section's layers come from + /// the cache while it is unchanged (uniform light is quicker to fill than + /// to keep). + fn light_data(&self, chunk: &Chunk, around: u64) -> LightData { + light_data_with(chunk, around, |s| { + if matches!(s.light, Light::Uniform(_)) { + return Arc::new(Layers::of(&s.light)); + } + self.cached(s, |e| e.light.clone()).unwrap_or_else(|| { + let layers = Arc::new(Layers::of(&s.light)); + self.cached(s, |e| e.light = Some(layers.clone())); + layers + }) + }) + } } /// The order LevelChunk.getBlockEntities() iterates in: a fastutil @@ -487,7 +565,17 @@ pub fn entity_tag(entity: &BlockEntity) -> Option { /// non-air section of this column or a neighbouring one (`around`, bit i for /// section i; LayerLightSectionStorage.updateSectionStatus). An existing /// layer is sent, or marked empty when all dark; the others are left out. +#[cfg(test)] fn light_data(chunk: &Chunk, around: u64) -> LightData { + light_data_with(chunk, around, |s| Arc::new(Layers::of(&s.light))) +} + +/// The light layers, `section` giving a resident section's. +fn light_data_with( + chunk: &Chunk, + around: u64, + section: impl Fn(&Arc
) -> Arc, +) -> LightData { let mut data = LightData { sky_mask: Vec::new(), block_mask: Vec::new(), @@ -500,47 +588,25 @@ fn light_data(chunk: &Chunk, around: u64) -> LightData { let exists = |b: usize| { (b.saturating_sub(2)..=b.min(SECTIONS - 1)).any(|s| s + 2 >= b && around >> s & 1 != 0) }; - let full_sky = Light::Uniform(0xF0); for b in 0..SECTIONS + 2 { if !exists(b) { continue; } - let light = match b { + let layers = match b { // Below the world nothing is lit; above it the sky is full. - 0 => &Light::Uniform(0), - _ if b == SECTIONS + 1 => &full_sky, - _ => &chunk.sections[b - 1].light, + 0 => Arc::new(Layers::of(&Light::Uniform(0))), + _ if b == SECTIONS + 1 => Arc::new(Layers::of(&Light::Uniform(0xF0))), + _ => section(&chunk.sections[b - 1]), }; - let (mut sky, mut block) = (vec![0u8; 2048], vec![0u8; 2048]); - let (sky_any, block_any) = match light { - Light::Uniform(v) => { - let (sk, bl) = (v >> 4, v & 15); - sky.fill(sk | sk << 4); - block.fill(bl | bl << 4); - (sk != 0, bl != 0) - } - Light::Full(a) => { - // Two blocks per byte, the even one in the low nibble. - for ((pair, sky), block) in - a.as_chunks::<2>().0.iter().zip(&mut sky).zip(&mut block) - { - let [even, odd] = *pair; - *sky = even >> 4 | (odd & 0xF0); - *block = (even & 15) | odd << 4; - } - let all = a.iter().fold(0u8, |acc, &v| acc | v); - (all & 0xF0 != 0, all & 15 != 0) - } - }; - if sky_any { + if layers.sky_any { set_bit(&mut data.sky_mask, b); - data.sky.push(sky); + data.sky.push(layers.sky.clone()); } else { set_bit(&mut data.empty_sky_mask, b); } - if block_any { + if layers.block_any { set_bit(&mut data.block_mask, b); - data.block.push(block); + data.block.push(layers.block.clone()); } else { set_bit(&mut data.empty_block_mask, b); } @@ -629,6 +695,22 @@ mod tests { } } + #[test] + fn cached_light_follows_edits() { + let encoder = encoder(); + let mut chunk = Chunk::empty(0, 0); + let mut light = Box::new([0x5Au8; 4096]); + Arc::make_mut(&mut chunk.sections[2]).light = Light::Full(light.clone()); + let first = encoder.encode(&chunk, &HashMap::new()).light; + assert_eq!(first, light_data(&chunk, u64::MAX)); + // Relighting moves the section, so the cached layers aren't reused. + light[7] = 0xF3; + Arc::make_mut(&mut chunk.sections[2]).light = Light::Full(light); + let second = encoder.encode(&chunk, &HashMap::new()).light; + assert_ne!(first, second); + assert_eq!(second, light_data(&chunk, u64::MAX)); + } + #[test] fn light_masks_cover_the_world_plus_borders() { let chunk = Chunk::empty(0, 0); From 6b0b34098eaa855e3526a87192031f662479689a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 08:09:50 +0200 Subject: [PATCH 19/46] Benchmark: Horizon's server against vanilla 26.3 on equal work Walk and explore passes at 1 to 100 bots on the ThinkPad (bots on the Mac mini), vanilla with the locator bar off, plus an explore pass at a rate both servers keep up with. The README has the method, the tables, the profile of what remains at 25 walking bots and the earlier runs; docs/server.md section 9 and the Scale row summarise it. Co-Authored-By: Claude Opus 5.5 --- .../server-equal-work-2026-10-17/README.md | 168 +++++ .../explore-equal-rate.json | 267 +++++++ .../server-equal-work-2026-10-17/horizon.json | 415 +++++++++++ .../run-1-before-chunk-cache.json | 693 ++++++++++++++++++ .../run-2-chunk-cache.json | 413 +++++++++++ .../server-equal-work-2026-10-17/vanilla.json | 324 ++++++++ docs/server.md | 20 +- 7 files changed, 2297 insertions(+), 3 deletions(-) create mode 100644 benchmarks/server-equal-work-2026-10-17/README.md create mode 100644 benchmarks/server-equal-work-2026-10-17/explore-equal-rate.json create mode 100644 benchmarks/server-equal-work-2026-10-17/horizon.json create mode 100644 benchmarks/server-equal-work-2026-10-17/run-1-before-chunk-cache.json create mode 100644 benchmarks/server-equal-work-2026-10-17/run-2-chunk-cache.json create mode 100644 benchmarks/server-equal-work-2026-10-17/vanilla.json diff --git a/benchmarks/server-equal-work-2026-10-17/README.md b/benchmarks/server-equal-work-2026-10-17/README.md new file mode 100644 index 000000000..737b05858 --- /dev/null +++ b/benchmarks/server-equal-work-2026-10-17/README.md @@ -0,0 +1,168 @@ +# Horizon's server against vanilla 26.3, equal work (2026-10-17) + +The same bots on Horizon's dedicated server and on vanilla 26.3's, one server at a time, on the same +machine, with the work each server does made the same before the numbers are compared. This replaces the +first run in docs/server.md section 9, where the work wasn't equal. + +## What was made equal + +The first run (PR #556) had three differences that made the comparison unfair. Each is fixed in the code +that ran here: + +- **Refused moves.** Vanilla pulls a player back when a move is too fast ("moved too quickly") or ends + inside a block ("moved wrongly"). Horizon now runs both checks the way vanilla does (PR #586), so a bot + that flies too fast is pulled back on both servers. +- **Chunk sending.** Vanilla paces chunks by the client's acknowledgements (PlayerChunkSender: one + unacknowledged batch at first, then ten, each at most the client's desired chunks per tick). Horizon used + to send twice as many per batch; it now paces them the same way (PR #586), and the bots acknowledge + batches and ask for a rate the way vanilla's client does, so both servers send at the pace the client + asks for. Chunks sent again while the bot still held + them (`resent`) are counted: 0 on both servers in every run. +- **Movement gated on chunks.** A bot doesn't move while the chunk it stands in hasn't arrived (vanilla's + client waits the same way), so a slower server isn't asked to teleport bots into terrain it hasn't sent. + +One difference isn't in Horizon yet: vanilla 26.3's locator bar (waypoints), which costs vanilla O(players²) +work per move. Every vanilla run here sets `gamerule locator_bar false`, so neither server does it. + +## Method + +`tools/server_bench.py` runs each configuration on a fresh server: + +- the same `server.properties` on both (seed 12345, view and simulation distance 10, offline, creative, + difficulty easy, `sync-chunk-writes=true`), and `gamerule respawn_radius 0`; +- the server waits for `Done`, the bots join one a second, a 60-second warm-up, then 300 seconds of + measurement; +- MSPT (average, P50, P95, P99) comes from each server's own `/tick query`, asked every 5 seconds on the + console, so both measure themselves the same way (vanilla's ServerTickRateManager numbers, which Horizon + reproduces); TPS is 20 while the average fits in 50 ms, else 1000 / MSPT; +- RSS and CPU are the server's whole process tree, once a second (100 % is one core); +- chunk counts come from the bots: chunks received per second, chunks no bot had before (new terrain), and + pull-backs (position packets that move a bot back). + +The bots are `horizon-bots` (creative, flying 24 blocks above spawn, 20 moves a second): + +- `walk`: flies to random points within 48 blocks of spawn at sprint speed (5.6 blocks a second); +- `explore`: flies straight outwards, by default at about 22 blocks a second, as fast as the server sends + chunks. + +Machine: the ThinkPad (Intel Core i7-7500U, 2 cores / 4 threads, 32 GB, NixOS), servers under `nice -n 19` +because it also runs other services; vanilla on OpenJDK 25.0.4.1 with a 4 GB heap (`-Xms4g -Xmx4g`). The +bots ran on the Mac mini and reached the ThinkPad over the tailnet, so they took none of the server's CPU. + +What ran: Horizon from `origin/main` at bf851bfe with #586 (move checks and chunk pacing), the bots and +`server_bench.py` from this PR, #623 (sections encoded once, its first commit) and #649 (a tick's packets +handed to each connection together). The ThinkPad copy wasn't a git checkout, so the JSON reports have an +empty `commit`. Vanilla: the pinned 26.3 server jar. + +## Results + +MSPT is the average milliseconds per tick (50 is the limit for 20 TPS); P95 is the 95th percentile. CPU is +the whole process tree. "New chunks/s" are chunks no bot had before. + +### Walk (the same work on both servers) + +| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s | +|---:|---|---:|---:|---:|---:|---:|---:|---:| +| 1 | Horizon | 5.5 | 12.1 | 20.0 | 1.37 GB | 57 % | 9 | 0.3 | +| 1 | Vanilla | 18.3 | 27.3 | 20.0 | 3.35 GB | 66 % | 10 | 0.3 | +| 10 | Horizon | 11.5 | 22.1 | 20.0 | 1.41 GB | 124 % | 94 | 2.4 | +| 10 | Vanilla | 16.8 | 30.5 | 20.0 | 3.41 GB | 84 % | 100 | 2.8 | +| 25 | Horizon | 20.7 | 40.4 | 20.0 | 1.45 GB | 170 % | 236 | 5.7 | +| 25 | Vanilla | 16.0 | 26.4 | 20.0 | 3.47 GB | 115 % | 252 | 6.7 | +| 50 | Horizon | 31.4 | 79.0 | 20.0 | 1.52 GB | 173 % | 451 | 10.3 | +| 50 | Vanilla | 20.5 | 29.7 | 20.0 | 3.55 GB | 194 % | 502 | 12.2 | +| 100 | Horizon | 114.5 | 256.2 | 8.7 | 1.33 GB | 181 % | 484 | 30.8 | +| 100 | Vanilla | stopped by its watchdog | | | | | | | + +Both servers sent the same chunks (about 10 a second per bot, the churn of flying around) and sent none +twice. Vanilla pulled back a few bots for moving too quickly when a tick ran long (5 to 33 per run); +Horizon none. At 100 bots vanilla's watchdog stopped the server (a tick ran over 60 s, in +`ChunkMap$TrackedEntity.updatePlayer`); Horizon kept running at 8.7 TPS. + +### Explore at a rate both servers keep up with (equal work) + +The bots fly outwards at 0.8 blocks a second (`--explore-speed 0.8`), slow enough that neither server makes +them wait for terrain, so both generate and send the same new chunks. + +| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s | +|---:|---|---:|---:|---:|---:|---:|---:|---:| +| 1 | Horizon | 4.0 | 6.6 | 20.0 | 1.36 GB | 25 % | 2 | 1.3 | +| 1 | Vanilla | 18.1 | 27.1 | 20.0 | 3.32 GB | 73 % | 2 | 1.4 | +| 10 | Horizon | 13.5 | 24.8 | 20.0 | 1.64 GB | 89 % | 13 | 11.8 | +| 10 | Vanilla | 29.2 | 43.0 | 20.0 | 3.52 GB | 143 % | 13 | 11.9 | +| 25 | Horizon | 20.2 | 36.8 | 20.0 | 1.74 GB | 121 % | 32 | 28.9 | +| 25 | Vanilla | 37.0 | 49.4 | 20.0 | 3.73 GB | 169 % | 32 | 28.9 | + +### Explore as fast as each server sends chunks (not equal work) + +The default 22 blocks a second is faster than either server can generate, so each server sets the pace and +a faster server is given more work: from 10 bots Horizon generated 1.5 to 2 times vanilla's new chunks a +second. Read it as throughput, not as a like-for-like tick time. + +| Bots | Server | MSPT | P95 | TPS | RSS | CPU | Chunks/s | New chunks/s | +|---:|---|---:|---:|---:|---:|---:|---:|---:| +| 1 | Horizon | 10.6 | 24.6 | 20.0 | 1.34 GB | 322 % | 39 | 34.6 | +| 1 | Vanilla | 9.9 | 21.3 | 20.0 | 3.48 GB | 245 % | 36 | 33.4 | +| 10 | Horizon | 30.4 | 52.3 | 20.0 | 2.18 GB | 345 % | 47 | 46.7 | +| 10 | Vanilla | 17.0 | 29.6 | 20.0 | 4.04 GB | 242 % | 22 | 22.4 | +| 25 | Horizon | 50.7 | 89.3 | 19.7 | 2.30 GB | 286 % | 50 | 49.7 | +| 25 | Vanilla | 24.2 | 36.5 | 20.0 | 4.40 GB | 320 % | 34 | 33.7 | +| 50 | Horizon | 50.7 | 102.7 | 19.7 | 1.72 GB | 213 % | 97 | 96.5 | +| 50 | Vanilla | stopped by its watchdog | | | | | | | +| 100 | Horizon | 92.9 | 139.6 | 10.8 | 1.70 GB | 322 % | 114 | 113.6 | +| 100 | Vanilla | stopped by its watchdog | | | | | | | + +Vanilla's watchdog stopped it at 50 bots (in `ClientboundLightUpdatePacketData`, copying light for a chunk +packet) and at 100 (in `Entity.move` from a move packet). + +## Findings + +- Horizon's RSS is 1.9 to 2.6 times smaller in every run, and it starts in 11 s against vanilla's 15 s. + Vanilla's heap is fixed at 4 GB (`-Xms4g`), so part of its RSS is that setting rather than need. +- With 1 bot Horizon's tick is 3.3 times shorter walking and 4.5 times shorter exploring at equal work; + at 10 bots it is still shorter in both. +- At equal exploring work Horizon's tick is about half of vanilla's at 10 and 25 bots. +- When the bots only fly around spawn (`walk`), vanilla's tick hardly grows with players (16 to 20 ms from + 1 to 50 bots) while Horizon's grows by about 0.5 ms per bot, so vanilla is ahead from about 20 bots: 16.0 + against 20.7 ms at 25 and 20.5 against 31.4 ms at 50. Both keep 20 TPS up to 50. +- With 100 bots vanilla's watchdog stops it in every pass, and Horizon keeps running at 9 to 11 TPS. + +### Where Horizon's walk tick goes at 25 bots + +Profiled on the ThinkPad with `perf` (the server thread, 20 s, self time): + +| Share | What | Whose | +|---:|---|---| +| 18 % | `Streaming::update`: every tick it walks all loaded columns and proto chunks and tests each against every player's area (unloading, dropping protos, finishing and decoration candidates), so the cost grows with players times chunks | streaming / engine tick | +| 20 % | `PalettedContainer::get` and `World::block`, mostly from block entity ticks: on the Mac profile `tick_hoppers` looks up the block under every block entity in the loaded world each tick and compares names as strings, and spawners rebuild their display id | engine tick | +| 8 % | `light_data` when a chunk is sent: the light layers were built twice per chunk; a follow-up commit on #623 builds them once and keeps each section's packed layers | server (this work) | +| 7 % | encoding chunk sections and heightmaps for the chunks each bot newly sees | server | +| 4 % | `Hub::tick` (moves, tracking) | server | +| 2 % | the moved-wrongly collision check | server | + +The first two grow with the number of players but aren't specific to the server: they are the +engine's tick and streaming, reported to perf-server-2. Before #623 and #649, encoding every chunk section +once per player and waking each connection's writer thread once per packet cost more than everything above +(at 50 walking bots the tick was 281 ms; see the earlier runs). + +## Earlier runs (same machine and method) + +- `run-1-before-chunk-cache.json`: before #623, with vanilla's locator bar on. Horizon's walk tick was + 27.5, 40.7, 281 and 467 ms at 10, 25, 50 and 100 bots, and vanilla's 33.2 ms at 50 (the locator bar). +- `run-2-chunk-cache.json`: Horizon with #623 only: 13.2, 23.5, 31.4 and 84.4 ms walking at 10 to 100 + bots. + +## Files + +- `horizon.json`, `vanilla.json`: the walk and explore passes (vanilla with `locator_bar=false`). +- `explore-equal-rate.json`: the explore pass at 0.8 blocks a second, both servers. +- `run-1-before-chunk-cache.json`, `run-2-chunk-cache.json`: the earlier runs. + +To run it again (bots on another machine reached at `--connect`): + + cargo build --release -p horizon-client --bin horizon-client -p horizon-server -p horizon-bots + python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25,50,100 --behaviour walk,explore \ + --gamerule locator_bar=false --nice 19 --bots-via 'ssh macmini' --bots-bin /path/to/horizon-bots \ + --connect --out results.json + python3 tools/server_bench.py --servers horizon,vanilla --bots 1,10,25 --behaviour explore \ + --explore-speed 0.8 --gamerule locator_bar=false --nice 19 ... --out explore-equal-rate.json diff --git a/benchmarks/server-equal-work-2026-10-17/explore-equal-rate.json b/benchmarks/server-equal-work-2026-10-17/explore-equal-rate.json new file mode 100644 index 000000000..bd097e43a --- /dev/null +++ b/benchmarks/server-equal-work-2026-10-17/explore-equal-rate.json @@ -0,0 +1,267 @@ +{ + "kind": "horizon-server-benchmark", + "date": "2026-10-17T05:47:12+00:00", + "machine": { + "system": "Linux", + "machine": "x86_64", + "cpus": 4 + }, + "commit": "", + "java": [ + "openjdk 25.0.4.1 2026-08-18" + ], + "settings": { + "servers": "horizon,vanilla", + "bots": "1,10,25", + "behaviour": "explore", + "join_every": 1.0, + "warmup": 60, + "seconds": 300, + "seed": 12345, + "explore_speed": 0.8, + "gamerule": "locator_bar=false", + "heap": "4g", + "out": "/home/ludovic/scratch/sh2-bench5.json", + "nice": 19, + "bots_via": "ssh -o BatchMode=yes macmini", + "bots_bin": "/tmp/sh2-horizon-bots", + "connect": "100.72.51.8", + "properties": { + "level-seed": "12345", + "view-distance": "10", + "simulation-distance": "10", + "online-mode": "false", + "white-list": "false", + "gamemode": "creative", + "force-gamemode": "true", + "spawn-protection": "0", + "max-players": "200", + "difficulty": "easy", + "sync-chunk-writes": "true" + } + }, + "runs": [ + { + "server": "horizon", + "bots": 1, + "behaviour": "explore", + "start_seconds": 10.91, + "mspt": { + "average": 4.02, + "p50": 3.75, + "p95": 6.63, + "p99": 14.55 + }, + "mspt_worst_p99": 63.3, + "tps": 20.0, + "rss_mb": { + "mean": 1392.42, + "max": 1746.1 + }, + "cpu_percent": 24.52, + "chunks_per_second": 1.69, + "unique_per_second": 1.34, + "forgotten_per_second": 1.62, + "waited_ticks_per_second": 0.0, + "chunks_total": 1048, + "chunks_per_bot": { + "explore": 1048.0 + }, + "unique_chunks_per_bot": { + "explore": 952.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 1, + "behaviour": "explore", + "start_seconds": 15.13, + "mspt": { + "average": 18.12, + "p50": 18.78, + "p95": 27.07, + "p99": 60.81 + }, + "mspt_worst_p99": 1397.6, + "tps": 20.0, + "rss_mb": { + "mean": 3397.31, + "max": 3430.2 + }, + "cpu_percent": 72.99, + "chunks_per_second": 1.69, + "unique_per_second": 1.38, + "forgotten_per_second": 1.62, + "waited_ticks_per_second": 0.0, + "chunks_total": 1048, + "chunks_per_bot": { + "explore": 1048.0 + }, + "unique_chunks_per_bot": { + "explore": 952.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 10, + "behaviour": "explore", + "start_seconds": 11.12, + "mspt": { + "average": 13.49, + "p50": 12.09, + "p95": 24.81, + "p99": 40.9 + }, + "mspt_worst_p99": 101.4, + "tps": 20.0, + "rss_mb": { + "mean": 1684.04, + "max": 2660.6 + }, + "cpu_percent": 89.04, + "chunks_per_second": 13.08, + "unique_per_second": 11.84, + "forgotten_per_second": 13.02, + "waited_ticks_per_second": 0.0, + "chunks_total": 9277, + "chunks_per_bot": { + "explore": 927.7 + }, + "unique_chunks_per_bot": { + "explore": 889.9 + }, + "resent": 0, + "pulled_back": 3381, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 10, + "behaviour": "explore", + "start_seconds": 14.84, + "mspt": { + "average": 29.18, + "p50": 26.76, + "p95": 43.02, + "p99": 80.16 + }, + "mspt_worst_p99": 425.5, + "tps": 20.0, + "rss_mb": { + "mean": 3609.51, + "max": 3791.6 + }, + "cpu_percent": 142.79, + "chunks_per_second": 13.1, + "unique_per_second": 11.88, + "forgotten_per_second": 13.12, + "waited_ticks_per_second": 0.0, + "chunks_total": 9245, + "chunks_per_bot": { + "explore": 924.5 + }, + "unique_chunks_per_bot": { + "explore": 885.3 + }, + "resent": 0, + "pulled_back": 3388, + "moved_too_quickly": 6, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "horizon", + "bots": 25, + "behaviour": "explore", + "start_seconds": 11.02, + "mspt": { + "average": 20.25, + "p50": 18.73, + "p95": 36.78, + "p99": 55.76 + }, + "mspt_worst_p99": 92.3, + "tps": 20.0, + "rss_mb": { + "mean": 1782.26, + "max": 2741.9 + }, + "cpu_percent": 120.8, + "chunks_per_second": 32.22, + "unique_per_second": 28.89, + "forgotten_per_second": 32.19, + "waited_ticks_per_second": 0.0, + "chunks_total": 23357, + "chunks_per_bot": { + "explore": 934.28 + }, + "unique_chunks_per_bot": { + "explore": 890.32 + }, + "resent": 0, + "pulled_back": 11580, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 25, + "behaviour": "explore", + "start_seconds": 14.54, + "mspt": { + "average": 37.04, + "p50": 34.77, + "p95": 49.42, + "p99": 101.67 + }, + "mspt_worst_p99": 735.2, + "tps": 20.0, + "rss_mb": { + "mean": 3815.46, + "max": 4202.0 + }, + "cpu_percent": 169.15, + "chunks_per_second": 32.34, + "unique_per_second": 28.93, + "forgotten_per_second": 32.31, + "waited_ticks_per_second": 0.0, + "chunks_total": 23306, + "chunks_per_bot": { + "explore": 932.24 + }, + "unique_chunks_per_bot": { + "explore": 886.96 + }, + "resent": 0, + "pulled_back": 11539, + "moved_too_quickly": 6, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 59 + } + ] +} diff --git a/benchmarks/server-equal-work-2026-10-17/horizon.json b/benchmarks/server-equal-work-2026-10-17/horizon.json new file mode 100644 index 000000000..d0b162c44 --- /dev/null +++ b/benchmarks/server-equal-work-2026-10-17/horizon.json @@ -0,0 +1,415 @@ +{ + "kind": "horizon-server-benchmark", + "date": "2026-10-17T05:04:57+00:00", + "machine": { + "system": "Linux", + "machine": "x86_64", + "cpus": 4 + }, + "commit": "", + "java": [ + "openjdk 25.0.4.1 2026-08-18" + ], + "settings": { + "servers": "horizon", + "bots": "1,10,25,50,100", + "behaviour": "walk,explore", + "join_every": 1.0, + "warmup": 60, + "seconds": 300, + "seed": 12345, + "explore_speed": 0, + "gamerule": "locator_bar=false", + "heap": "4g", + "out": "/home/ludovic/scratch/sh2-bench4.json", + "nice": 19, + "bots_via": "ssh -o BatchMode=yes macmini", + "bots_bin": "/tmp/sh2-horizon-bots", + "connect": "100.72.51.8", + "properties": { + "level-seed": "12345", + "view-distance": "10", + "simulation-distance": "10", + "online-mode": "false", + "white-list": "false", + "gamemode": "creative", + "force-gamemode": "true", + "spawn-protection": "0", + "max-players": "200", + "difficulty": "easy", + "sync-chunk-writes": "true" + } + }, + "runs": [ + { + "server": "horizon", + "bots": 1, + "behaviour": "walk", + "start_seconds": 11.02, + "mspt": { + "average": 5.45, + "p50": 4.63, + "p95": 12.14, + "p99": 30.63 + }, + "mspt_worst_p99": 91.5, + "tps": 20.0, + "rss_mb": { + "mean": 1398.5, + "max": 1708.4 + }, + "cpu_percent": 57.03, + "chunks_per_second": 9.17, + "unique_per_second": 0.26, + "forgotten_per_second": 9.2, + "waited_ticks_per_second": 0.0, + "chunks_total": 3708, + "chunks_per_bot": { + "walk": 3708.0 + }, + "unique_chunks_per_bot": { + "walk": 694.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 10, + "behaviour": "walk", + "start_seconds": 11.02, + "mspt": { + "average": 11.51, + "p50": 10.6, + "p95": 22.13, + "p99": 36.92 + }, + "mspt_worst_p99": 71.9, + "tps": 20.0, + "rss_mb": { + "mean": 1440.2, + "max": 1832.4 + }, + "cpu_percent": 124.19, + "chunks_per_second": 94.04, + "unique_per_second": 2.38, + "forgotten_per_second": 93.95, + "waited_ticks_per_second": 0.0, + "chunks_total": 37269, + "chunks_per_bot": { + "walk": 3726.9 + }, + "unique_chunks_per_bot": { + "walk": 688.9 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 25, + "behaviour": "walk", + "start_seconds": 10.91, + "mspt": { + "average": 20.74, + "p50": 19.27, + "p95": 40.42, + "p99": 57.12 + }, + "mspt_worst_p99": 102.0, + "tps": 20.0, + "rss_mb": { + "mean": 1485.4, + "max": 1871.9 + }, + "cpu_percent": 169.52, + "chunks_per_second": 235.81, + "unique_per_second": 5.68, + "forgotten_per_second": 235.83, + "waited_ticks_per_second": 0.0, + "chunks_total": 94456, + "chunks_per_bot": { + "walk": 3778.24 + }, + "unique_chunks_per_bot": { + "walk": 692.96 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 50, + "behaviour": "walk", + "start_seconds": 11.12, + "mspt": { + "average": 31.41, + "p50": 25.39, + "p95": 78.97, + "p99": 110.73 + }, + "mspt_worst_p99": 192.9, + "tps": 20.0, + "rss_mb": { + "mean": 1558.34, + "max": 1915.3 + }, + "cpu_percent": 173.27, + "chunks_per_second": 450.85, + "unique_per_second": 10.3, + "forgotten_per_second": 451.86, + "waited_ticks_per_second": 0.0, + "chunks_total": 186885, + "chunks_per_bot": { + "walk": 3737.7 + }, + "unique_chunks_per_bot": { + "walk": 688.9 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 100, + "behaviour": "walk", + "start_seconds": 18.16, + "mspt": { + "average": 114.55, + "p50": 101.37, + "p95": 256.19, + "p99": 338.64 + }, + "mspt_worst_p99": 442.6, + "tps": 8.73, + "rss_mb": { + "mean": 1357.65, + "max": 1358.4 + }, + "cpu_percent": 181.21, + "chunks_per_second": 484.16, + "unique_per_second": 30.76, + "forgotten_per_second": 478.77, + "waited_ticks_per_second": 0.0, + "chunks_total": 212947, + "chunks_per_bot": { + "walk": 2129.47 + }, + "unique_chunks_per_bot": { + "walk": 583.02 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 100, + "bots_failed": [], + "tick_queries": 57 + }, + { + "server": "horizon", + "bots": 1, + "behaviour": "explore", + "start_seconds": 17.45, + "mspt": { + "average": 10.62, + "p50": 9.2, + "p95": 24.61, + "p99": 38.18 + }, + "mspt_worst_p99": 81.1, + "tps": 20.0, + "rss_mb": { + "mean": 1372.73, + "max": 1568.7 + }, + "cpu_percent": 322.38, + "chunks_per_second": 39.21, + "unique_per_second": 34.6, + "forgotten_per_second": 38.55, + "waited_ticks_per_second": 0.51, + "chunks_total": 12549, + "chunks_per_bot": { + "explore": 12549.0 + }, + "unique_chunks_per_bot": { + "explore": 11168.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 10, + "behaviour": "explore", + "start_seconds": 11.32, + "mspt": { + "average": 30.38, + "p50": 27.84, + "p95": 52.31, + "p99": 77.89 + }, + "mspt_worst_p99": 158.3, + "tps": 20.0, + "rss_mb": { + "mean": 2231.56, + "max": 4022.6 + }, + "cpu_percent": 344.99, + "chunks_per_second": 47.34, + "unique_per_second": 46.73, + "forgotten_per_second": 44.57, + "waited_ticks_per_second": 112.27, + "chunks_total": 19870, + "chunks_per_bot": { + "explore": 1987.0 + }, + "unique_chunks_per_bot": { + "explore": 1966.5 + }, + "resent": 0, + "pulled_back": 16130, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 25, + "behaviour": "explore", + "start_seconds": 11.42, + "mspt": { + "average": 50.67, + "p50": 47.61, + "p95": 89.3, + "p99": 119.15 + }, + "mspt_worst_p99": 222.3, + "tps": 19.73, + "rss_mb": { + "mean": 2358.4, + "max": 4273.7 + }, + "cpu_percent": 286.32, + "chunks_per_second": 50.39, + "unique_per_second": 49.67, + "forgotten_per_second": 47.45, + "waited_ticks_per_second": 311.85, + "chunks_total": 28954, + "chunks_per_bot": { + "explore": 1158.16 + }, + "unique_chunks_per_bot": { + "explore": 1147.56 + }, + "resent": 0, + "pulled_back": 36319, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 50, + "behaviour": "explore", + "start_seconds": 20.06, + "mspt": { + "average": 50.69, + "p50": 47.48, + "p95": 102.67, + "p99": 133.27 + }, + "mspt_worst_p99": 274.4, + "tps": 19.73, + "rss_mb": { + "mean": 1764.01, + "max": 2542.0 + }, + "cpu_percent": 212.83, + "chunks_per_second": 97.33, + "unique_per_second": 96.47, + "forgotten_per_second": 76.74, + "waited_ticks_per_second": 750.49, + "chunks_total": 38538, + "chunks_per_bot": { + "explore": 770.76 + }, + "unique_chunks_per_bot": { + "explore": 763.84 + }, + "resent": 0, + "pulled_back": 39880, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 100, + "behaviour": "explore", + "start_seconds": 11.82, + "mspt": { + "average": 92.93, + "p50": 87.84, + "p95": 139.6, + "p99": 178.38 + }, + "mspt_worst_p99": 272.9, + "tps": 10.76, + "rss_mb": { + "mean": 1736.38, + "max": 1855.7 + }, + "cpu_percent": 321.53, + "chunks_per_second": 113.89, + "unique_per_second": 113.56, + "forgotten_per_second": 101.68, + "waited_ticks_per_second": 1179.4, + "chunks_total": 84617, + "chunks_per_bot": { + "explore": 846.17 + }, + "unique_chunks_per_bot": { + "explore": 845.01 + }, + "resent": 0, + "pulled_back": 128104, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 100, + "bots_failed": [], + "tick_queries": 58 + } + ] +} diff --git a/benchmarks/server-equal-work-2026-10-17/run-1-before-chunk-cache.json b/benchmarks/server-equal-work-2026-10-17/run-1-before-chunk-cache.json new file mode 100644 index 000000000..d79b3f179 --- /dev/null +++ b/benchmarks/server-equal-work-2026-10-17/run-1-before-chunk-cache.json @@ -0,0 +1,693 @@ +{ + "kind": "horizon-server-benchmark", + "date": "2026-10-17T00:37:35+00:00", + "machine": { + "system": "Linux", + "machine": "x86_64", + "cpus": 4 + }, + "commit": "", + "java": [ + "openjdk 25.0.4.1 2026-08-18" + ], + "settings": { + "servers": "horizon,vanilla", + "bots": "1,10,25,50,100", + "behaviour": "walk,explore", + "join_every": 1.0, + "warmup": 60, + "seconds": 300, + "seed": 12345, + "heap": "4g", + "out": "/home/ludovic/scratch/sh2-bench.json", + "nice": 19, + "bots_via": "ssh -o BatchMode=yes macmini", + "bots_bin": "/tmp/sh2-horizon-bots", + "connect": "100.72.51.8", + "properties": { + "level-seed": "12345", + "view-distance": "10", + "simulation-distance": "10", + "online-mode": "false", + "white-list": "false", + "gamemode": "creative", + "force-gamemode": "true", + "spawn-protection": "0", + "max-players": "200", + "difficulty": "easy", + "sync-chunk-writes": "true" + } + }, + "runs": [ + { + "server": "horizon", + "bots": 1, + "behaviour": "walk", + "start_seconds": 11.12, + "mspt": { + "average": 7.63, + "p50": 5.51, + "p95": 17.46, + "p99": 36.79 + }, + "mspt_worst_p99": 79.6, + "tps": 20.0, + "rss_mb": { + "mean": 1391.94, + "max": 1700.7 + }, + "cpu_percent": 60.18, + "chunks_per_second": 9.15, + "unique_per_second": 0.29, + "forgotten_per_second": 9.18, + "waited_ticks_per_second": 0.0, + "chunks_total": 3682, + "chunks_per_bot": { + "walk": 3682.0 + }, + "unique_chunks_per_bot": { + "walk": 692.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 1, + "behaviour": "walk", + "start_seconds": 15.35, + "mspt": { + "average": 18.08, + "p50": 18.66, + "p95": 28.05, + "p99": 46.94 + }, + "mspt_worst_p99": 456.4, + "tps": 20.0, + "rss_mb": { + "mean": 3455.72, + "max": 3471.7 + }, + "cpu_percent": 65.67, + "chunks_per_second": 9.89, + "unique_per_second": 0.29, + "forgotten_per_second": 9.92, + "waited_ticks_per_second": 0.0, + "chunks_total": 3827, + "chunks_per_bot": { + "walk": 3827.0 + }, + "unique_chunks_per_bot": { + "walk": 699.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 10, + "behaviour": "walk", + "start_seconds": 11.22, + "mspt": { + "average": 27.53, + "p50": 24.93, + "p95": 53.93, + "p99": 77.03 + }, + "mspt_worst_p99": 111.4, + "tps": 20.0, + "rss_mb": { + "mean": 1433.85, + "max": 1831.9 + }, + "cpu_percent": 138.65, + "chunks_per_second": 95.98, + "unique_per_second": 2.38, + "forgotten_per_second": 95.78, + "waited_ticks_per_second": 0.0, + "chunks_total": 38041, + "chunks_per_bot": { + "walk": 3804.1 + }, + "unique_chunks_per_bot": { + "walk": 690.8 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 10, + "behaviour": "walk", + "start_seconds": 14.83, + "mspt": { + "average": 18.92, + "p50": 16.02, + "p95": 39.0, + "p99": 56.13 + }, + "mspt_worst_p99": 180.3, + "tps": 20.0, + "rss_mb": { + "mean": 3479.45, + "max": 3535.7 + }, + "cpu_percent": 99.39, + "chunks_per_second": 99.93, + "unique_per_second": 2.94, + "forgotten_per_second": 100.04, + "waited_ticks_per_second": 0.0, + "chunks_total": 38411, + "chunks_per_bot": { + "walk": 3841.1 + }, + "unique_chunks_per_bot": { + "walk": 697.1 + }, + "resent": 0, + "pulled_back": 7, + "moved_too_quickly": 7, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "horizon", + "bots": 25, + "behaviour": "walk", + "start_seconds": 11.52, + "mspt": { + "average": 40.69, + "p50": 37.28, + "p95": 81.16, + "p99": 108.42 + }, + "mspt_worst_p99": 149.9, + "tps": 20.0, + "rss_mb": { + "mean": 1444.12, + "max": 1882.6 + }, + "cpu_percent": 176.94, + "chunks_per_second": 244.11, + "unique_per_second": 6.51, + "forgotten_per_second": 243.96, + "waited_ticks_per_second": 0.0, + "chunks_total": 95219, + "chunks_per_bot": { + "walk": 3808.76 + }, + "unique_chunks_per_bot": { + "walk": 695.64 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 25, + "behaviour": "walk", + "start_seconds": 15.23, + "mspt": { + "average": 18.81, + "p50": 17.26, + "p95": 30.16, + "p99": 53.9 + }, + "mspt_worst_p99": 390.0, + "tps": 20.0, + "rss_mb": { + "mean": 3517.36, + "max": 3555.7 + }, + "cpu_percent": 148.52, + "chunks_per_second": 252.34, + "unique_per_second": 7.75, + "forgotten_per_second": 251.95, + "waited_ticks_per_second": 0.0, + "chunks_total": 96645, + "chunks_per_bot": { + "walk": 3865.8 + }, + "unique_chunks_per_bot": { + "walk": 698.4 + }, + "resent": 0, + "pulled_back": 11, + "moved_too_quickly": 11, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "horizon", + "bots": 50, + "behaviour": "walk", + "start_seconds": 12.72, + "mspt": { + "average": 281.42, + "p50": 278.28, + "p95": 343.64, + "p99": 384.23 + }, + "mspt_worst_p99": 475.1, + "tps": 3.55, + "rss_mb": { + "mean": 1334.32, + "max": 1335.4 + }, + "cpu_percent": 197.11, + "chunks_per_second": 391.5, + "unique_per_second": 21.24, + "forgotten_per_second": 388.33, + "waited_ticks_per_second": 0.0, + "chunks_total": 153136, + "chunks_per_bot": { + "walk": 3062.72 + }, + "unique_chunks_per_bot": { + "walk": 661.82 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 57 + }, + { + "server": "vanilla", + "bots": 50, + "behaviour": "walk", + "start_seconds": 15.74, + "mspt": { + "average": 33.21, + "p50": 29.9, + "p95": 53.37, + "p99": 109.14 + }, + "mspt_worst_p99": 833.3, + "tps": 20.0, + "rss_mb": { + "mean": 3568.07, + "max": 3594.9 + }, + "cpu_percent": 266.59, + "chunks_per_second": 496.3, + "unique_per_second": 18.64, + "forgotten_per_second": 495.77, + "waited_ticks_per_second": 0.0, + "chunks_total": 191965, + "chunks_per_bot": { + "walk": 3839.3 + }, + "unique_chunks_per_bot": { + "walk": 696.22 + }, + "resent": 0, + "pulled_back": 184, + "moved_too_quickly": 183, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 100, + "behaviour": "walk", + "start_seconds": 11.22, + "mspt": { + "average": 467.37, + "p50": 464.62, + "p95": 524.07, + "p99": 548.77 + }, + "mspt_worst_p99": 581.1, + "tps": 2.14, + "rss_mb": { + "mean": 1353.68, + "max": 1354.9 + }, + "cpu_percent": 191.96, + "chunks_per_second": 377.62, + "unique_per_second": 55.8, + "forgotten_per_second": 348.88, + "waited_ticks_per_second": 0.0, + "chunks_total": 165719, + "chunks_per_bot": { + "walk": 1657.19 + }, + "unique_chunks_per_bot": { + "walk": 549.8 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 100, + "bots_failed": [], + "tick_queries": 56 + }, + { + "server": "vanilla", + "bots": 100, + "behaviour": "walk", + "start_seconds": 14.84, + "error": "[Errno 32] Broken pipe" + }, + { + "server": "horizon", + "bots": 1, + "behaviour": "explore", + "start_seconds": 11.12, + "mspt": { + "average": 17.07, + "p50": 16.6, + "p95": 32.82, + "p99": 50.3 + }, + "mspt_worst_p99": 113.9, + "tps": 20.0, + "rss_mb": { + "mean": 1391.72, + "max": 1566.6 + }, + "cpu_percent": 333.8, + "chunks_per_second": 39.42, + "unique_per_second": 34.77, + "forgotten_per_second": 39.34, + "waited_ticks_per_second": 0.0, + "chunks_total": 13860, + "chunks_per_bot": { + "explore": 13860.0 + }, + "unique_chunks_per_bot": { + "explore": 12379.0 + }, + "resent": 0, + "pulled_back": 192, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 1, + "behaviour": "explore", + "start_seconds": 16.03, + "mspt": { + "average": 9.9, + "p50": 8.04, + "p95": 20.41, + "p99": 63.62 + }, + "mspt_worst_p99": 351.1, + "tps": 20.0, + "rss_mb": { + "mean": 3709.92, + "max": 3776.2 + }, + "cpu_percent": 246.64, + "chunks_per_second": 36.06, + "unique_per_second": 33.33, + "forgotten_per_second": 35.73, + "waited_ticks_per_second": 0.0, + "chunks_total": 12369, + "chunks_per_bot": { + "explore": 12369.0 + }, + "unique_chunks_per_bot": { + "explore": 11559.0 + }, + "resent": 0, + "pulled_back": 222, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "horizon", + "bots": 10, + "behaviour": "explore", + "start_seconds": 11.42, + "mspt": { + "average": 33.72, + "p50": 31.08, + "p95": 61.07, + "p99": 89.09 + }, + "mspt_worst_p99": 142.6, + "tps": 20.0, + "rss_mb": { + "mean": 2239.97, + "max": 4108.8 + }, + "cpu_percent": 350.83, + "chunks_per_second": 46.49, + "unique_per_second": 46.08, + "forgotten_per_second": 44.33, + "waited_ticks_per_second": 111.28, + "chunks_total": 19915, + "chunks_per_bot": { + "explore": 1991.5 + }, + "unique_chunks_per_bot": { + "explore": 1974.4 + }, + "resent": 0, + "pulled_back": 17516, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 10, + "behaviour": "explore", + "start_seconds": 15.15, + "mspt": { + "average": 16.25, + "p50": 13.67, + "p95": 28.92, + "p99": 115.9 + }, + "mspt_worst_p99": 1202.1, + "tps": 20.0, + "rss_mb": { + "mean": 4202.72, + "max": 4502.7 + }, + "cpu_percent": 247.47, + "chunks_per_second": 22.3, + "unique_per_second": 22.25, + "forgotten_per_second": 22.64, + "waited_ticks_per_second": 78.89, + "chunks_total": 10092, + "chunks_per_bot": { + "explore": 1009.2 + }, + "unique_chunks_per_bot": { + "explore": 1007.4 + }, + "resent": 0, + "pulled_back": 16286, + "moved_too_quickly": 12, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "horizon", + "bots": 25, + "behaviour": "explore", + "start_seconds": 11.82, + "mspt": { + "average": 48.03, + "p50": 44.99, + "p95": 83.06, + "p99": 109.63 + }, + "mspt_worst_p99": 191.8, + "tps": 20.0, + "rss_mb": { + "mean": 2214.16, + "max": 4598.6 + }, + "cpu_percent": 356.03, + "chunks_per_second": 64.2, + "unique_per_second": 63.5, + "forgotten_per_second": 60.9, + "waited_ticks_per_second": 301.65, + "chunks_total": 32247, + "chunks_per_bot": { + "explore": 1289.88 + }, + "unique_chunks_per_bot": { + "explore": 1279.4 + }, + "resent": 0, + "pulled_back": 42159, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 25, + "behaviour": "explore", + "start_seconds": 14.73, + "mspt": { + "average": 25.73, + "p50": 22.75, + "p95": 37.72, + "p99": 201.98 + }, + "mspt_worst_p99": 4051.5, + "tps": 20.0, + "rss_mb": { + "mean": 4355.9, + "max": 4983.2 + }, + "cpu_percent": 309.3, + "chunks_per_second": 33.33, + "unique_per_second": 33.21, + "forgotten_per_second": 34.22, + "waited_ticks_per_second": 258.68, + "chunks_total": 19426, + "chunks_per_bot": { + "explore": 777.04 + }, + "unique_chunks_per_bot": { + "explore": 772.92 + }, + "resent": 0, + "pulled_back": 53918, + "moved_too_quickly": 93, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 50, + "behaviour": "explore", + "start_seconds": 11.01, + "mspt": { + "average": 108.61, + "p50": 107.37, + "p95": 151.96, + "p99": 177.41 + }, + "mspt_worst_p99": 271.6, + "tps": 9.21, + "rss_mb": { + "mean": 1775.98, + "max": 1956.9 + }, + "cpu_percent": 359.7, + "chunks_per_second": 100.32, + "unique_per_second": 98.91, + "forgotten_per_second": 95.42, + "waited_ticks_per_second": 518.15, + "chunks_total": 55956, + "chunks_per_bot": { + "explore": 1119.12 + }, + "unique_chunks_per_bot": { + "explore": 1111.42 + }, + "resent": 0, + "pulled_back": 69967, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 50, + "behaviour": "explore", + "start_seconds": 14.74, + "error": "[Errno 32] Broken pipe" + }, + { + "server": "horizon", + "bots": 100, + "behaviour": "explore", + "start_seconds": 11.12, + "mspt": { + "average": 244.43, + "p50": 243.58, + "p95": 308.39, + "p99": 360.12 + }, + "mspt_worst_p99": 470.2, + "tps": 4.09, + "rss_mb": { + "mean": 1806.85, + "max": 2084.5 + }, + "cpu_percent": 310.46, + "chunks_per_second": 186.87, + "unique_per_second": 182.99, + "forgotten_per_second": 161.75, + "waited_ticks_per_second": 1131.65, + "chunks_total": 100389, + "chunks_per_bot": { + "explore": 1003.89 + }, + "unique_chunks_per_bot": { + "explore": 991.9 + }, + "resent": 0, + "pulled_back": 56791, + "moved_too_quickly": 344, + "moved_wrongly": 0, + "bots_joined": 100, + "bots_failed": [], + "tick_queries": 57 + }, + { + "server": "vanilla", + "bots": 100, + "behaviour": "explore", + "start_seconds": 14.83, + "error": "[Errno 32] Broken pipe" + } + ] +} diff --git a/benchmarks/server-equal-work-2026-10-17/run-2-chunk-cache.json b/benchmarks/server-equal-work-2026-10-17/run-2-chunk-cache.json new file mode 100644 index 000000000..4c182395c --- /dev/null +++ b/benchmarks/server-equal-work-2026-10-17/run-2-chunk-cache.json @@ -0,0 +1,413 @@ +{ + "kind": "horizon-server-benchmark", + "date": "2026-10-17T02:22:59+00:00", + "machine": { + "system": "Linux", + "machine": "x86_64", + "cpus": 4 + }, + "commit": "", + "java": [ + "openjdk 25.0.4.1 2026-08-18" + ], + "settings": { + "servers": "horizon", + "bots": "1,10,25,50,100", + "behaviour": "walk,explore", + "join_every": 1.0, + "warmup": 60, + "seconds": 300, + "seed": 12345, + "heap": "4g", + "out": "/home/ludovic/scratch/sh2-bench2.json", + "nice": 19, + "bots_via": "ssh -o BatchMode=yes macmini", + "bots_bin": "/tmp/sh2-horizon-bots", + "connect": "100.72.51.8", + "properties": { + "level-seed": "12345", + "view-distance": "10", + "simulation-distance": "10", + "online-mode": "false", + "white-list": "false", + "gamemode": "creative", + "force-gamemode": "true", + "spawn-protection": "0", + "max-players": "200", + "difficulty": "easy", + "sync-chunk-writes": "true" + } + }, + "runs": [ + { + "server": "horizon", + "bots": 1, + "behaviour": "walk", + "start_seconds": 11.12, + "mspt": { + "average": 5.41, + "p50": 4.63, + "p95": 11.61, + "p99": 30.5 + }, + "mspt_worst_p99": 64.6, + "tps": 20.0, + "rss_mb": { + "mean": 1398.84, + "max": 1708.5 + }, + "cpu_percent": 56.84, + "chunks_per_second": 9.19, + "unique_per_second": 0.27, + "forgotten_per_second": 9.22, + "waited_ticks_per_second": 0.0, + "chunks_total": 3713, + "chunks_per_bot": { + "walk": 3713.0 + }, + "unique_chunks_per_bot": { + "walk": 694.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 10, + "behaviour": "walk", + "start_seconds": 10.92, + "mspt": { + "average": 13.18, + "p50": 11.74, + "p95": 26.5, + "p99": 44.82 + }, + "mspt_worst_p99": 87.6, + "tps": 20.0, + "rss_mb": { + "mean": 1439.83, + "max": 1831.6 + }, + "cpu_percent": 132.94, + "chunks_per_second": 93.87, + "unique_per_second": 2.38, + "forgotten_per_second": 93.77, + "waited_ticks_per_second": 0.0, + "chunks_total": 37240, + "chunks_per_bot": { + "walk": 3724.0 + }, + "unique_chunks_per_bot": { + "walk": 688.7 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 25, + "behaviour": "walk", + "start_seconds": 10.92, + "mspt": { + "average": 23.52, + "p50": 21.92, + "p95": 44.7, + "p99": 63.12 + }, + "mspt_worst_p99": 119.1, + "tps": 20.0, + "rss_mb": { + "mean": 1485.82, + "max": 1872.0 + }, + "cpu_percent": 173.82, + "chunks_per_second": 235.63, + "unique_per_second": 5.64, + "forgotten_per_second": 235.72, + "waited_ticks_per_second": 0.0, + "chunks_total": 94549, + "chunks_per_bot": { + "walk": 3781.96 + }, + "unique_chunks_per_bot": { + "walk": 692.8 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 50, + "behaviour": "walk", + "start_seconds": 10.91, + "mspt": { + "average": 31.36, + "p50": 26.08, + "p95": 70.6, + "p99": 92.83 + }, + "mspt_worst_p99": 125.5, + "tps": 20.0, + "rss_mb": { + "mean": 1556.81, + "max": 1913.0 + }, + "cpu_percent": 192.16, + "chunks_per_second": 468.69, + "unique_per_second": 10.43, + "forgotten_per_second": 468.78, + "waited_ticks_per_second": 0.0, + "chunks_total": 193547, + "chunks_per_bot": { + "walk": 3870.94 + }, + "unique_chunks_per_bot": { + "walk": 692.84 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 100, + "behaviour": "walk", + "start_seconds": 11.02, + "mspt": { + "average": 84.38, + "p50": 81.5, + "p95": 132.92, + "p99": 168.38 + }, + "mspt_worst_p99": 245.5, + "tps": 11.85, + "rss_mb": { + "mean": 1395.64, + "max": 1941.3 + }, + "cpu_percent": 271.28, + "chunks_per_second": 850.05, + "unique_per_second": 21.79, + "forgotten_per_second": 851.1, + "waited_ticks_per_second": 0.0, + "chunks_total": 368464, + "chunks_per_bot": { + "walk": 3684.64 + }, + "unique_chunks_per_bot": { + "walk": 680.58 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 100, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 1, + "behaviour": "explore", + "start_seconds": 11.02, + "mspt": { + "average": 11.63, + "p50": 10.27, + "p95": 24.52, + "p99": 40.53 + }, + "mspt_worst_p99": 99.9, + "tps": 20.0, + "rss_mb": { + "mean": 1413.81, + "max": 1596.1 + }, + "cpu_percent": 329.84, + "chunks_per_second": 39.47, + "unique_per_second": 34.81, + "forgotten_per_second": 39.42, + "waited_ticks_per_second": 0.0, + "chunks_total": 13798, + "chunks_per_bot": { + "explore": 13798.0 + }, + "unique_chunks_per_bot": { + "explore": 12330.0 + }, + "resent": 0, + "pulled_back": 185, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 10, + "behaviour": "explore", + "start_seconds": 11.02, + "mspt": { + "average": 28.49, + "p50": 26.2, + "p95": 48.58, + "p99": 72.04 + }, + "mspt_worst_p99": 125.7, + "tps": 20.0, + "rss_mb": { + "mean": 2231.06, + "max": 4077.8 + }, + "cpu_percent": 344.95, + "chunks_per_second": 46.31, + "unique_per_second": 45.88, + "forgotten_per_second": 44.14, + "waited_ticks_per_second": 111.95, + "chunks_total": 19722, + "chunks_per_bot": { + "explore": 1972.2 + }, + "unique_chunks_per_bot": { + "explore": 1957.0 + }, + "resent": 0, + "pulled_back": 18533, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 25, + "behaviour": "explore", + "start_seconds": 11.12, + "mspt": { + "average": 40.04, + "p50": 37.61, + "p95": 62.39, + "p99": 83.64 + }, + "mspt_worst_p99": 147.0, + "tps": 20.0, + "rss_mb": { + "mean": 2466.85, + "max": 4504.5 + }, + "cpu_percent": 340.13, + "chunks_per_second": 60.61, + "unique_per_second": 59.62, + "forgotten_per_second": 56.28, + "waited_ticks_per_second": 299.57, + "chunks_total": 32877, + "chunks_per_bot": { + "explore": 1315.08 + }, + "unique_chunks_per_bot": { + "explore": 1300.72 + }, + "resent": 0, + "pulled_back": 46272, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 50, + "behaviour": "explore", + "start_seconds": 11.32, + "mspt": { + "average": 61.82, + "p50": 59.21, + "p95": 90.46, + "p99": 115.58 + }, + "mspt_worst_p99": 320.9, + "tps": 16.18, + "rss_mb": { + "mean": 2634.54, + "max": 4883.1 + }, + "cpu_percent": 356.96, + "chunks_per_second": 95.26, + "unique_per_second": 94.31, + "forgotten_per_second": 85.86, + "waited_ticks_per_second": 528.08, + "chunks_total": 59251, + "chunks_per_bot": { + "explore": 1185.02 + }, + "unique_chunks_per_bot": { + "explore": 1173.96 + }, + "resent": 0, + "pulled_back": 99493, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "horizon", + "bots": 100, + "behaviour": "explore", + "start_seconds": 10.81, + "mspt": { + "average": 103.24, + "p50": 100.03, + "p95": 144.77, + "p99": 178.8 + }, + "mspt_worst_p99": 258.6, + "tps": 9.69, + "rss_mb": { + "mean": 1784.48, + "max": 1922.0 + }, + "cpu_percent": 336.94, + "chunks_per_second": 115.06, + "unique_per_second": 114.86, + "forgotten_per_second": 109.43, + "waited_ticks_per_second": 1127.57, + "chunks_total": 93839, + "chunks_per_bot": { + "explore": 938.39 + }, + "unique_chunks_per_bot": { + "explore": 935.28 + }, + "resent": 0, + "pulled_back": 133404, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 100, + "bots_failed": [], + "tick_queries": 58 + } + ] +} diff --git a/benchmarks/server-equal-work-2026-10-17/vanilla.json b/benchmarks/server-equal-work-2026-10-17/vanilla.json new file mode 100644 index 000000000..014554cee --- /dev/null +++ b/benchmarks/server-equal-work-2026-10-17/vanilla.json @@ -0,0 +1,324 @@ +{ + "kind": "horizon-server-benchmark", + "date": "2026-10-17T03:29:30+00:00", + "machine": { + "system": "Linux", + "machine": "x86_64", + "cpus": 4 + }, + "commit": "", + "java": [ + "openjdk 25.0.4.1 2026-08-18" + ], + "settings": { + "servers": "vanilla", + "bots": "1,10,25,50,100", + "behaviour": "walk,explore", + "join_every": 1.0, + "warmup": 60, + "seconds": 300, + "seed": 12345, + "gamerule": "locator_bar=false", + "heap": "4g", + "out": "/home/ludovic/scratch/sh2-bench3.json", + "nice": 19, + "bots_via": "ssh -o BatchMode=yes macmini", + "bots_bin": "/tmp/sh2-horizon-bots", + "connect": "100.72.51.8", + "properties": { + "level-seed": "12345", + "view-distance": "10", + "simulation-distance": "10", + "online-mode": "false", + "white-list": "false", + "gamemode": "creative", + "force-gamemode": "true", + "spawn-protection": "0", + "max-players": "200", + "difficulty": "easy", + "sync-chunk-writes": "true" + } + }, + "runs": [ + { + "server": "vanilla", + "bots": 1, + "behaviour": "walk", + "start_seconds": 15.43, + "mspt": { + "average": 18.32, + "p50": 19.26, + "p95": 27.34, + "p99": 45.48 + }, + "mspt_worst_p99": 393.3, + "tps": 20.0, + "rss_mb": { + "mean": 3428.43, + "max": 3437.7 + }, + "cpu_percent": 66.47, + "chunks_per_second": 9.92, + "unique_per_second": 0.29, + "forgotten_per_second": 9.95, + "waited_ticks_per_second": 0.0, + "chunks_total": 3850, + "chunks_per_bot": { + "walk": 3850.0 + }, + "unique_chunks_per_bot": { + "walk": 699.0 + }, + "resent": 0, + "pulled_back": 0, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 10, + "behaviour": "walk", + "start_seconds": 14.76, + "mspt": { + "average": 16.8, + "p50": 14.55, + "p95": 30.52, + "p99": 50.01 + }, + "mspt_worst_p99": 205.2, + "tps": 20.0, + "rss_mb": { + "mean": 3490.15, + "max": 3580.7 + }, + "cpu_percent": 83.7, + "chunks_per_second": 100.01, + "unique_per_second": 2.83, + "forgotten_per_second": 100.04, + "waited_ticks_per_second": 0.0, + "chunks_total": 38623, + "chunks_per_bot": { + "walk": 3862.3 + }, + "unique_chunks_per_bot": { + "walk": 697.2 + }, + "resent": 0, + "pulled_back": 5, + "moved_too_quickly": 5, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "vanilla", + "bots": 25, + "behaviour": "walk", + "start_seconds": 14.84, + "mspt": { + "average": 16.01, + "p50": 14.55, + "p95": 26.39, + "p99": 51.26 + }, + "mspt_worst_p99": 397.8, + "tps": 20.0, + "rss_mb": { + "mean": 3550.02, + "max": 3593.5 + }, + "cpu_percent": 114.96, + "chunks_per_second": 251.62, + "unique_per_second": 6.72, + "forgotten_per_second": 251.16, + "waited_ticks_per_second": 0.0, + "chunks_total": 98701, + "chunks_per_bot": { + "walk": 3948.04 + }, + "unique_chunks_per_bot": { + "walk": 698.84 + }, + "resent": 0, + "pulled_back": 10, + "moved_too_quickly": 10, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "vanilla", + "bots": 50, + "behaviour": "walk", + "start_seconds": 14.43, + "mspt": { + "average": 20.52, + "p50": 19.55, + "p95": 29.72, + "p99": 49.04 + }, + "mspt_worst_p99": 600.4, + "tps": 20.0, + "rss_mb": { + "mean": 3633.12, + "max": 3658.7 + }, + "cpu_percent": 193.84, + "chunks_per_second": 501.86, + "unique_per_second": 12.15, + "forgotten_per_second": 501.8, + "waited_ticks_per_second": 0.0, + "chunks_total": 203429, + "chunks_per_bot": { + "walk": 4068.58 + }, + "unique_chunks_per_bot": { + "walk": 698.66 + }, + "resent": 0, + "pulled_back": 33, + "moved_too_quickly": 32, + "moved_wrongly": 0, + "bots_joined": 50, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "vanilla", + "bots": 100, + "behaviour": "walk", + "start_seconds": 15.34, + "error": "[Errno 32] Broken pipe" + }, + { + "server": "vanilla", + "bots": 1, + "behaviour": "explore", + "start_seconds": 15.55, + "mspt": { + "average": 9.93, + "p50": 8.12, + "p95": 21.33, + "p99": 60.19 + }, + "mspt_worst_p99": 373.0, + "tps": 20.0, + "rss_mb": { + "mean": 3564.11, + "max": 3655.0 + }, + "cpu_percent": 245.18, + "chunks_per_second": 35.93, + "unique_per_second": 33.35, + "forgotten_per_second": 35.64, + "waited_ticks_per_second": 0.0, + "chunks_total": 12340, + "chunks_per_bot": { + "explore": 12340.0 + }, + "unique_chunks_per_bot": { + "explore": 11569.0 + }, + "resent": 0, + "pulled_back": 261, + "moved_too_quickly": 0, + "moved_wrongly": 0, + "bots_joined": 1, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "vanilla", + "bots": 10, + "behaviour": "explore", + "start_seconds": 15.03, + "mspt": { + "average": 16.99, + "p50": 14.46, + "p95": 29.61, + "p99": 132.18 + }, + "mspt_worst_p99": 1244.0, + "tps": 20.0, + "rss_mb": { + "mean": 4135.2, + "max": 4453.1 + }, + "cpu_percent": 242.32, + "chunks_per_second": 22.39, + "unique_per_second": 22.41, + "forgotten_per_second": 22.78, + "waited_ticks_per_second": 78.78, + "chunks_total": 10177, + "chunks_per_bot": { + "explore": 1017.7 + }, + "unique_chunks_per_bot": { + "explore": 1016.2 + }, + "resent": 0, + "pulled_back": 17314, + "moved_too_quickly": 19, + "moved_wrongly": 0, + "bots_joined": 10, + "bots_failed": [], + "tick_queries": 59 + }, + { + "server": "vanilla", + "bots": 25, + "behaviour": "explore", + "start_seconds": 14.84, + "mspt": { + "average": 24.19, + "p50": 21.22, + "p95": 36.51, + "p99": 174.82 + }, + "mspt_worst_p99": 1532.8, + "tps": 20.0, + "rss_mb": { + "mean": 4504.55, + "max": 4988.9 + }, + "cpu_percent": 319.55, + "chunks_per_second": 33.78, + "unique_per_second": 33.66, + "forgotten_per_second": 34.64, + "waited_ticks_per_second": 269.22, + "chunks_total": 20522, + "chunks_per_bot": { + "explore": 820.88 + }, + "unique_chunks_per_bot": { + "explore": 815.76 + }, + "resent": 0, + "pulled_back": 46246, + "moved_too_quickly": 28, + "moved_wrongly": 0, + "bots_joined": 25, + "bots_failed": [], + "tick_queries": 58 + }, + { + "server": "vanilla", + "bots": 50, + "behaviour": "explore", + "start_seconds": 14.73, + "error": "[Errno 32] Broken pipe" + }, + { + "server": "vanilla", + "bots": 100, + "behaviour": "explore", + "start_seconds": 14.54, + "error": "[Errno 32] Broken pipe" + } + ] +} diff --git a/docs/server.md b/docs/server.md index 6e165f534..39b790535 100644 --- a/docs/server.md +++ b/docs/server.md @@ -84,7 +84,7 @@ not tick cost, so it is in scope here (see section 9). | Management | Only stdin. There is no service, no backups, no status beyond `list`, no restart after a crash, and a server can't be managed while it runs in the background. | | Packaging | The server is the full game client. Resources come from `horizon-prepare`, which needs a JDK and the official launcher's client install, both awkward on a headless VPS. | | Tick times | The dedicated loop never recorded its tick times in the game clock (only the windowed loop did), so `/tick query` on a dedicated server reported 0 ms. Fixed in PR 2b, which the benchmark needs (section 9). | -| Scale | Not measured with more than one player. The tick is single-threaded, and each remote player costs the hub one tracking and chunk-sending pass. | +| Scale | Measured against vanilla on equal work (section 9, `benchmarks/server-equal-work-2026-10-17/`): 20 TPS up to 50 bots, 9 to 11 TPS at 100, where vanilla's watchdog stops it. Horizon is ahead with few players and when exploring; with 25 to 50 players near spawn vanilla's tick is shorter. | ### Harnesses on main @@ -457,8 +457,22 @@ reproducible by anyone, and show the same gameplay on both sides. - Vanilla's chunk sending yields under load. - Horizon sent each nearby `walk` bot 1.5–4 times as many chunks. - Horizon sent 2–4 times the chunks per second in every multi-bot run. The next run equalises the work - (slower `explore`, a `walk`-only pass) on a quiet machine before anything is published. + Horizon sent 2–4 times the chunks per second in every multi-bot run. +- **Equal-work run (2026-10-17,** `benchmarks/server-equal-work-2026-10-17/`, on the ThinkPad with the bots + on the Mac mini). Horizon now checks moves and paces chunks as vanilla does (#586), the bots wait for the + chunk they stand in, an `--explore-speed` pass keeps both servers at the same rate, and vanilla runs with + `gamerule locator_bar false` (Horizon has no locator bar yet). Results: + - Memory: Horizon's RSS is 1.9 to 2.6 times smaller in every run (vanilla's heap is fixed at 4 GB). + - Walking near spawn: Horizon's tick is shorter with 1 and 10 bots (5.5 against 18.3 ms, 11.5 against + 16.8), and longer with 25 and 50 (20.7 against 16.0, 31.4 against 20.5). Both keep 20 TPS up to 50. + - Exploring at the same rate: Horizon's tick is about half of vanilla's (13.5 against 29.2 ms at 10 bots, + 20.2 against 37.0 at 25). + - At 100 bots: vanilla's watchdog stops it in every pass; Horizon runs at 9 to 11 TPS. + + Two server costs were found and fixed on the way: every chunk section was encoded once per player (#623), + and every packet woke its connection's writer thread (#649). Together they took the 50-bot walking tick + from 281 ms to 31 ms. At 25 walking bots most of what remains is the engine's streaming and block entity + ticks, both of which grow with players (the README has the profile). - **Ownership.** perf-server-1 owns making the tick faster. This work only measures it, files what it finds, and fixes startup, RAM and packaging. From c7ad9b861fea6746cba412b1cf532c8e834edc33 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 08:45:23 +0200 Subject: [PATCH 20/46] Swimming pose and stroke on the player model The player's model never read the swimming pose: sprint-swimming and crawling drew it upright and walking. Add LivingEntity.swimAmount (eased 0.09 a tick toward isVisuallySwimming), AvatarRenderer's swim rotation (tipped by the pitch in water, -90 out of it, laid along the swimming box) and HumanoidModel.setupSwimAnimation (the 26-unit arm stroke, head down, flutter kick). The avatar rotations now follow LivingEntityRenderer.setupRotations' death and upside-down turns, as in vanilla. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/perspective.rs | 11 ++ crates/horizon-client/src/mobs.rs | 33 ++++ crates/horizon-client/src/mobs/anim.rs | 152 ++++++++++++++++++ crates/horizon-client/src/mobs/render.rs | 36 +++-- 4 files changed, 221 insertions(+), 11 deletions(-) diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs index bb463547f..e6ccb574f 100644 --- a/crates/horizon-client/src/game/perspective.rs +++ b/crates/horizon-client/src/game/perspective.rs @@ -313,6 +313,15 @@ impl Game<'_> { .map_or(25, |s| Self::charge_ticks(s).max(1)) as i32; let attack = (self.swing.old_animation, self.swing.animation); let swinging = self.swing.swinging(); + // currentSwing.hand().asArm(mainArm). + let swing_right_arm = swinging.then(|| { + (self.swing.attack_hand() == horizon_client::first_person::Hand::Main) + != self.settings.main_hand_left + }); + // LivingEntity.isVisuallySwimming and Entity.isInWater. + let visually_swimming = + p.pose == Pose::Swimming || (!p.fall_flying && p.pose == Pose::FallFlying); + let in_water = p.fluids.was_touching_water; let (yaw, pitch) = (self.yaw, self.pitch); let main = self.inventory[self.selected] .as_ref() @@ -378,6 +387,8 @@ impl Game<'_> { m.extra.charged = charged; m.extra.ints[5] = charge_duration; m.extra.elytra.tick(fall_flying, crouching, velocity); + m.extra.swim.tick(visually_swimming, in_water); + m.extra.swing_right_arm = swing_right_arm; m.hurt_time = hurt; } /// Whether the player's own model shows in the world view. diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 8b51593bc..c894cf471 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -690,6 +690,10 @@ pub struct Extra { pub fall_fly_ticks: i32, pub main_hand_left: bool, pub elytra: ElytraAnimation, + pub swim: SwimAnimation, + /// The arm the current swing moves (`currentSwing.hand().asArm`): `Some(true)` + /// for the right arm. + pub swing_right_arm: Option, pub flag: bool, pub flag2: bool, /// Species scratch values (the wither's head targets and clocks). @@ -2068,6 +2072,35 @@ impl ElytraAnimation { } } +/// `LivingEntity.swimAmount` and the render state the swimming pose reads +/// (`isVisuallySwimming`, `isInWater`). +#[derive(Clone, Copy, Debug, Default)] +pub struct SwimAnimation { + pub old: f32, + pub amount: f32, + /// `isVisuallySwimming`: in the swimming pose (or still in the gliding + /// pose after a glide ended). + pub visually: bool, + pub in_water: bool, +} +impl SwimAnimation { + /// `LivingEntity.updateSwimAmount`. + pub fn tick(&mut self, visually: bool, in_water: bool) { + self.old = self.amount; + self.amount = if visually { + (self.amount + 0.09).min(1.0) + } else { + (self.amount - 0.09).max(0.0) + }; + self.visually = visually; + self.in_water = in_water; + } + /// `LivingEntity.getSwimAmount`. + pub fn amount(&self, partial: f32) -> f32 { + self.old + partial * (self.amount - self.old) + } +} + #[cfg(test)] mod elytra_tests { use super::*; diff --git a/crates/horizon-client/src/mobs/anim.rs b/crates/horizon-client/src/mobs/anim.rs index 161db24f9..4f16dcffb 100644 --- a/crates/horizon-client/src/mobs/anim.rs +++ b/crates/horizon-client/src/mobs/anim.rs @@ -276,6 +276,12 @@ pub struct Hum { pub charge: (f32, f32), /// `PiglinModel.setupAttackAnimation`: swing a held weapon down. pub weapon_swing: bool, + /// `swimAmount` at this frame. + pub swim: f32, + /// `isUsingItem`: the swim stroke leaves the arms alone. + pub using_item: bool, + /// The arm the current swing moves (`Some(true)` for the right one). + pub swing_right_arm: Option, } impl Hum { pub fn new(right: ArmPose, left: ArmPose) -> Self { @@ -290,6 +296,9 @@ impl Hum { holding: false, charge: (0.0, 0.0), weapon_swing: false, + swim: 0.0, + using_item: false, + swing_right_arm: None, } } } @@ -455,6 +464,86 @@ pub(super) fn humanoid(p: &mut Poses, s: &State, h: &Hum) { } bob(p, "right_arm", s.age, 1.0); bob(p, "left_arm", s.age, -1.0); + if h.swim > 0.0 { + swim(p, s.pos, h); + } +} +/// `Mth.rotLerpRad`. +fn rot_lerp_rad(a: f32, from: f32, to: f32) -> f32 { + let mut diff = to - from; + while diff < -PI { + diff += PI * 2.0; + } + while diff >= PI { + diff -= PI * 2.0; + } + from + a * diff +} +/// `HumanoidModel.setupSwimAnimation`: the stroke of both arms over 26 +/// walk-animation units, the head down and a slow flutter kick. The left arm +/// eases the short way round, the right one linearly, as in vanilla. +fn swim(p: &mut Poses, pos: f32, h: &Hum) { + let amount = h.swim; + if !h.fall_flying { + let x = p.get("head")[3]; + p.xrot( + "head", + rot_lerp_rad(amount, x, -std::f32::consts::FRAC_PI_4), + ); + } + let swim_pos = pos % 26.0; + let right_amount = if h.swing_right_arm == Some(true) { + 0.0 + } else { + amount + }; + let left_amount = if h.swing_right_arm == Some(false) { + 0.0 + } else { + amount + }; + let lerp = |a: f32, from: f32, to: f32| from + a * (to - from); + let quadratic = |x: f32| -65.0 * x + x * x; + if !h.using_item { + // Targets (x, y, z) for the left and right arm. + let targets = if swim_pos < 14.0 { + let stroke = 1.870_796_4 * quadratic(swim_pos) / quadratic(14.0); + Some(([0.0, PI, PI + stroke], [0.0, PI, PI - stroke])) + } else if swim_pos < 22.0 { + let t = (swim_pos - 14.0) / 8.0; + let x = PI / 2.0 * t; + Some(( + [x, PI, 5.012_389 - 1.870_796_4 * t], + [x, PI, 1.270_796_3 + 1.870_796_4 * t], + )) + } else if swim_pos < 26.0 { + let t = (swim_pos - 22.0) / 4.0; + let x = PI / 2.0 - PI / 2.0 * t; + Some(([x, PI, PI], [x, PI, PI])) + } else { + None + }; + if let Some((left, right)) = targets { + for (i, target) in left.into_iter().enumerate() { + let angle = &mut p.get("left_arm")[3 + i]; + *angle = rot_lerp_rad(left_amount, *angle, target); + } + for (i, target) in right.into_iter().enumerate() { + let angle = &mut p.get("right_arm")[3 + i]; + *angle = lerp(right_amount, *angle, target); + } + } + } + let x = p.get("left_leg")[3]; + p.xrot( + "left_leg", + lerp(amount, x, 0.3 * (pos * 0.333_333_34 + PI).mcos()), + ); + let x = p.get("right_leg")[3]; + p.xrot( + "right_leg", + lerp(amount, x, 0.3 * (pos * 0.333_333_34).mcos()), + ); } /// Apply the mob's model animation to `p`. pub fn setup( @@ -580,6 +669,9 @@ pub fn setup( } h.crouching = m.extra.crouching; h.passenger = m.extra.passenger; + h.swim = m.extra.swim.amount(s.partial); + h.using_item = m.extra.using_item > 0; + h.swing_right_arm = m.extra.swing_right_arm; humanoid(p, s, &h); if m.ai.aggressive && !bow { // SkeletonModel melee pose. @@ -710,4 +802,64 @@ mod flight_pose_tests { assert_eq!(flight.get("head")[3], -std::f32::consts::FRAC_PI_4); assert_eq!(flight.get("right_leg")[3], ground.get("right_leg")[3] / 8.0); } + + #[test] + fn swimming_strokes_the_arms_and_kicks() { + let state = State { + pos: 7.0, + speed: 1.0, + age: 0.0, + y_rot: 0.0, + x_rot: 30.0, + swing: 0.0, + baby: false, + partial: 0.0, + }; + let make = || Poses { + map: ["head", "right_arm", "left_arm", "right_leg", "left_leg"] + .into_iter() + .map(|n| (n.to_string(), [0.0; 9])) + .collect(), + dummy: [0.0; 9], + skipped: Default::default(), + hidden: Default::default(), + }; + let same_angle = |a: f32, b: f32| ((a - b + PI).rem_euclid(PI * 2.0) - PI).abs() < 1e-5; + let mut h = Hum::new(ArmPose::Empty, ArmPose::Empty); + h.swim = 1.0; + let mut p = make(); + humanoid(&mut p, &state, &h); + // Mid-stroke: both arms sweep out from overhead by the quadratic. + let stroke = 1.870_796_4 * (-65.0 * 7.0 + 49.0) / (-65.0 * 14.0 + 196.0); + assert_eq!(p.get("right_arm")[5], PI - stroke); + assert!(same_angle(p.get("left_arm")[5], PI + stroke)); + assert_eq!(p.get("right_arm")[4], PI); + assert!(same_angle(p.get("head")[3], -std::f32::consts::FRAC_PI_4)); + assert!(same_angle( + p.get("right_leg")[3], + 0.3 * (7.0f32 * 0.333_333_34).mcos() + )); + // Using an item keeps the arms; a swing frees its own arm only. + let mut using = make(); + h.using_item = true; + humanoid(&mut using, &state, &h); + assert_eq!(using.get("right_arm")[4], 0.0); + h.using_item = false; + h.swing_right_arm = Some(true); + let mut swinging = make(); + humanoid( + &mut swinging, + &State { + swing: 0.5, + ..state + }, + &h, + ); + assert!(swinging.get("right_arm")[4] < 1.0); + assert!(same_angle(swinging.get("left_arm")[4], PI)); + // Out of the pose nothing changes. + let mut dry = make(); + humanoid(&mut dry, &state, &Hum::new(ArmPose::Empty, ArmPose::Empty)); + assert_eq!(dry.get("head")[3], 30.0f32.to_radians()); + } } diff --git a/crates/horizon-client/src/mobs/render.rs b/crates/horizon-client/src/mobs/render.rs index e8120e92e..21ab88aa3 100644 --- a/crates/horizon-client/src/mobs/render.rs +++ b/crates/horizon-client/src/mobs/render.rs @@ -765,6 +765,17 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4 .unwrap_or_else(|| glam::Mat4::from_rotation_y((180.0 - body).to_radians())), }; let mut base = origin * rotation; + if m.death_time > 0 && !super::creaking::tearing_down(m) { + let f = ((m.death_time as f32 + alpha - 1.0) / 20.0 * 1.6) + .sqrt() + .min(1.0); + base *= glam::Mat4::from_rotation_z(f * flip_degrees(m).to_radians()); + } else if matches!(m.custom_name.as_deref(), Some("Dinnerbone" | "Grumm")) { + // isEntityUpsideDown + base *= glam::Mat4::from_translation(glam::Vec3::new(0.0, m.height() + 0.1, 0.0)) + * glam::Mat4::from_rotation_z(PI); + } + // AvatarRenderer.setupRotations, after LivingEntityRenderer's. if m.extra.fall_flying { let ticks = m.extra.fall_fly_ticks as f32 + alpha; let scale = (ticks * ticks / 100.0).min(1.0); @@ -785,17 +796,20 @@ pub fn base_transform_at(m: &Mob, alpha: f32, origin: glam::Mat4) -> glam::Mat4 (sign * horizon_core::jmath::acos(dot.abs().min(1.0))) as f32, ); } - } - - if m.death_time > 0 && !super::creaking::tearing_down(m) { - let f = ((m.death_time as f32 + alpha - 1.0) / 20.0 * 1.6) - .sqrt() - .min(1.0); - base *= glam::Mat4::from_rotation_z(f * flip_degrees(m).to_radians()); - } else if matches!(m.custom_name.as_deref(), Some("Dinnerbone" | "Grumm")) { - // isEntityUpsideDown - base *= glam::Mat4::from_translation(glam::Vec3::new(0.0, m.height() + 0.1, 0.0)) - * glam::Mat4::from_rotation_z(PI); + } else if m.extra.swim.amount(alpha) > 0.0 { + // AvatarRenderer.setupRotations: tip forward with the swim amount, + // following the pitch in water, then lie along the swimming box. + let amount = m.extra.swim.amount(alpha); + let pitch = m.previous_head_pitch + (m.head_pitch - m.previous_head_pitch) * alpha; + let target = if m.extra.swim.in_water { + -90.0 - pitch + } else { + -90.0 + }; + base *= glam::Mat4::from_rotation_x((amount * target).to_radians()); + if m.extra.swim.visually { + base *= glam::Mat4::from_translation(glam::Vec3::new(0.0, -1.0, 0.3)); + } } base *= species_rotations(m, alpha); base *= glam::Mat4::from_scale(glam::Vec3::new(-1.0, -1.0, 1.0)); From 310047c225f6bc1022429136acf5eef3d6b606ea Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Sat, 17 Oct 2026 02:55:27 -0400 Subject: [PATCH 21/46] Allow render distances up to 64 chunks in settings and saved options --- .../horizon-client/examples/options_probe.rs | 12 ++++++++-- crates/horizon-client/src/options_file.rs | 2 +- crates/horizon-client/src/options_ui.rs | 23 +++++++++++++++++-- tools/test_options_parity.py | 7 ++++-- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/crates/horizon-client/examples/options_probe.rs b/crates/horizon-client/examples/options_probe.rs index 1cdf8c8fb..f186af994 100644 --- a/crates/horizon-client/examples/options_probe.rs +++ b/crates/horizon-client/examples/options_probe.rs @@ -1,7 +1,10 @@ #![forbid(unsafe_code)] //! Loads and saves option files like `Options.load`/`save`, for the //! differential harness (tools/test_options_parity.py). -use horizon_client::{Result, keybinds, options_file::OptionsFile}; +use horizon_client::{ + Result, keybinds, + options_file::{OptionsFile, V}, +}; use std::{fs, io::Write}; fn main() -> Result<()> { @@ -14,11 +17,16 @@ fn main() -> Result<()> { let mut first = true; for path in names { let name = path.file_name().unwrap().to_string_lossy().into_owned(); - let file = if name == "absent.txt" { + let mut file = if name == "absent.txt" { OptionsFile::default() } else { OptionsFile::parse(&String::from_utf8_lossy(&fs::read(&path)?)) }; + // Horizon extends the slider to 64; vanilla rejects 33..64 to its default. + // Compare that deliberate extension as vanilla would serialize it. + if file.int("renderDistance") > 32 { + file.set("renderDistance", V::Int(12)); + } write!(out, "== {name}\n{}", file.serialize())?; if first { first = false; diff --git a/crates/horizon-client/src/options_file.rs b/crates/horizon-client/src/options_file.rs index 339bb0fdf..49c94613f 100644 --- a/crates/horizon-client/src/options_file.rs +++ b/crates/horizon-client/src/options_file.rs @@ -159,7 +159,7 @@ static TABLE: LazyLock> = LazyLock::new(|| { b("reducedDebugInfo", false), def("renderClouds", O(Clouds), V::Int(2)), i("cloudRange", 2, 128, 128), - i("renderDistance", 2, 32, 12), + i("renderDistance", 2, 64, 12), i("simulationDistance", 5, 32, 12), u("screenEffectScale", 1.0), def("soundDevice", O(AnyStr), V::Str(String::new())), diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index fab36defa..dca180e15 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -190,7 +190,7 @@ impl Opt { let unit = |v: f32, lo: f32, hi: f32| Kind::Slider(((v - lo) / (hi - lo)).clamp(0.0, 1.0)); match self { Opt::Fov => unit(s.fov, 30.0, 110.0), - Opt::RenderDistance => unit(s.render_distance as f32, 2.0, 32.0), + Opt::RenderDistance => unit(s.render_distance as f32, 2.0, 64.0), Opt::SimulationDistance => unit(s.simulation_distance as f32, 5.0, 32.0), Opt::Sensitivity => Kind::Slider(s.sensitivity), Opt::WheelSensitivity => unit(s.mouse_wheel_sensitivity, 0.01, 10.0), @@ -484,7 +484,7 @@ impl Opt { let step = |lo: f32, hi: f32| (lo + v * (hi - lo)).round(); match self { Opt::Fov => s.fov = step(30.0, 110.0), - Opt::RenderDistance => s.render_distance = step(2.0, 32.0) as i32, + Opt::RenderDistance => s.render_distance = step(2.0, 64.0) as i32, Opt::SimulationDistance => s.simulation_distance = step(5.0, 32.0) as i32, Opt::Sensitivity => s.sensitivity = v, Opt::WheelSensitivity => s.mouse_wheel_sensitivity = 0.01 + v * 9.99, @@ -2356,6 +2356,25 @@ mod tests { use super::*; use crate::ui_theme::{MenuStyle, set_style, style}; + #[test] + fn render_distance_slider_round_trips_through_extended_options_range() { + let mut s = Settings::default(); + for (position, distance) in [(0.0, 2), (0.5, 33), (1.0, 64)] { + set_slider(Opt::RenderDistance, &mut s, position); + assert_eq!(s.render_distance, distance); + let reloaded = Settings::parse(&s.serialize()); + assert_eq!(reloaded.render_distance, distance); + assert_eq!( + Opt::RenderDistance.slider_position(&reloaded), + Some(position) + ); + } + let mut file = crate::options_file::OptionsFile::default(); + file.set_text("renderDistance", "64").unwrap(); + assert!(file.set_text("renderDistance", "65").is_err()); + assert!(file.set_text("renderDistance", "1").is_err()); + assert_eq!(file.int("renderDistance"), 64); + } fn atlas() -> HudAtlas { HudAtlas::build(std::path::Path::new("/nonexistent/horizon-test-assets")).unwrap() } diff --git a/tools/test_options_parity.py b/tools/test_options_parity.py index 95732663d..cf7698e5c 100644 --- a/tools/test_options_parity.py +++ b/tools/test_options_parity.py @@ -1,7 +1,9 @@ #!/usr/bin/env python3 """Compare options.txt loading and saving, and the key mapping table, with the pinned client: every file is loaded through the real Options.load and written -back with Options.save, and the Rust port must produce identical text.""" +back with Options.save. The Rust probe normalizes Horizon's intentional 33..64 +render-distance extension to vanilla's default; a Rust slider/persistence +regression covers the extended range.""" from pathlib import Path import random import shutil @@ -182,7 +184,8 @@ def main(): 'fields, lenient Gson parsing and syntax-error aborts, key mappings (names, scancode-number forms, unbinding), ' 'sound volumes, model parts, line endings, the OPTIONS data fixers across version boundaries, and the ' 'KeyMapping table (order, defaults, categories, toggle mappings). Does not cover option screens or ' - 'runtime side effects of setting an option.') + 'runtime side effects of setting an option. Horizon render distances 33..64 are normalized to vanilla\'s ' + 'default by options_probe; the slider/persistence unit regression checks that intentional extension.') harness.differential( 'rust-options-parity', 'VanillaOptionsOracle', 'options_probe', make_cases, scope, sources=[lab.ROOT / 'crates/horizon-client/src/options_file.rs', lab.ROOT / 'crates/horizon-client/src/options_fixes.rs', From f48a54da095686cdf5f1088e13e0f5731db0f66e Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 07:36:40 +0200 Subject: [PATCH 22/46] Block state ids past 16 bits Chunk sections keep block states as u32 and size the global palette to the registry: 16 bits for vanilla's 35,723 states, wider when content mods take the registry past 65,536. The content-mod limit goes from 2^16 to 2^20 states. The LAN host writes chunks at the registry's width, so with vanilla (or mods within 16 bits) the wire is unchanged. Remote chunks are read at the server's width, 16 from a vanilla server, and widened to ours. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/examples/lan_flat.rs | 7 +-- .../horizon-client/examples/light_parity.rs | 6 +- .../examples/random_tick_eligibility_bench.rs | 8 +-- .../examples/save_batch_bench.rs | 4 +- crates/horizon-client/examples/save_parity.rs | 4 +- .../examples/section_mesh_fixture.rs | 2 +- crates/horizon-client/src/assets.rs | 3 + crates/horizon-client/src/chunk.rs | 62 ++++++++++++------- crates/horizon-client/src/chunk_map.rs | 2 +- crates/horizon-client/src/flatgen.rs | 4 +- crates/horizon-client/src/game.rs | 2 +- crates/horizon-client/src/game/commands.rs | 11 ++-- crates/horizon-client/src/game/creaking.rs | 2 +- crates/horizon-client/src/game/lan.rs | 4 +- .../src/game/natural_spawning.rs | 2 +- crates/horizon-client/src/game/remote.rs | 25 ++++++-- crates/horizon-client/src/game/sculk.rs | 14 ++--- crates/horizon-client/src/lan/chunks.rs | 26 ++++---- crates/horizon-client/src/lan/containers.rs | 4 +- crates/horizon-client/src/lan/hub.rs | 4 +- crates/horizon-client/src/light.rs | 24 +++---- crates/horizon-client/src/mesher.rs | 21 +++---- crates/horizon-client/src/mesher/fluid.rs | 12 ++-- .../src/mesher/leaf_culling_tests.rs | 6 +- .../src/mesher/visibility_tests.rs | 2 +- crates/horizon-client/src/minimap.rs | 14 ++--- crates/horizon-client/src/mod_content.rs | 10 +-- .../horizon-client/src/mod_content_tests.rs | 28 +++++++-- crates/horizon-client/src/poi_sections.rs | 4 +- .../src/random_tick_sections.rs | 13 ++-- crates/horizon-client/src/save.rs | 19 +++--- crates/horizon-client/src/testgen.rs | 24 +++---- crates/horizon-client/src/vanillagen.rs | 4 +- crates/horizon-client/src/world.rs | 17 +++-- crates/horizon-client/tests/lan_bot.rs | 10 +-- .../horizon-client/tests/streaming_meshes.rs | 8 +-- crates/horizon-client/tests/wide_states.rs | 40 ++++++++++++ 37 files changed, 265 insertions(+), 187 deletions(-) create mode 100644 crates/horizon-client/tests/wide_states.rs diff --git a/crates/horizon-client/examples/lan_flat.rs b/crates/horizon-client/examples/lan_flat.rs index 16fc36b95..a86a4d82e 100644 --- a/crates/horizon-client/examples/lan_flat.rs +++ b/crates/horizon-client/examples/lan_flat.rs @@ -22,12 +22,7 @@ fn main() -> Result<(), Box> { let port: u16 = args.next().ok_or("port")?.parse()?; let assets = Assets::load(&root)?; let facts = BlockFacts::load(&root, assets.registry)?; - let state = |name: &str| { - assets - .registry - .default_state(name) - .map_or(0, |s| s.0 as u16) - }; + let state = |name: &str| assets.registry.default_state(name).map_or(0, |s| s.0); let sync = Arc::new(SyncData::load(&root)?); let biomes: Vec = sync .dynamic diff --git a/crates/horizon-client/examples/light_parity.rs b/crates/horizon-client/examples/light_parity.rs index afc3e3156..29488130e 100644 --- a/crates/horizon-client/examples/light_parity.rs +++ b/crates/horizon-client/examples/light_parity.rs @@ -232,7 +232,7 @@ fn incremental( c.lit = true; world.insert((x, z), Arc::new(c)); } - let palette: Vec = [ + let palette: Vec = [ "minecraft:air", "minecraft:stone", "minecraft:torch", @@ -242,7 +242,7 @@ fn incremental( "minecraft:glass", ] .iter() - .filter_map(|n| registry.default_state(n).map(|s| s.0 as u16)) + .filter_map(|n| registry.default_state(n).map(|s| s.0)) .chain( facts .states @@ -257,7 +257,7 @@ fn incremental( ] .contains(&&*f.name) }) - .map(|(i, _)| i as u16) + .map(|(i, _)| i as u32) .step_by(3), ) .collect(); diff --git a/crates/horizon-client/examples/random_tick_eligibility_bench.rs b/crates/horizon-client/examples/random_tick_eligibility_bench.rs index 856d7d520..49c32a8f7 100644 --- a/crates/horizon-client/examples/random_tick_eligibility_bench.rs +++ b/crates/horizon-client/examples/random_tick_eligibility_bench.rs @@ -56,16 +56,16 @@ fn main() -> horizon_client::Result<()> { "resource_load_ms={:.3}", start.elapsed().as_secs_f64() * 1000.0 ); - let inactive: Vec = facts + let inactive: Vec = facts .states .iter() .enumerate() .filter(|(_, f)| !f.random_ticks) .take(128) - .map(|(i, _)| i as u16) + .map(|(i, _)| i as u32) .collect(); - let active = registry.default_state("minecraft:grass_block").unwrap().0 as u16; - assert!(facts.get(BlockStateId(u32::from(active))).random_ticks); + let active = registry.default_state("minecraft:grass_block").unwrap().0; + assert!(facts.get(BlockStateId(active)).random_ticks); for (name, palette) in [("sparse", 1), ("dense", 128)] { let start = Instant::now(); let mut chunks = FxHashMap::default(); diff --git a/crates/horizon-client/examples/save_batch_bench.rs b/crates/horizon-client/examples/save_batch_bench.rs index 11c4f64ed..4ee5103de 100644 --- a/crates/horizon-client/examples/save_batch_bench.rs +++ b/crates/horizon-client/examples/save_batch_bench.rs @@ -4,7 +4,7 @@ //! Exact NBT equality is always validated. No GPU, compression or disk I/O timed. use horizon_client::{ biome::Biomes, - chunk::{BLOCK_STRATEGY, Chunk}, + chunk::{Chunk, block_strategy}, containers::BlockEntity, items::ItemStack, save::{self, ChunkExtras}, @@ -64,7 +64,7 @@ fn fixture(per_chunk: usize) -> (Vec>, Entities, Names) { }; let mut template = Chunk::empty(0, 0); for s in &mut template.sections[..8] { - Arc::make_mut(s).blocks = PalettedContainer::new(BLOCK_STRATEGY, 1); + Arc::make_mut(s).blocks = PalettedContainer::new(block_strategy(), 1); } template.heights = Arc::new([64; 256]); for i in 0..256 { diff --git a/crates/horizon-client/examples/save_parity.rs b/crates/horizon-client/examples/save_parity.rs index ba2c4b0fa..3954e3bb3 100644 --- a/crates/horizon-client/examples/save_parity.rs +++ b/crates/horizon-client/examples/save_parity.rs @@ -257,9 +257,9 @@ fn main() -> horizon_client::Result<()> { ); Ok(()) } -fn tables_air(assets: &Assets) -> u16 { +fn tables_air(assets: &Assets) -> u32 { assets .registry .default_state("minecraft:air") - .map_or(0, |s| s.0 as u16) + .map_or(0, |s| s.0) } diff --git a/crates/horizon-client/examples/section_mesh_fixture.rs b/crates/horizon-client/examples/section_mesh_fixture.rs index a42448794..6359f32d0 100644 --- a/crates/horizon-client/examples/section_mesh_fixture.rs +++ b/crates/horizon-client/examples/section_mesh_fixture.rs @@ -83,7 +83,7 @@ fn scene( for block in row["blocks"].as_array().ok_or("missing blocks")? { let (x, y, z) = (int(&block[0])?, int(&block[1])?, int(&block[2])?); let i = chunk_index(x, z)?; - chunks[i].set(x & 15, y, z & 15, u16::try_from(int(&block[3])?)?); + chunks[i].set(x & 15, y, z & 15, u32::try_from(int(&block[3])?)?); } for cell in row["lights"].as_array().ok_or("missing lights")? { let (x, y, z) = (int(&cell[0])?, int(&cell[1])?, int(&cell[2])?); diff --git a/crates/horizon-client/src/assets.rs b/crates/horizon-client/src/assets.rs index b8551a059..f278740f5 100644 --- a/crates/horizon-client/src/assets.rs +++ b/crates/horizon-client/src/assets.rs @@ -189,6 +189,9 @@ impl Assets { .default_state(&format!("minecraft:{name}")) .ok_or_else(|| invalid("missing test-scene material"))?; } + // Chunks hold every state of this registry: content mods can take it + // past vanilla's 16-bit global palette. + crate::chunk::set_block_states(registry.len()); let registry: &'static BlockRegistry = Box::leak(Box::new(registry)); Self::with_models( root, diff --git a/crates/horizon-client/src/chunk.rs b/crates/horizon-client/src/chunk.rs index b0b2ef262..ce2c4ea71 100644 --- a/crates/horizon-client/src/chunk.rs +++ b/crates/horizon-client/src/chunk.rs @@ -9,11 +9,26 @@ pub const MIN_Y: i32 = -64; pub const HEIGHT: i32 = 384; pub const SECTIONS: usize = (HEIGHT / 16) as usize; -/// Block states are `PalettedContainer`s over the pinned registry (35,723 -/// states: a 16-bit global palette); biomes are 4x4x4 containers over the -/// biome table (67 entries: a 7-bit global palette). -pub const BLOCK_STRATEGY: Strategy = Strategy::blocks(16); +/// Biomes are 4x4x4 containers over the biome table (67 entries: a 7-bit +/// global palette). pub const BIOME_STRATEGY: Strategy = Strategy::biomes(7); + +/// Bits of the block states' global palette: 16 for vanilla's 35,723 states +/// (what vanilla servers and clients send), more when content mods add states +/// past 65,536 (docs/modpacks.md). Set once, before the first chunk. +static BLOCK_BITS: std::sync::atomic::AtomicU8 = std::sync::atomic::AtomicU8::new(16); + +/// Block states are `PalettedContainer`s over the registry: vanilla's 16-bit +/// global palette, wider with enough content mods. +pub fn block_strategy() -> Strategy { + Strategy::blocks(BLOCK_BITS.load(std::sync::atomic::Ordering::Relaxed)) +} + +/// Sizes the block states' global palette for a registry of `states`. +pub fn set_block_states(states: usize) { + let bits = horizon_core::paletted::ceil_log2(states).max(16); + BLOCK_BITS.store(bits, std::sync::atomic::Ordering::Relaxed); +} /// Packed light per block: sky light in the high nibble, block light in the low one. #[derive(Clone)] pub enum Light { @@ -43,7 +58,7 @@ pub struct Section { impl Default for Section { fn default() -> Self { Self { - blocks: PalettedContainer::new(BLOCK_STRATEGY, 0), + blocks: PalettedContainer::new(block_strategy(), 0), biomes: PalettedContainer::new(BIOME_STRATEGY, 0), light: Light::Uniform(0xF0), } @@ -51,27 +66,26 @@ impl Default for Section { } impl Section { #[inline] - pub fn get(&self, i: usize) -> u16 { - self.blocks.get(i) as u16 + pub fn get(&self, i: usize) -> u32 { + self.blocks.get(i) } - pub fn set(&mut self, i: usize, v: u16) -> u16 { - self.blocks.set(i, u32::from(v)) as u16 + pub fn set(&mut self, i: usize, v: u32) -> u32 { + self.blocks.set(i, v) } /// All 4,096 block states in index order. - pub fn unpack(&self, out: &mut [u16; 4096]) { - self.blocks.unpack_u16(out); + pub fn unpack(&self, out: &mut [u32; 4096]) { + self.blocks.unpack(out); } /// The block states of a whole section at once. - pub fn from_blocks(values: &[u16; 4096]) -> PalettedContainer { - let wide: Vec = values.iter().map(|&v| u32::from(v)).collect(); - PalettedContainer::from_values(BLOCK_STRATEGY, &wide) + pub fn from_blocks(values: &[u32; 4096]) -> PalettedContainer { + PalettedContainer::from_values(block_strategy(), values) } #[inline] pub fn light(&self, i: usize) -> u8 { self.light.get(i) } - pub fn is_uniform(&self, v: u16) -> bool { - self.blocks.is_uniform(u32::from(v)) + pub fn is_uniform(&self, v: u32) -> bool { + self.blocks.is_uniform(v) } /// Heap bytes held by the block, biome and light storage (benchmark accounting). pub fn heap_bytes(&self) -> usize { @@ -147,7 +161,7 @@ impl Chunk { } } #[inline] - pub fn get(&self, x: i32, y: i32, z: i32) -> u16 { + pub fn get(&self, x: i32, y: i32, z: i32) -> u32 { let s = (y - MIN_Y) >> 4; if !(0..SECTIONS as i32).contains(&s) { return 0; @@ -156,11 +170,11 @@ impl Chunk { } #[inline] pub fn block(&self, x: i32, y: i32, z: i32) -> BlockStateId { - BlockStateId(u32::from(self.get(x, y, z))) + BlockStateId(self.get(x, y, z)) } /// The highest y where `matches`, scanning down. Sections holding only /// `skip` are passed over whole: `matches` must be false for it. - pub fn highest(&self, skip: u16, mut matches: impl FnMut(i32) -> bool) -> Option { + pub fn highest(&self, skip: u32, mut matches: impl FnMut(i32) -> bool) -> Option { self.sections .iter() .enumerate() @@ -171,7 +185,7 @@ impl Chunk { (base..base + 16).rev().find(|&y| matches(y)) }) } - pub fn set(&mut self, x: i32, y: i32, z: i32, v: u16) -> u16 { + pub fn set(&mut self, x: i32, y: i32, z: i32, v: u32) -> u32 { let s = (y - MIN_Y) >> 4; if !(0..SECTIONS as i32).contains(&s) { return v; @@ -228,15 +242,15 @@ mod tests { Arc::make_mut(&mut chunk.sections[5]).set(i, cave_air); } chunk.set(3, 150, 4, stone); - let full = |c: &Chunk, matches: &dyn Fn(u16) -> bool| { + let full = |c: &Chunk, matches: &dyn Fn(u32) -> bool| { (MIN_Y..MIN_Y + HEIGHT) .rev() .find(|&y| matches(c.get(3, y, 4))) }; for matches in [ - &(|v: u16| v != air) as &dyn Fn(u16) -> bool, - &|v: u16| v == stone, - &|v: u16| v == cave_air, + &(|v: u32| v != air) as &dyn Fn(u32) -> bool, + &|v: u32| v == stone, + &|v: u32| v == cave_air, ] { let fast = chunk.highest(air, |y| matches(chunk.get(3, y, 4))); assert_eq!(fast, full(&chunk, matches)); diff --git a/crates/horizon-client/src/chunk_map.rs b/crates/horizon-client/src/chunk_map.rs index 81e06f020..ed25491c5 100644 --- a/crates/horizon-client/src/chunk_map.rs +++ b/crates/horizon-client/src/chunk_map.rs @@ -76,7 +76,7 @@ impl<'a> IntoIterator for &'a ChunkMap { } } impl crate::light::LightWorld for ChunkMap { - fn state(&self, x: i32, y: i32, z: i32) -> Option { + fn state(&self, x: i32, y: i32, z: i32) -> Option { self.columns.state(x, y, z) } fn light(&self, x: i32, y: i32, z: i32) -> Option { diff --git a/crates/horizon-client/src/flatgen.rs b/crates/horizon-client/src/flatgen.rs index d7764c30e..edf601768 100644 --- a/crates/horizon-client/src/flatgen.rs +++ b/crates/horizon-client/src/flatgen.rs @@ -4,7 +4,7 @@ use horizon_world::{nbt::Tag, registry::BlockRegistry}; /// The layers of a flat generator, bottom up from the world's minimum Y. pub struct FlatTerrain { - layers: Vec, + layers: Vec, biome: u16, } impl FlatTerrain { @@ -30,7 +30,7 @@ impl FlatTerrain { for layer in list { let block = crate::save::text(layer.get("block"))?; let height = crate::save::number(layer.get("height")).unwrap_or(0).max(0); - let state = registry.default_state(&block)?.0 as u16; + let state = registry.default_state(&block)?.0; layers.extend(std::iter::repeat_n(state, height as usize)); } } diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 117b83bc5..82fe39ae1 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -1122,7 +1122,7 @@ struct Game<'a> { lan_events: Vec<(i32, [i32; 3], i32, Option)>, /// Block events (position, b0, b1, state) and entity events (id, event, /// position) for the guests. - lan_block_events: Vec<([i32; 3], i32, i32, u16)>, + lan_block_events: Vec<([i32; 3], i32, i32, u32)>, lan_entity_events: Vec<(i32, i8, [f64; 3])>, /// `ContainerOpenersCounter`: how many players (the host and the guests) /// have each chest open. diff --git a/crates/horizon-client/src/game/commands.rs b/crates/horizon-client/src/game/commands.rs index 6c4817f63..962075ee7 100644 --- a/crates/horizon-client/src/game/commands.rs +++ b/crates/horizon-client/src/game/commands.rs @@ -2312,7 +2312,7 @@ impl Game<'_> { }; let from = self.source_position().map(|v| v.floor() as i32); const RANGE: i32 = 256; - let mut cache: std::collections::HashMap> = + let mut cache: std::collections::HashMap> = std::collections::HashMap::new(); let mut best: Option<(i64, [i32; 3], &'static str)> = None; let (cx0, cz0) = ((from[0] - RANGE) >> 4, (from[2] - RANGE) >> 4); @@ -2323,15 +2323,12 @@ impl Game<'_> { continue; }; for (i, section) in chunk.sections.iter().enumerate() { - let mut wanted_state = |v: u32| { - let state = v as u16; + let mut wanted_state = |state: u32| { cache .entry(state) .or_insert_with(|| { - self.poi_type(horizon_world::registry::BlockStateId(u32::from( - state, - ))) - .filter(|t| wanted.iter().any(|w| w == t)) + self.poi_type(horizon_world::registry::BlockStateId(state)) + .filter(|t| wanted.iter().any(|w| w == t)) }) .is_some() }; diff --git a/crates/horizon-client/src/game/creaking.rs b/crates/horizon-client/src/game/creaking.rs index 1caa419ff..b079545e6 100644 --- a/crates/horizon-client/src/game/creaking.rs +++ b/crates/horizon-client/src/game/creaking.rs @@ -333,7 +333,7 @@ impl Game<'_> { } for i in 0..4096 { let id = section.get(i); - if !hearts.get(usize::from(id)).copied().unwrap_or(false) { + if !hearts.get(id as usize).copied().unwrap_or(false) { continue; } let (lx, lz, ly) = ((i & 15) as i32, ((i >> 4) & 15) as i32, (i >> 8) as i32); diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index f6fc1e860..7fe4278c5 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -258,7 +258,7 @@ fn mob_meta(m: &Mob, hub: &Hub) -> Vec<(u8, i32, Value)> { meta.push(( 16, serializer::OPTIONAL_BLOCK_STATE, - Value::Id(i32::from(state.0 as u16)), + Value::Id(state.0 as i32), )); } } @@ -859,7 +859,7 @@ impl Game<'_> { /// `Level.blockEvent` for the guests (`ClientboundBlockEventPacket`). pub(super) fn lan_block_event(&mut self, pos: [i32; 3], b0: i32, b1: i32) { if self.audio.capture.is_some() { - let state = self.world.block(pos[0], pos[1], pos[2]).0 as u16; + let state = self.world.block(pos[0], pos[1], pos[2]).0; self.lan_block_events.push((pos, b0, b1, state)); } } diff --git a/crates/horizon-client/src/game/natural_spawning.rs b/crates/horizon-client/src/game/natural_spawning.rs index 571bbf5e0..80d26a823 100644 --- a/crates/horizon-client/src/game/natural_spawning.rs +++ b/crates/horizon-client/src/game/natural_spawning.rs @@ -206,7 +206,7 @@ impl NaturalLevel for GameLevel<'_, '_> { .chunks .get(&(x >> 4, z >> 4)) .and_then(|chunk| { - chunk.highest(world.air.0 as u16, |y| { + chunk.highest(world.air.0, |y| { spawn_selection::heightmap_blocks(self, kind, x, y, z) }) }) diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index f066c9755..5b026171f 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -9,7 +9,7 @@ use super::{Dim, Game, Mining, Screen}; use horizon_client::{ Result, - chunk::{BIOME_STRATEGY, BLOCK_STRATEGY, Chunk, Light, MIN_Y, SECTIONS, Section}, + chunk::{BIOME_STRATEGY, Chunk, Light, MIN_Y, SECTIONS, Section, block_strategy}, containers::{BlockEntity, Furnace, FurnaceKind}, entities::{Experience, ItemEntity}, hud::{HudBatch, rgba}, @@ -22,7 +22,11 @@ use horizon_client::{ streaming::{ChunkGenerator, Proto, Streaming}, world::World, }; -use horizon_core::{geometry::Vec3, paletted::PalettedContainer, random::RandomSource}; +use horizon_core::{ + geometry::Vec3, + paletted::{PalettedContainer, Strategy}, + random::RandomSource, +}; use horizon_protocol::{ entity_data::{ITEM_ENTITY_ITEM, Value}, item::{Hashed, Stack}, @@ -624,11 +628,24 @@ impl Game<'_> { if !(0..SECTIONS as i32).contains(&target) { continue; } - let strategy = BLOCK_STRATEGY; + // A global section is as wide as the server's registry: 16 bits + // from a vanilla server, wider from a Horizon host with the same + // content mods. Read it at that width, then widen it to ours. + let ours = block_strategy(); + let strategy = if ours.wire_has_palette(s.states.bits) { + ours + } else { + Strategy::blocks(s.states.bits) + }; let palette = s.states.palette.iter().map(|&p| p as u32).collect(); let words = s.states.data.iter().map(|&w| w as u64).collect(); - let blocks = PalettedContainer::from_wire(strategy, s.states.bits, palette, words) + let mut blocks = PalettedContainer::from_wire(strategy, s.states.bits, palette, words) .map_err(|e| e.to_string())?; + if strategy.global_bits != ours.global_bits { + let mut values = [0u32; 4096]; + blocks.unpack(&mut values); + blocks = PalettedContainer::from_values(ours, &values); + } let mut section = Section { blocks, biomes: PalettedContainer::from_values(BIOME_STRATEGY, &cells), diff --git a/crates/horizon-client/src/game/sculk.rs b/crates/horizon-client/src/game/sculk.rs index 6701181e7..e5de3e33c 100644 --- a/crates/horizon-client/src/game/sculk.rs +++ b/crates/horizon-client/src/game/sculk.rs @@ -301,11 +301,11 @@ impl Game<'_> { self.world.watched = t.kinds.iter().map(|k| *k != 0).collect(); self.sculk.tables = t; } - fn kind_of_state(&self, state: u16) -> u8 { + fn kind_of_state(&self, state: u32) -> u8 { self.sculk .tables .kinds - .get(usize::from(state)) + .get(state as usize) .copied() .unwrap_or(0) } @@ -345,10 +345,10 @@ impl Game<'_> { // SculkShriekerBlockEntity.preRemoveSideEffects. if old_kind == KIND_SHRIEKER && let Some(BlockEntity::Sculk(e)) = self.world.block_entities.get(&key) - && self.shrieker_shrieking(BlockStateId(u32::from(old))) + && self.shrieker_shrieking(BlockStateId(old)) { let warning = e.warning_level; - self.shrieker_respond(key, BlockStateId(u32::from(old)), warning); + self.shrieker_respond(key, BlockStateId(old), warning); } if matches!( self.world.block_entities.get(&key), @@ -377,7 +377,7 @@ impl Game<'_> { // A uniform section of sculk blocks does not exist. continue; } - let mut a = [0u16; 4096]; + let mut a = [0u32; 4096]; section.unpack(&mut a); for (i, v) in a.iter().enumerate() { if self.kind_of_state(*v) != 0 { @@ -847,12 +847,12 @@ impl Game<'_> { let state = self.world.block(key.0, key.1, key.2); let is_warden = matches!(who, Who::Mob(id) if self.mobs.iter().any(|m| m.id == id && m.species() == Species::Warden)); - match self.kind_of_state(state.0 as u16) { + match self.kind_of_state(state.0) { KIND_SENSOR | KIND_CALIBRATED => { if is_warden || !self.res.behaviours.sculk_sensor_can_activate(state) { continue; } - let calibrated = self.kind_of_state(state.0 as u16) == KIND_CALIBRATED; + let calibrated = self.kind_of_state(state.0) == KIND_CALIBRATED; if calibrated { let back = self.calibrated_signal(key); if back != 0 && back != 1 { diff --git a/crates/horizon-client/src/lan/chunks.rs b/crates/horizon-client/src/lan/chunks.rs index 6ca321edd..6751524f7 100644 --- a/crates/horizon-client/src/lan/chunks.rs +++ b/crates/horizon-client/src/lan/chunks.rs @@ -145,23 +145,23 @@ impl ChunkEncoder { tables: None, } } - pub fn entity_type(&self, state: u16) -> Option { + pub fn entity_type(&self, state: u32) -> Option { self.entity_types - .get(usize::from(state)) + .get(state as usize) .filter(|t| **t >= 0) .map(|t| i32::from(*t)) } - pub fn is_air(&self, state: u16) -> bool { + pub fn is_air(&self, state: u32) -> bool { self.flags - .get(usize::from(state)) + .get(state as usize) .is_none_or(|f| f & NON_AIR == 0) } fn section(&self, section: &Section) -> (horizon_protocol::chunk::Section, bool) { let mut values = Vec::with_capacity(BLOCKS); let (mut non_empty, mut fluids, mut entities) = (0i16, 0i16, false); - let mut count = |state: u16, n: i16| { - let f = self.flags.get(usize::from(state)).copied().unwrap_or(0); + let mut count = |state: u32, n: i16| { + let f = self.flags.get(state as usize).copied().unwrap_or(0); if f & NON_AIR != 0 { non_empty += n; if f & FLUID != 0 { @@ -170,11 +170,11 @@ impl ChunkEncoder { } f & ENTITY != 0 }; - let mut unpacked = [0u16; BLOCKS]; + let mut unpacked = [0u32; BLOCKS]; section.unpack(&mut unpacked); for &v in &unpacked { entities |= count(v, 1); - values.push(i32::from(v)); + values.push(v as i32); } let biome_values: Vec = (0..BIOMES) .map(|j| { @@ -189,7 +189,11 @@ impl ChunkEncoder { horizon_protocol::chunk::Section { non_empty, fluids, - states: Paletted::from_values(&values, Strategy::Blocks, 16), + states: Paletted::from_values( + &values, + Strategy::Blocks, + crate::chunk::block_strategy().global_bits, + ), biomes: Paletted::from_values(&biome_values, Strategy::Biomes, self.biome_bits), }, entities, @@ -201,11 +205,11 @@ impl ChunkEncoder { fn occupied(&self, chunk: &Chunk) -> u64 { let mut bits = 0u64; for (i, s) in chunk.sections.iter().enumerate() { - let mut unpacked = [0u16; BLOCKS]; + let mut unpacked = [0u32; BLOCKS]; s.unpack(&mut unpacked); let any = unpacked .iter() - .any(|&v| self.flags.get(usize::from(v)).copied().unwrap_or(0) & NON_AIR != 0); + .any(|&v| self.flags.get(v as usize).copied().unwrap_or(0) & NON_AIR != 0); if any { bits |= 1 << i; } diff --git a/crates/horizon-client/src/lan/containers.rs b/crates/horizon-client/src/lan/containers.rs index 0fa47510a..04c57afd2 100644 --- a/crates/horizon-client/src/lan/containers.rs +++ b/crates/horizon-client/src/lan/containers.rs @@ -79,11 +79,11 @@ impl Hub { } /// ClientboundBlockEventPacket (`PlayerList.broadcast` within 64 blocks). - pub fn block_event(&self, pos: [i32; 3], b0: i32, b1: i32, state: u16) { + pub fn block_event(&self, pos: [i32; 3], b0: i32, b1: i32, state: u32) { let block = self .encoder .block_ids - .get(usize::from(state)) + .get(state as usize) .copied() .unwrap_or(0); let at = [f64::from(pos[0]), f64::from(pos[1]), f64::from(pos[2])]; diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index e9255d822..c7b5a4ff2 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -1157,7 +1157,7 @@ impl Hub { let (x, y, z) = positions[0]; C::BlockUpdate(play::BlockUpdate { pos: [x, y, z], - state: i32::from(world.block(x, y, z).0 as u16), + state: world.block(x, y, z).0 as i32, }) } else { C::SectionBlocksUpdate(play::SectionBlocksUpdate { @@ -1186,7 +1186,7 @@ impl Hub { let Some(tag) = super::chunks::entity_tag(entity) else { continue; }; - let state = world.block(x, y, z).0 as u16; + let state = world.block(x, y, z).0; let Some(kind) = self.encoder.entity_type(state) else { continue; }; diff --git a/crates/horizon-client/src/light.rs b/crates/horizon-client/src/light.rs index fd271f40f..595efd9b2 100644 --- a/crates/horizon-client/src/light.rs +++ b/crates/horizon-client/src/light.rs @@ -165,14 +165,14 @@ impl LightTables { fn edge_occluded(&self, top: usize, bottom: usize) -> bool { self.cells[bottom].dampening != 0 || self.blocked(top, bottom, Direction::Down as usize) } - pub fn emission(&self, state: u16) -> u8 { + pub fn emission(&self, state: u32) -> u8 { self.cells[state as usize].emission } - pub fn dampening(&self, state: u16) -> u8 { + pub fn dampening(&self, state: u32) -> u8 { self.cells[state as usize].dampening } /// Whether a state change can change light (`hasDifferentLightProperties`). - pub fn differs(&self, old: u16, new: u16) -> bool { + pub fn differs(&self, old: u32, new: u32) -> bool { let (a, b) = (&self.cells[old as usize], &self.cells[new as usize]); old != new && (a.dampening != b.dampening || a.emission != b.emission || a.shaped || b.shaped) @@ -211,12 +211,12 @@ pub fn light_chunk( // up to 14 blocks into it (sky light there is always 15). let h = ((top_section + 1) * 16).min(HEIGHT as usize); let at = |x: usize, y: usize, z: usize| (y * W + z) * W + x; - let mut states = vec![0u16; W * W * h]; + let mut states = vec![0u32; W * W * h]; let mut sky = vec![0u8; W * W * h]; let mut block = vec![0u8; W * W * h]; let mut queue = VecDeque::new(); let mut sky_queue = VecDeque::new(); - let mut ids = Box::new([0u16; 4096]); + let mut ids = Box::new([0u32; 4096]); for (dz, row) in region.iter().enumerate() { for (dx, chunk) in row.iter().enumerate() { let Some(chunk) = chunk else { continue }; @@ -391,13 +391,13 @@ pub fn apply_relighting(chunk: &mut Chunk, lights: Vec) -> Vec<(i32, i32, /// Resident chunks the incremental relighter reads and writes. pub trait LightWorld { - fn state(&self, x: i32, y: i32, z: i32) -> Option; + fn state(&self, x: i32, y: i32, z: i32) -> Option; /// Packed light (sky << 4 | block), None outside loaded chunks. fn light(&self, x: i32, y: i32, z: i32) -> Option; fn set_light(&mut self, x: i32, y: i32, z: i32, packed: u8); } impl LightWorld for HashMap<(i32, i32), Arc, S> { - fn state(&self, x: i32, y: i32, z: i32) -> Option { + fn state(&self, x: i32, y: i32, z: i32) -> Option { if !(MIN_Y..MIN_Y + HEIGHT).contains(&y) { return None; } @@ -611,10 +611,10 @@ fn relight_layer( mod tests { use super::*; - const AIR: u16 = 0; - const STONE: u16 = 1; - const TORCH: u16 = 2; - const SLAB: u16 = 3; + const AIR: u32 = 0; + const STONE: u32 = 1; + const TORCH: u32 = 2; + const SLAB: u32 = 3; /// Air, stone, torch and a bottom slab (full bottom face, half sides, /// empty top), with a third face shape for the half sides. fn tables() -> LightTables { @@ -889,7 +889,7 @@ mod tests { for (si, s) in fixture.sections.iter_mut().enumerate() { let section = Arc::make_mut(s); for i in 0..4096 { - section.set(i, ((i + si) % 16) as u16); + section.set(i, ((i + si) % 16) as u32); } for i in 0..64 { section.biomes.set(i, (i % 4) as u32); diff --git a/crates/horizon-client/src/mesher.rs b/crates/horizon-client/src/mesher.rs index 7f1191126..c3990f598 100644 --- a/crates/horizon-client/src/mesher.rs +++ b/crates/horizon-client/src/mesher.rs @@ -434,17 +434,17 @@ fn pi(x: i32, y: i32, z: i32) -> usize { } /// Blocks and light of one section plus a `B`-block border. struct Padded { - blocks: Vec, + blocks: Vec, light: Vec, } impl Padded { fn new(region: &[[Option<&Chunk>; 3]; 3], sy: i32) -> Self { - let mut blocks = vec![0u16; P * P * P]; + let mut blocks = vec![0u32; P * P * P]; let mut light = vec![0u8; P * P * P]; let base_y = MIN_Y + sy * 16; // The section itself is unpacked in one pass; the border cells of the // neighbouring sections are read one by one. - let mut own = Box::new([0u16; 4096]); + let mut own = Box::new([0u32; 4096]); let center = region[1][1].map(|c| &c.sections[sy as usize]); if let Some(section) = center { section.unpack(&mut own); @@ -643,10 +643,8 @@ impl Mesher<'_> { } let state = &info[id as usize]; if state.block_entity { - out.block_entities.push(( - [center.x * 16 + x, base_y + y, center.z * 16 + z], - u32::from(id), - )); + out.block_entities + .push(([center.x * 16 + x, base_y + y, center.z * 16 + z], id)); } if state.solid && Direction::ALL.iter().all(|d| { @@ -665,10 +663,7 @@ impl Mesher<'_> { continue; } let world = BlockPos::new(center.x * 16 + x, base_y + y, center.z * 16 + z); - let Ok(models) = self - .assets - .model_catalog - .collect(BlockStateId(id.into()), world) + let Ok(models) = self.assets.model_catalog.collect(BlockStateId(id), world) else { continue; }; @@ -700,8 +695,8 @@ impl Mesher<'_> { && self .visibility .should_render_face( - BlockStateId(id.into()), - BlockStateId(neighbor.into()), + BlockStateId(id), + BlockStateId(neighbor), d, true, ) diff --git a/crates/horizon-client/src/mesher/fluid.rs b/crates/horizon-client/src/mesher/fluid.rs index 41b1e200e..c29f2b92c 100644 --- a/crates/horizon-client/src/mesher/fluid.rs +++ b/crates/horizon-client/src/mesher/fluid.rs @@ -159,28 +159,28 @@ struct FlowView<'a> { info: &'a [Info], } impl FlowView<'_> { - fn id(&self, p: BlockPos) -> u16 { + fn id(&self, p: BlockPos) -> u32 { self.pad.blocks[pi(p.x, p.y, p.z)] } } impl FluidFlowWorld for FlowView<'_> { type Error = Infallible; - type Block = u16; + type Block = u32; fn fluid(&mut self, p: BlockPos) -> Result { Ok(self.info[self.id(p) as usize].fluid) } - fn block(&mut self, p: BlockPos) -> Result { + fn block(&mut self, p: BlockPos) -> Result { Ok(self.id(p)) } - fn blocks_fluid_flow(&self, state: u16) -> bool { + fn blocks_fluid_flow(&self, state: u32) -> bool { self.info[state as usize].blocks_flow } - fn is_ice_class(&self, state: u16) -> bool { + fn is_ice_class(&self, state: u32) -> bool { self.info[state as usize].ice } fn is_face_sturdy( &mut self, - state: u16, + state: u32, _: BlockPos, d: Direction, ) -> Result { diff --git a/crates/horizon-client/src/mesher/leaf_culling_tests.rs b/crates/horizon-client/src/mesher/leaf_culling_tests.rs index 16ea98cef..9369a1ba2 100644 --- a/crates/horizon-client/src/mesher/leaf_culling_tests.rs +++ b/crates/horizon-client/src/mesher/leaf_culling_tests.rs @@ -13,12 +13,12 @@ fn leaf_culling_removes_only_internal_leaf_and_root_faces() { let visibility = crate::models::load_visibility(&root, assets.registry).unwrap(); let tables = MeshTables::new(&assets, &facts, visibility.clone()).unwrap(); let biomes = Biomes::load(&root).unwrap(); - let state = |name| assets.registry.default_state(name).unwrap().0 as u16; + let state = |name| assets.registry.default_state(name).unwrap().0; let oak = state("minecraft:oak_leaves"); let birch = state("minecraft:birch_leaves"); let roots = state("minecraft:mangrove_roots"); let stone = state("minecraft:stone"); - let mesh = |blocks: &[([i32; 3], u16)], cull_leaves, cutout_leaves| { + let mesh = |blocks: &[([i32; 3], u32)], cull_leaves, cutout_leaves| { let mut center = Chunk::empty(0, 0); let mut east = Chunk::empty(1, 0); for &([x, y, z], state) in blocks { @@ -51,7 +51,7 @@ fn leaf_culling_removes_only_internal_leaf_and_root_faces() { let vertices = mesh(&[(at, id)], false, true); let models = assets .model_catalog - .collect(BlockStateId(id.into()), BlockPos::new(at[0], at[1], at[2])) + .collect(BlockStateId(id), BlockPos::new(at[0], at[1], at[2])) .unwrap(); let faces: Vec<_> = models.iter().flat_map(|(_, model)| &model.faces).collect(); assert_eq!(vertices.len(), faces.len() * 4); diff --git a/crates/horizon-client/src/mesher/visibility_tests.rs b/crates/horizon-client/src/mesher/visibility_tests.rs index 2f95c45cf..32eb4800c 100644 --- a/crates/horizon-client/src/mesher/visibility_tests.rs +++ b/crates/horizon-client/src/mesher/visibility_tests.rs @@ -105,7 +105,7 @@ fn fixture(mut opaque: impl FnMut(i32, i32, i32) -> bool) -> Padded { for y in 0..16 { for z in 0..16 { for x in 0..16 { - pad.blocks[pi(x, y, z)] = u16::from(opaque(x, y, z)) + 2 * ((x + y + z) as u16 & 1); + pad.blocks[pi(x, y, z)] = u32::from(opaque(x, y, z)) + 2 * ((x + y + z) as u32 & 1); } } } diff --git a/crates/horizon-client/src/minimap.rs b/crates/horizon-client/src/minimap.rs index 8015e2ab2..8b250e1af 100644 --- a/crates/horizon-client/src/minimap.rs +++ b/crates/horizon-client/src/minimap.rs @@ -75,8 +75,8 @@ impl Palette { } } #[inline] - fn get(&self, id: u16) -> (u8, u8) { - let i = usize::from(id); + fn get(&self, id: u32) -> (u8, u8) { + let i = id as usize; ( self.color.get(i).copied().unwrap_or(0), self.flags.get(i).copied().unwrap_or(AIR), @@ -137,7 +137,7 @@ fn scan_column( (0, MIN_Y as i16, 0) } /// The highest block of a chunk worth scanning from. -fn top_of(chunk: &Chunk, air: u16, layer: Layer) -> i32 { +fn top_of(chunk: &Chunk, air: u32, layer: Layer) -> i32 { let surface = (0..SECTIONS) .rev() .find(|&s| { @@ -152,7 +152,7 @@ fn top_of(chunk: &Chunk, air: u16, layer: Layer) -> i32 { Layer::Below(head) => surface.min(head), } } -fn scan_tile(chunk: &Chunk, palette: &Palette, air: u16, layer: Layer, revision: u64) -> Tile { +fn scan_tile(chunk: &Chunk, palette: &Palette, air: u32, layer: Layer, revision: u64) -> Tile { let top = top_of(chunk, air, layer); let mut tile = Tile { color: [0; 256], @@ -287,7 +287,7 @@ impl Minimap { ) -> usize { let palette = self.palette.get_or_insert_with(|| Palette::new(facts)); let started = Instant::now(); - let air = world.air.0 as u16; + let air = world.air.0; // Tiles of unloaded or distant chunks go. self.tiles.retain(|k, _| { (k.0 - center.0).abs() <= radius + 2 @@ -417,7 +417,7 @@ mod tests { (LAVA, 2), ]) } - fn chunk(columns: &[(i32, i32, &[(i32, u16)])]) -> Chunk { + fn chunk(columns: &[(i32, i32, &[(i32, u32)])]) -> Chunk { let mut c = Chunk::empty(0, 0); for &(x, z, blocks) in columns { for &(y, id) in blocks { @@ -467,7 +467,7 @@ mod tests { fn below_a_height_shows_the_floor_and_cuts_walls() { let p = palette(); // A cave: stone everywhere from 0 to 20, air at 10 and 11 in column 0. - let mut blocks: Vec<(i32, u16)> = (0..=20).map(|y| (y, 2)).collect(); + let mut blocks: Vec<(i32, u32)> = (0..=20).map(|y| (y, 2)).collect(); let solid = blocks.clone(); blocks.retain(|&(y, _)| y != 10 && y != 11); let c = chunk(&[(0, 0, &blocks), (1, 0, &solid)]); diff --git a/crates/horizon-client/src/mod_content.rs b/crates/horizon-client/src/mod_content.rs index f78808da7..25df87352 100644 --- a/crates/horizon-client/src/mod_content.rs +++ b/crates/horizon-client/src/mod_content.rs @@ -323,7 +323,7 @@ impl<'a> Plan<'a> { } let list: Vec = by_mod.iter().map(|(m, n)| format!("{m} {n}")).collect(); return Err(format!( - "{next} block states, more than the {MAX_STATES} chunks can hold ({} in the game; \ + "{next} block states, more than the {MAX_STATES} a world can hold ({} in the game; \ the mods: {})", names.len(), list.join(", ") @@ -644,9 +644,11 @@ const NBT_TABLES: [&str; 6] = [ /// In a root built here: the content mods' ids, the namespaces loaders /// read besides `minecraft`. const MARKER: &str = "horizon-mod-content.json"; -/// Block states a world can hold: chunk sections store a state in 16 bits -/// (crate::chunk). Mods past it are refused, not wrapped onto other blocks. -pub const MAX_STATES: u32 = 1 << 16; +/// Block states a world can hold. Chunk sections widen their global palette +/// past vanilla's 16 bits to fit the registry (crate::chunk::set_block_states); +/// this caps it at 20 bits, about 29 times vanilla's 35,723 states. Mods past +/// it are refused, not wrapped onto other blocks. +pub const MAX_STATES: u32 = 1 << 20; /// The content mods' namespaces in a root built by [`build`]; none in any /// other root, so vanilla's loaders read exactly what they did. diff --git a/crates/horizon-client/src/mod_content_tests.rs b/crates/horizon-client/src/mod_content_tests.rs index 7067eef40..2a040b0fc 100644 --- a/crates/horizon-client/src/mod_content_tests.rs +++ b/crates/horizon-client/src/mod_content_tests.rs @@ -266,17 +266,17 @@ fn refuses_unknown_templates_and_vanilla_ids() { } #[test] -fn refuses_more_states_than_chunks_hold() { +fn refuses_more_states_than_a_world_holds() { let Some(base) = prepared() else { return; }; let scratch = std::env::temp_dir().join(format!("horizon-mod-states-{}", std::process::id())); let _ = fs::remove_dir_all(&scratch); let mut m = ruby_mod(&scratch.join("ruby")); - // Redstone wire has 1296 states: 40 copies pass any game's 65536. + // Redstone wire has 1296 states: 810 copies pass 2^20 with any game. let mut wire = m.content.blocks[0].clone(); wire.template = "minecraft:redstone_wire".into(); - for i in 0..40 { + for i in 0..810 { let mut b = wire.clone(); b.id = format!("ruby:wire_{i}"); m.content.blocks.push(b); @@ -284,13 +284,33 @@ fn refuses_more_states_than_chunks_hold() { let e = build(&base, std::slice::from_ref(&m), &scratch.join("out")).unwrap_err(); assert!( e.to_string() - .contains("more than the 65536 chunks can hold"), + .contains("more than the 1048576 a world can hold"), "{e}" ); assert!(e.to_string().contains("the mods: ruby "), "{e}"); fs::remove_dir_all(&scratch).unwrap(); } +#[test] +fn builds_past_sixteen_bit_states() { + let Some(base) = prepared() else { + return; + }; + let scratch = std::env::temp_dir().join(format!("horizon-mod-wide-{}", std::process::id())); + let _ = fs::remove_dir_all(&scratch); + let mut m = ruby_mod(&scratch.join("ruby")); + // 40 redstone wires: 51,840 states, past 65,536 with vanilla's 35,723. + let mut wire = m.content.blocks[0].clone(); + wire.template = "minecraft:redstone_wire".into(); + for i in 0..40 { + let mut b = wire.clone(); + b.id = format!("ruby:wire_{i}"); + m.content.blocks.push(b); + } + build(&base, std::slice::from_ref(&m), &scratch.join("out")).unwrap(); + fs::remove_dir_all(&scratch).unwrap(); +} + #[test] fn no_content_keeps_the_base_root() { let base = Path::new("/nonexistent/base"); diff --git a/crates/horizon-client/src/poi_sections.rs b/crates/horizon-client/src/poi_sections.rs index 2116362e0..79ff0441d 100644 --- a/crates/horizon-client/src/poi_sections.rs +++ b/crates/horizon-client/src/poi_sections.rs @@ -54,12 +54,12 @@ impl PoiSections { return cached.pois.clone(); } let pois: SectionPois = if section.blocks.maybe_has(|v| kind(v).is_some()) { - let mut states = [0u16; 4096]; + let mut states = [0u32; 4096]; section.unpack(&mut states); states .iter() .enumerate() - .filter_map(|(i, &state)| kind(u32::from(state)).map(|poi| (i as u16, poi))) + .filter_map(|(i, &state)| kind(state).map(|poi| (i as u16, poi))) .collect() } else { Arc::from([]) diff --git a/crates/horizon-client/src/random_tick_sections.rs b/crates/horizon-client/src/random_tick_sections.rs index 97a1f02fa..cd06f2ac9 100644 --- a/crates/horizon-client/src/random_tick_sections.rs +++ b/crates/horizon-client/src/random_tick_sections.rs @@ -134,7 +134,7 @@ mod tests { let mut chunk = Chunk::empty(0, 0); for i in [0, 9, SECTIONS - 1] { Arc::make_mut(&mut chunk.sections[i]).blocks = - Section::from_blocks(&std::array::from_fn(|j| (j % 300) as u16)); + Section::from_blocks(&std::array::from_fn(|j| (j % 300) as u32)); } let chunk = Arc::new(chunk); let mut cache = RandomTickSections::default(); @@ -176,12 +176,9 @@ mod tick_parity { } fn set_raw(&mut self, pos: BlockPos, state: BlockStateId) -> Option { let chunk = self.chunks.get_mut(&(pos.x >> 4, pos.z >> 4))?; - Some(BlockStateId(u32::from(Arc::make_mut(chunk).set( - pos.x, - pos.y, - pos.z, - state.0 as u16, - )))) + Some(BlockStateId( + Arc::make_mut(chunk).set(pos.x, pos.y, pos.z, state.0), + )) } fn is_loaded(&self, pos: BlockPos) -> bool { self.chunks.contains_key(&(pos.x >> 4, pos.z >> 4)) @@ -233,7 +230,7 @@ mod tick_parity { // Every sampled block can run real behaviour and change to dirt. for i in [4, 7] { Arc::make_mut(&mut c.sections[i]).blocks = - crate::chunk::Section::from_blocks(&[grass.0 as u16; 4096]); + crate::chunk::Section::from_blocks(&[grass.0; 4096]); } Arc::new(c) }; diff --git a/crates/horizon-client/src/save.rs b/crates/horizon-client/src/save.rs index a8553e276..963e3f711 100644 --- a/crates/horizon-client/src/save.rs +++ b/crates/horizon-client/src/save.rs @@ -16,7 +16,7 @@ use crate::{ Result, biome::Biomes, - chunk::{BIOME_STRATEGY, BLOCK_STRATEGY, Chunk, Light, MIN_Y, SECTIONS}, + chunk::{BIOME_STRATEGY, Chunk, Light, MIN_Y, SECTIONS, block_strategy}, streaming::ChunkGenerator, }; use horizon_core::{ @@ -238,7 +238,7 @@ pub struct SaveTables { default_state: Vec, block_entity: Vec, heightmaps: crate::assets::Properties, - air: u16, + air: u32, } impl SaveTables { pub fn new(assets: &crate::assets::Assets) -> Self { @@ -266,9 +266,7 @@ impl SaveTables { default_state, block_entity: Vec::new(), heightmaps: assets.properties.clone(), - air: registry - .default_state("minecraft:air") - .map_or(0, |s| s.0 as u16), + air: registry.default_state("minecraft:air").map_or(0, |s| s.0), } } /// Which states carry a block entity (`BlockFacts`), to drop entries for @@ -1030,8 +1028,8 @@ fn decode_column( } } } - let air = registry.default_state("minecraft:air")?.0 as u16; - let mut cache: HashMap = HashMap::new(); + let air = registry.default_state("minecraft:air")?.0; + let mut cache: HashMap = HashMap::new(); let Some(Tag::List(sections)) = tag.get("sections") else { return Some(chunk); }; @@ -1046,7 +1044,7 @@ fn decode_column( if let Some(states) = section.get("block_states") && let Some(Tag::List(palette)) = states.get("palette") { - let ids: Vec = palette + let palette: Vec = palette .iter() .map(|p| { let state = BlockState::from_nbt(p).ok(); @@ -1069,7 +1067,7 @@ fn decode_column( registry.id(&full).or(Some(default)) }) }) - .map_or(air, |id| id.0 as u16) + .map_or(air, |id| id.0) }) }) .collect(); @@ -1080,9 +1078,8 @@ fn decode_column( } _ => None, }; - let palette: Vec = ids.iter().map(|&id| u32::from(id)).collect(); if let Ok(blocks) = - PalettedContainer::from_packed(BLOCK_STRATEGY, palette, data.as_deref()) + PalettedContainer::from_packed(block_strategy(), palette, data.as_deref()) { target.blocks = blocks; } diff --git a/crates/horizon-client/src/testgen.rs b/crates/horizon-client/src/testgen.rs index e0a5d49b3..6268a8b6c 100644 --- a/crates/horizon-client/src/testgen.rs +++ b/crates/horizon-client/src/testgen.rs @@ -4,24 +4,24 @@ use crate::{chunk::Chunk, streaming::ChunkGenerator}; use horizon_world::registry::BlockRegistry; pub struct TestTerrain { - stone: u16, - dirt: u16, - grass: u16, - water: u16, - sand: u16, - bedrock: u16, - log: u16, - leaves: u16, - short_grass: u16, + stone: u32, + dirt: u32, + grass: u32, + water: u32, + sand: u32, + bedrock: u32, + log: u32, + leaves: u32, + short_grass: u32, plains: u16, } impl TestTerrain { pub fn new(registry: &BlockRegistry, biomes: &crate::biome::Biomes) -> crate::Result { - let id = |name: &str| -> crate::Result { + let id = |name: &str| -> crate::Result { Ok(registry .default_state(name) .ok_or_else(|| format!("missing {name}"))? - .0 as u16) + .0) }; Ok(Self { stone: id("minecraft:stone")?, @@ -41,7 +41,7 @@ impl TestTerrain { ] .into(), })? - .0 as u16, + .0, short_grass: id("minecraft:short_grass")?, plains: biomes.id("minecraft:plains"), }) diff --git a/crates/horizon-client/src/vanillagen.rs b/crates/horizon-client/src/vanillagen.rs index fc18e8404..7addfc608 100644 --- a/crates/horizon-client/src/vanillagen.rs +++ b/crates/horizon-client/src/vanillagen.rs @@ -119,7 +119,7 @@ impl VanillaTerrain { chunk.terrain.min_y().max(MIN_Y), (chunk.terrain.min_y() + chunk.terrain.height()).min(MIN_Y + HEIGHT), ); - let mut values = Box::new([0u16; 4096]); + let mut values = Box::new([0u32; 4096]); for si in 0..SECTIONS as i32 { let base = MIN_Y + si * 16; if base + 16 <= lo || base >= hi { @@ -130,7 +130,7 @@ impl VanillaTerrain { for y in base.max(lo)..(base + 16).min(hi) { for z in 0..16 { for x in 0..16 { - let id = chunk.block(bx + x, y, bz + z).0 as u16; + let id = chunk.block(bx + x, y, bz + z).0; values[((y & 15) << 8 | z << 4 | x) as usize] = id; any |= id != 0; } diff --git a/crates/horizon-client/src/world.rs b/crates/horizon-client/src/world.rs index 44e442ec1..05b89234c 100644 --- a/crates/horizon-client/src/world.rs +++ b/crates/horizon-client/src/world.rs @@ -21,7 +21,7 @@ pub struct World { pub dirty_light: crate::fast_hash::FxHashSet<(i32, i32)>, /// Edits on lit chunks (position, old state, new state), relit /// incrementally by streaming. - pub light_edits: Vec<((i32, i32, i32), u16, u16)>, + pub light_edits: Vec<((i32, i32, i32), u32, u32)>, /// Saved entities of chunks that just loaded, spawned by the game. pub loaded_entities: Vec<((i32, i32), Vec)>, /// Chunks changed since the last save. @@ -36,7 +36,7 @@ pub struct World { /// blocks, which need a block entity). pub watched: Vec, /// Writes of watched states: position, previous and new state. - pub watched_writes: Vec<((i32, i32, i32), u16, u16)>, + pub watched_writes: Vec<((i32, i32, i32), u32, u32)>, /// `ChunkAccess.inhabitedTime` of resident chunks: ticks a player spent /// within spawning range (local difficulty). pub inhabited: HashMap<(i32, i32), i64>, @@ -198,12 +198,11 @@ impl World { if y < MIN_Y || y >= MIN_Y + (SECTIONS as i32) * 16 { return Err("write outside world height".into()); } - let previous = Arc::make_mut(chunk).set(x & 15, y, z & 15, state.0 as u16); - if u32::from(previous) != state.0 { - let watches = |id: u16| self.watched.get(usize::from(id)).copied().unwrap_or(false); - if watches(previous) || watches(state.0 as u16) { - self.watched_writes - .push(((x, y, z), previous, state.0 as u16)); + let previous = Arc::make_mut(chunk).set(x & 15, y, z & 15, state.0); + if previous != state.0 { + let watches = |id: u32| self.watched.get(id as usize).copied().unwrap_or(false); + if watches(previous) || watches(state.0) { + self.watched_writes.push(((x, y, z), previous, state.0)); } self.revision = self.revision.wrapping_add(1); if let Some(log) = &mut self.block_log { @@ -225,7 +224,7 @@ impl World { } let _ = sy; if self.chunks.get(&(x >> 4, z >> 4)).is_some_and(|c| c.lit) { - self.light_edits.push(((x, y, z), previous, state.0 as u16)); + self.light_edits.push(((x, y, z), previous, state.0)); } else { for dz in -1..=1 { for dx in -1..=1 { diff --git a/crates/horizon-client/tests/lan_bot.rs b/crates/horizon-client/tests/lan_bot.rs index 36f53444c..7b958202c 100644 --- a/crates/horizon-client/tests/lan_bot.rs +++ b/crates/horizon-client/tests/lan_bot.rs @@ -38,7 +38,7 @@ fn resources() -> Option { root.join("items.json").exists().then_some(root) } -const STONE: u16 = 1; +const STONE: u32 = 1; fn flat_world() -> World { let mut world = World::new(BlockStateId(0), 0); @@ -163,7 +163,7 @@ struct Server { hub: Hub, world: World, next_entity: u32, - placed: Vec<(u32, [i32; 3], u16, i32)>, + placed: Vec<(u32, [i32; 3], u32, i32)>, } impl Server { fn tick(&mut self, entities: &[EntityState]) { @@ -202,7 +202,7 @@ impl Server { if let S::UseItemOn(p) = *packet { let at = [p.pos[0], p.pos[1] + 1, p.pos[2]]; ctx.world - .set(at[0], at[1], at[2], BlockStateId(u32::from(STONE))) + .set(at[0], at[1], at[2], BlockStateId(STONE)) .unwrap(); self.placed.push((conn, at, STONE, p.sequence)); self.hub.ack(conn, p.sequence); @@ -348,7 +348,7 @@ fn status_and_join() { chunks += 1; let sections = l.chunk.sections(24, 16, 7).map_err(|e| e.to_string())?; // The floor is in the lowest section. - assert_eq!(sections[0].states.get(4 * 256), i32::from(STONE)); + assert_eq!(sections[0].states.get(4 * 256), STONE as i32); assert_eq!(sections[0].non_empty, 256); assert_eq!(sections[1].non_empty, 0); assert!(!l.light.sky.is_empty()); @@ -394,7 +394,7 @@ fn status_and_join() { assert!(chunks >= 9, "only {chunks} chunks"); assert_eq!( block_update, - Some(([9, MIN_Y + 5, 9], i32::from(STONE))), + Some(([9, MIN_Y + 5, 9], STONE as i32)), "placed block was not broadcast" ); Ok(bot.name) diff --git a/crates/horizon-client/tests/streaming_meshes.rs b/crates/horizon-client/tests/streaming_meshes.rs index 74edd5049..6804d197e 100644 --- a/crates/horizon-client/tests/streaming_meshes.rs +++ b/crates/horizon-client/tests/streaming_meshes.rs @@ -107,7 +107,7 @@ fn columns_loaded_past_the_render_distance_mesh_when_they_come_in_range() { /// A one-block cave under the sky: a stone floor at y 62 with a glowstone, /// and a roof at y 64 with holes, so that every light change in the cave is /// sampled by a face. -fn roofed(x: i32, z: i32, stone: u16, glowstone: u16) -> Chunk { +fn roofed(x: i32, z: i32, stone: u32, glowstone: u32) -> Chunk { let mut chunk = Chunk::empty(x, z); for lz in 0..16 { for lx in 0..16 { @@ -143,7 +143,7 @@ fn relit_columns_keep_every_mesh_current() { biomes: Arc::new(Biomes::load(&root).unwrap()), assets: assets.clone(), }); - let state = |name: &str| assets.registry.default_state(name).unwrap().0 as u16; + let state = |name: &str| assets.registry.default_state(name).unwrap().0; let (stone, glowstone, torch) = ( state("minecraft:stone"), state("minecraft:glowstone"), @@ -185,9 +185,7 @@ fn relit_columns_keep_every_mesh_current() { let (bx, bz) = (16 + lx, lz); world.set(bx, 64, bz, BlockStateId(0)).unwrap(); if i % 3 == 0 { - world - .set(bx, 63, bz, BlockStateId(u32::from(torch))) - .unwrap(); + world.set(bx, 63, bz, BlockStateId(torch)).unwrap(); } } } diff --git a/crates/horizon-client/tests/wide_states.rs b/crates/horizon-client/tests/wide_states.rs new file mode 100644 index 000000000..690732ceb --- /dev/null +++ b/crates/horizon-client/tests/wide_states.rs @@ -0,0 +1,40 @@ +//! Block states past vanilla's 16-bit global palette (docs/modpacks.md): +//! content mods can take the registry past 65,536 states. Its own test binary, +//! since the palette width is set once for the whole process. + +use horizon_client::chunk::{Chunk, Section, block_strategy, set_block_states}; + +#[test] +fn sections_hold_states_past_sixteen_bits() { + // Vanilla's width until the registry needs more (one test: the width is + // global to the process). + assert_eq!(block_strategy().global_bits, 16); + set_block_states(35_723); + assert_eq!(block_strategy().global_bits, 16); + set_block_states(100_000); + assert_eq!(block_strategy().global_bits, 17); + + // A few states past 65,536 stay in the section's own palette. + let mut chunk = Chunk::empty(0, 0); + chunk.set(1, 70, 2, 70_000); + chunk.set(3, 70, 4, 99_999); + assert_eq!(chunk.get(1, 70, 2), 70_000); + assert_eq!(chunk.get(3, 70, 4), 99_999); + assert_eq!(chunk.get(0, 70, 0), 0); + + // More than 256 distinct states take the global palette at 17 bits. + let mut values = [0u32; 4096]; + for (i, v) in values.iter_mut().enumerate() { + *v = 65_000 + (i as u32 % 1000) * 30; + } + let mut section = Section { + blocks: Section::from_blocks(&values), + ..Section::default() + }; + let mut out = [0u32; 4096]; + section.unpack(&mut out); + assert_eq!(out, values); + section.set(17, 99_998); + assert_eq!(section.get(17), 99_998); + assert_eq!(section.get(18), values[18]); +} From 4d1596fe3b903d4f2ca35ad8aac097f571c5f81b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 08:53:46 +0200 Subject: [PATCH 23/46] Load ATM10's 42 carried mods: room past 8,192 textures and tags With the wide state ids, ATM10's 42 data-tier mods (193,762 states) reach the world once these loaders stop refusing them: - Block sprites: eight texture arrays of 2048 layers instead of four (9,790 block textures for the 42). - Per-state tables read as NBT: the table limits cover 2^20 states, and the collision table in level data uses them. - Worldgen block tags: 2^20 blocks instead of 8,192 (mineable/pickaxe holds every stone block of a pack). - As vanilla's loaders do, a blockstate definition that does not bind, a missing or broken block model of a mod, and a recipe that does not parse are logged and skipped instead of dropping every mod (or stopping the game). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/crafting.rs | 10 +++- crates/horizon-client/src/game/remote.rs | 7 +++ crates/horizon-client/src/gfx.rs | 10 +++- crates/horizon-client/src/model_library.rs | 50 ++++++++++++++++--- crates/horizon-client/src/models/catalog.rs | 38 +++++++++++--- crates/horizon-client/src/terrain.wgsl | 10 +++- crates/horizon-world/src/level/data.rs | 2 +- crates/horizon-world/src/nbt.rs | 8 +-- .../src/worldgen/feature_catalog.rs | 2 +- .../src/worldgen/state_provider.rs | 7 ++- .../tests/state_provider_bounds.rs | 8 ++- docs/modpacks.md | 18 +++++-- 12 files changed, 139 insertions(+), 31 deletions(-) diff --git a/crates/horizon-client/src/crafting.rs b/crates/horizon-client/src/crafting.rs index 457ddf497..0b8f2856b 100644 --- a/crates/horizon-client/src/crafting.rs +++ b/crates/horizon-client/src/crafting.rs @@ -1209,7 +1209,15 @@ impl Recipes { for (prefix, path) in files { let stem = path.file_stem().and_then(|s| s.to_str()).unwrap_or(""); let name = format!("{prefix}{stem}"); - let v: Value = serde_json::from_slice(&fs::read(&path)?)?; + // Vanilla's RecipeManager logs a file that does not parse and + // goes on ("Couldn't parse data file"). + let v: Value = match serde_json::from_slice(&fs::read(&path)?) { + Ok(v) => v, + Err(e) => { + log::warn!("Horizon: recipe {name} not loaded: {e}"); + continue; + } + }; let text = |k: &str| v[k].as_str().unwrap_or("").to_owned(); meta.insert(name.clone(), (text("category"), text("group"))); let ing = |k: &str| Ingredient::parse(&v[k], items); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 5b026171f..014fd5e2a 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -644,6 +644,13 @@ impl Game<'_> { if strategy.global_bits != ours.global_bits { let mut values = [0u32; 4096]; blocks.unpack(&mut values); + // Ids past our registry (a host with mods we lack) read as air. + let limit = 1u64 << ours.global_bits; + for v in &mut values { + if u64::from(*v) >= limit { + *v = 0; + } + } blocks = PalettedContainer::from_values(ours, &values); } let mut section = Section { diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 7391ad8b9..df642e417 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -385,7 +385,7 @@ fn sprite_split() -> u32 { .unwrap_or(SPRITE_SPLIT) } /// Sprite arrays terrain.wgsl binds (`sprites`, `sprites_1`...). -const SPRITE_ARRAYS: u32 = 4; +const SPRITE_ARRAYS: u32 = 8; /// The views of terrain.wgsl's sprite arrays, the unused ones a 1-layer /// stand-in. fn sprite_views( @@ -441,6 +441,10 @@ fn terrain_group( view(5, &sprites[1]), view(6, &sprites[2]), view(7, &sprites[3]), + view(8, &sprites[4]), + view(9, &sprites[5]), + view(10, &sprites[6]), + view(11, &sprites[7]), ], }) } @@ -739,6 +743,10 @@ impl Renderer { entry(5, vf, sprite_array), entry(6, vf, sprite_array), entry(7, vf, sprite_array), + entry(8, vf, sprite_array), + entry(9, vf, sprite_array), + entry(10, vf, sprite_array), + entry(11, vf, sprite_array), ], }); let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { diff --git a/crates/horizon-client/src/model_library.rs b/crates/horizon-client/src/model_library.rs index 7f7852ad0..c6a1a9d87 100644 --- a/crates/horizon-client/src/model_library.rs +++ b/crates/horizon-client/src/model_library.rs @@ -42,25 +42,52 @@ impl ParsedModels { /// Blocks require every referenced resource, including parents. Items instead /// skip broken resources and use the resolver's missing-model fallback. - pub(crate) fn block_library( + pub(crate) fn block_library(&self, root: &Path, pending: Vec) -> Result { + self.block_models(root, pending, false) + } + /// [`Self::block_library`], but a model that does not read takes the + /// built-in missing model, logged, as vanilla's model discovery does + /// ("Missing block model"). Mods' content gets this; vanilla's resources + /// always read. + pub(crate) fn block_library_or_missing( + &self, + root: &Path, + pending: Vec, + ) -> Result { + self.block_models(root, pending, true) + } + fn block_models( &self, root: &Path, mut pending: Vec, + or_missing: bool, ) -> Result { let mut models = BTreeMap::new(); + let mut skipped = std::collections::BTreeSet::new(); while let Some(name) = pending.pop() { - if models.contains_key(&name) { + if models.contains_key(&name) || skipped.contains(&name) { continue; } let model = match self.models.get(&name) { Some(model) => Arc::clone(model), None => { - let (namespace, path) = - name.split_once(':').ok_or("invalid model identifier")?; - let text = fs::read_to_string( - root.join(format!("assets/{namespace}/models/{path}.json")), - )?; - Arc::new(CuboidModel::from_json(&text)?) + let read = || -> Result { + let (namespace, path) = + name.split_once(':').ok_or("invalid model identifier")?; + let text = fs::read_to_string( + root.join(format!("assets/{namespace}/models/{path}.json")), + )?; + Ok(CuboidModel::from_json(&text)?) + }; + match read() { + Ok(model) => Arc::new(model), + Err(e) if or_missing => { + log::warn!("Horizon: missing block model {name}: {e}"); + skipped.insert(name); + continue; + } + Err(e) => return Err(e), + } } }; if let Some(parent) = &model.parent { @@ -141,6 +168,13 @@ mod tests { .to_string() }; assert_eq!(load(&direct), load(&parsed)); + // Mods' content: vanilla's missing model instead of an error. + let lenient = parsed.block_library_or_missing(&fixture.0, vec![name.into()])?; + assert_eq!( + format!("{:?}", lenient.resolve(name)?.elements()), + format!("{:?}", lenient.resolve(MISSING_MODEL)?.elements()), + "{name}" + ); } let items = parsed.into_item_library()?; let block = shared.resolve("horizon:nested/child")?; diff --git a/crates/horizon-client/src/models/catalog.rs b/crates/horizon-client/src/models/catalog.rs index ecedd0f95..a78ddc951 100644 --- a/crates/horizon-client/src/models/catalog.rs +++ b/crates/horizon-client/src/models/catalog.rs @@ -136,11 +136,29 @@ impl StateModels { }) .collect::>()?; let possible: Vec = serde_json::from_value(facts["states"].clone())?; - let resource = fs::read_to_string( + // Vanilla's BlockStateModelLoader: a definition that does not + // read or bind is logged and its block gets no model; the other + // blocks still load. + let loaded = fs::read_to_string( root.join(format!("assets/{namespace}/blockstates/{path}.json")), - )?; - let definition = BlockStateDefinition::from_json(&resource)?; - let bound = definition.bind(&schema, &possible)?; + ) + .map_err(|e| e.to_string()) + .and_then(|text| BlockStateDefinition::from_json(&text).map_err(|e| e.to_string())) + .and_then(|definition| { + let bound = definition + .bind(&schema, &possible) + .map_err(|e| e.to_string())?; + Ok((definition, bound)) + }); + let (definition, bound) = match loaded { + Ok(loaded) => loaded, + Err(e) => { + log::warn!( + "Horizon: blockstate definition of {namespace}:{path} not loaded: {e}" + ); + continue; + } + }; let native_order: Vec<_> = by_name .get(name.as_str()) .map(Vec::as_slice) @@ -185,10 +203,14 @@ impl StateModels { } choices.push(CompiledChoices::new(&definition)?); } - let library = models.block_library( - root, - variants.iter().map(|(name, _, _)| name.clone()).collect(), - )?; + let names: Vec = variants.iter().map(|(name, _, _)| name.clone()).collect(); + let library = match models.block_library(root, names.clone()) { + Ok(library) => library, + Err(e) => { + log::warn!("Horizon: block models incomplete ({e}); using the missing model"); + models.block_library_or_missing(root, names)? + } + }; let mut baked = BTreeMap::new(); for (name, turns, lock) in variants { let model = library.resolve(&name)?; diff --git a/crates/horizon-client/src/terrain.wgsl b/crates/horizon-client/src/terrain.wgsl index 4689e7d2b..dad173efd 100644 --- a/crates/horizon-client/src/terrain.wgsl +++ b/crates/horizon-client/src/terrain.wgsl @@ -31,6 +31,10 @@ struct Globals { @group(0) @binding(5) var sprites_1: texture_2d_array; @group(0) @binding(6) var sprites_2: texture_2d_array; @group(0) @binding(7) var sprites_3: texture_2d_array; +@group(0) @binding(8) var sprites_4: texture_2d_array; +@group(0) @binding(9) var sprites_5: texture_2d_array; +@group(0) @binding(10) var sprites_6: texture_2d_array; +@group(0) @binding(11) var sprites_7: texture_2d_array; // How many sprite arrays hold layers (a pipeline constant): 1 for vanilla, // which then samples exactly as before. override SPRITE_ARRAYS: u32 = 1u; @@ -47,7 +51,11 @@ fn sprite(uv: vec2, layer: u32) -> vec4 { case 0u: { return textureSampleGrad(sprites, sprite_sampler, uv, l, dx, dy); } case 1u: { return textureSampleGrad(sprites_1, sprite_sampler, uv, l, dx, dy); } case 2u: { return textureSampleGrad(sprites_2, sprite_sampler, uv, l, dx, dy); } - default: { return textureSampleGrad(sprites_3, sprite_sampler, uv, l, dx, dy); } + case 3u: { return textureSampleGrad(sprites_3, sprite_sampler, uv, l, dx, dy); } + case 4u: { return textureSampleGrad(sprites_4, sprite_sampler, uv, l, dx, dy); } + case 5u: { return textureSampleGrad(sprites_5, sprite_sampler, uv, l, dx, dy); } + case 6u: { return textureSampleGrad(sprites_6, sprite_sampler, uv, l, dx, dy); } + default: { return textureSampleGrad(sprites_7, sprite_sampler, uv, l, dx, dy); } } } diff --git a/crates/horizon-world/src/level/data.rs b/crates/horizon-world/src/level/data.rs index 42f8f75de..80e42185b 100644 --- a/crates/horizon-world/src/level/data.rs +++ b/crates/horizon-world/src/level/data.rs @@ -744,7 +744,7 @@ pub(super) fn load_with_gameplay( // Collision shapes. let collision_tag = nbt::read_named( &fs::read(root.join("cached-collision.nbt"))?, - Limits::default(), + Limits::tables(), ) .map_err(|e| invalid(e.to_string()))? .0 diff --git a/crates/horizon-world/src/nbt.rs b/crates/horizon-world/src/nbt.rs index 7e4d76a41..414767795 100644 --- a/crates/horizon-world/src/nbt.rs +++ b/crates/horizon-world/src/nbt.rs @@ -100,11 +100,13 @@ impl Default for Limits { impl Limits { /// The prepared per-state block tables (`cached-collision.nbt`, /// `block-properties.nbt`, ...): trusted files with a row per block - /// state, which content mods' states grow past the default caps. + /// state, which content mods' states grow past the default caps + /// (vanilla's 35,723 states fill about a tenth of these; ATM10's ported + /// mods, 193,762 states, about half). pub fn tables() -> Self { Self { - max_bytes: 1 << 28, - max_nodes: 16_000_000, + max_bytes: 1 << 30, + max_nodes: 128_000_000, max_depth: 512, } } diff --git a/crates/horizon-world/src/worldgen/feature_catalog.rs b/crates/horizon-world/src/worldgen/feature_catalog.rs index 0b8d56cc4..4db251114 100644 --- a/crates/horizon-world/src/worldgen/feature_catalog.rs +++ b/crates/horizon-world/src/worldgen/feature_catalog.rs @@ -192,7 +192,7 @@ impl FeatureCatalog { if names.is_empty() { return Ok(serde_json::to_string(&format!("#{tag}"))?); } - if names.len() > 8192 { + if names.len() > super::state_provider::MAX_TAG_BLOCKS { return Err(DecodeError::Field("placed-feature tag size")); } names diff --git a/crates/horizon-world/src/worldgen/state_provider.rs b/crates/horizon-world/src/worldgen/state_provider.rs index 37e9c866b..098decdf1 100644 --- a/crates/horizon-world/src/worldgen/state_provider.rs +++ b/crates/horizon-world/src/worldgen/state_provider.rs @@ -93,7 +93,7 @@ impl<'r> StateProviderBindings<'r> { } let mut bound_tags = BTreeMap::new(); for (name, entries) in tags { - if entries.len() > 8192 { + if entries.len() > MAX_TAG_BLOCKS { return Err(DecodeError::Field("provider tag size")); } let values = entries @@ -558,6 +558,11 @@ impl BlockStateProvider { } } +/// Blocks a bound block tag may list (8,192 before content mods, vanilla's +/// tags fit well within it): content mods' blocks join the shared tags +/// (`mineable/pickaxe` takes every stone block of a pack). +pub(crate) const MAX_TAG_BLOCKS: usize = 1 << 20; + /// Bind the pinned registry's full-axis/full-facing/horizontal-facing property /// families. A five-way facing or two-axis property is a different property and /// is intentionally left unchanged. Unrelated properties retain their values. diff --git a/crates/horizon-world/tests/state_provider_bounds.rs b/crates/horizon-world/tests/state_provider_bounds.rs index 033d4675c..23553e6b7 100644 --- a/crates/horizon-world/tests/state_provider_bounds.rs +++ b/crates/horizon-world/tests/state_provider_bounds.rs @@ -41,7 +41,13 @@ fn bound_recursive_providers_and_registry_lists_before_sampling() { let branching = serde_json::json!({"if_true":{"type":"all_of","predicates":vec![serde_json::json!({"type":"true"});7]},"then":{"id":"stone"}}); let oversized = serde_json::json!({"type":"rule_based","rules":vec![branching;8192]}); assert!(BlockStateProvider::from_json(&oversized.to_string(), &bindings).is_err()); - let tags = BTreeMap::from([("horizon:oversized".into(), vec!["stone".into(); 8193])]); + // Content mods' blocks join shared tags: the cap is 2^20 blocks. + let tags = BTreeMap::from([("horizon:large".into(), vec!["stone".into(); 8193])]); + assert!(StateProviderBindings::new(®istry, BTreeSet::new(), &tags).is_ok()); + let tags = BTreeMap::from([( + "horizon:oversized".into(), + vec!["stone".into(); (1 << 20) + 1], + )]); assert!(StateProviderBindings::new(®istry, BTreeSet::new(), &tags).is_err()); let tags = BTreeMap::from([("tag".into(), vec![]), ("minecraft:tag".into(), vec![])]); assert!(StateProviderBindings::new(®istry, BTreeSet::new(), &tags).is_err()); diff --git a/docs/modpacks.md b/docs/modpacks.md index 1d8609cef..82f90e540 100644 --- a/docs/modpacks.md +++ b/docs/modpacks.md @@ -237,11 +237,19 @@ How the game loads them, without touching vanilla's path: - Loaders that read only `data/minecraft/` (recipes, loot, tags) read every namespace, as vanilla does. With no mods there is only `minecraft`, so nothing changes. - The overlay is cached like the resource-pack overlay and rebuilt when a mod file changes. -- **Limits.** Chunk sections store a block state in 16 bits: vanilla 26.3 has 35,723 states, - so mods may add 29,813. Past that the content root is refused with the states per mod - (Macaw's Doors, Fences, Paths and Trapdoors alone add 36,154: not all four fit). Block - sprites fill texture arrays of 2048 layers, four at most (8,192; vanilla takes 1,250, - identical textures share a layer). Wider state ids are the next step for big packs. +- **Limits.** Chunk sections size their global palette to the registry: 16 bits for vanilla's + 35,723 states (the same chunks, saves and packets as before), one more bit each time content + mods double it, up to 2^20 states (1,048,576). Past that the content root is refused with the + states per mod. ATM10's 42 carried mods take the registry to 193,762 states (18 bits). On the + network the width is the registry's: unchanged for vanilla clients as long as no content mod + is on, wider only between Horizons that share the same mods; a Horizon with content mods still + reads a vanilla server's 16-bit chunks. Block sprites fill texture arrays of 2048 layers, eight + at most (16,384; vanilla takes 1,250, identical textures share a layer; ATM10's 42 take 9,790). +- **Broken mod files load as vanilla loads them.** A blockstate definition that does not bind + (a multipart value the block does not have), a block model that is missing or does not parse, + and a recipe that does not parse are logged and skipped: the block gets no model or the + missing model, the recipe is absent, everything else loads. Vanilla's own files never hit + these paths. - Not in 0.2: multiplayer registry sync (single player and the integrated server first), worlds opened without a mod they used (vanilla turns unknown blocks into air; we will ask first), vanilla ids redefined by a mod (refused). From 62f96e9d65f77ed261ad1d14f4cff5fe5ce37a33 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 09:42:46 +0200 Subject: [PATCH 24/46] Mobs float in water instead of bouncing FloatGoal's constructor lets the navigation float, so Mob.jumpInLiquid adds 0.04F a tick; Horizon set that flag only for a few species, and every other FloatGoal user (pigs, cows, wolves, cats, horses, witches, illagers...) got the non-floater 0.3 and bounced out of the water. Register it from the goal (and from the constructors that set it: allay, armadillo, camel, goat, parrot, wither), and add 0.04 as the float vanilla adds. Mobs that drop back into water now splash (Entity.doWaterSplashEffect from updateFluidInteraction, skipped on the first tick), with their swim splash sound. The new mob_ai deep_water scenarios also caught: horses register addBehaviourGoals last (none for the skeleton horse, no mount panic for the zombie horse), RandomStandGoal waits the horse ambient interval (400 for every AbstractHorse), and the cat's sit-on- block goal draws its delay only for tame cats once the last ran out. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/mobs.rs | 3 + crates/horizon-client/src/mobs/ai.rs | 22 ++++- crates/horizon-client/src/mobs/equine.rs | 26 +++-- crates/horizon-client/src/mobs/goals.rs | 4 + crates/horizon-client/src/mobs/living.rs | 115 +++++++++++++++++++++- crates/horizon-client/src/mobs/species.rs | 11 ++- crates/horizon-client/src/mobs/tame.rs | 11 ++- tools/test_mob_ai_parity.py | 6 ++ 8 files changed, 181 insertions(+), 17 deletions(-) diff --git a/crates/horizon-client/src/mobs.rs b/crates/horizon-client/src/mobs.rs index 8b51593bc..59acf1a45 100644 --- a/crates/horizon-client/src/mobs.rs +++ b/crates/horizon-client/src/mobs.rs @@ -807,6 +807,8 @@ pub struct Mob { /// Entity.wasEyeInWater: the eyes were in water before this tick's fluid /// update (`isUnderWater` reads it). pub was_eye_in_water: bool, + /// `Entity.firstTick`: no splash for a mob that appears in water. + pub first_tick: bool, pub no_gravity: bool, /// `Entity.mainSupportingBlockPos`: the block it stood on after its last /// move. @@ -1484,6 +1486,7 @@ impl Mob { extra: Extra::default(), fluids: living::Fluids::default(), was_eye_in_water: false, + first_tick: true, no_gravity: false, supporting: None, no_ai: false, diff --git a/crates/horizon-client/src/mobs/ai.rs b/crates/horizon-client/src/mobs/ai.rs index 318b37d5c..9ab29d0a5 100644 --- a/crates/horizon-client/src/mobs/ai.rs +++ b/crates/horizon-client/src/mobs/ai.rs @@ -225,6 +225,22 @@ pub fn register(m: &mut Mob) { Family::Bat => super::bat::register(m), Family::Bee => super::bee::register(m), } + // FloatGoal's constructor lets the navigation float, as do the + // constructors of these brain-driven and flying mobs. A floater rises + // 0.04 a tick in Mob.jumpInLiquid, the others 0.3 (the bounce of #542). + if m.ai.goals.has("Float") + || matches!( + m.species(), + Species::Allay + | Species::Armadillo + | Species::Camel + | Species::Goat + | Species::Parrot + | Species::Wither + ) + { + m.ai.nav.can_float = true; + } } /// Mob.tick additions that run before the entity tick (creeper fuse, puffing). fn pre_tick(m: &mut Mob, events: &mut Vec) { @@ -428,10 +444,7 @@ fn tick_swing(m: &mut Mob) { /// Entity.baseTick + LivingEntity.baseTick + Mob.baseTick. fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) { m.was_eye_in_water = m.fluids.eye_in_water; - m.fluids = w.fluids(m.bounds(), m.eye_y()); - if m.fluids.in_water { - m.fall_distance = 0.0; - } + m.update_fluids(w, events); let fire = crate::motion::environment::fire_contact(w.world, w.registry, m.bounds()); if fire > 0.0 { m.ticks_frozen = 0; @@ -474,6 +487,7 @@ fn base_tick(m: &mut Mob, w: &MobWorld, events: &mut Vec) { if m.position.y < f64::from(crate::chunk::MIN_Y - 64) { m.damage(4.0, Damage::of(DamageKind::OutOfWorld)); } + m.first_tick = false; if m.alive() { // LivingEntity.baseTick: suffocation inside full blocks. let (ex, ey, ez) = ( diff --git a/crates/horizon-client/src/mobs/equine.rs b/crates/horizon-client/src/mobs/equine.rs index 46d33b576..e7d73f0fa 100644 --- a/crates/horizon-client/src/mobs/equine.rs +++ b/crates/horizon-client/src/mobs/equine.rs @@ -83,19 +83,33 @@ pub fn register(m: &mut Mob) { return super::llama::register(m); } let tempt = m.kind.tempt.clone(); - let rears = can_rear(m.species()); + let species = m.species(); + let rears = can_rear(species); + let stand_interval = m.kind.ambient_interval; let g = &mut m.ai.goals; - g.add(0, Float); - g.add(1, MountPanic(Panic::new(1.2))); g.add(1, RunAroundLikeCrazy); g.add(2, Breed::new(1.0)); - g.add(3, Tempt::new(1.25, tempt, false)); g.add(4, FollowParent::new(1.0)); g.add(6, Stroll::avoiding_water(0.7)); g.add(7, LookAtPlayer::new(6.0)); g.add(8, RandomLookAround::default()); if rears { - g.add(9, RandomStand { next: -80 }); + // resetStandInterval: -getAmbientStandInterval (400 for every horse). + g.add( + 9, + RandomStand { + next: -stand_interval, + }, + ); + } + // addBehaviourGoals, after the rest: none for the skeleton horse (it + // sinks), no mount panic for the zombie horse. + if species != Species::SkeletonHorse { + g.add(0, Float); + if species != Species::ZombieHorse { + g.add(1, MountPanic(Panic::new(1.2))); + } + g.add(3, Tempt::new(1.25, tempt, false)); } } /// `generateMaxHealth`, `generateSpeed`, `generateJumpStrength` and the coat. @@ -285,7 +299,7 @@ impl Goal for RandomStand { fn can_use(&mut self, m: &mut Mob, _: &mut Cx) -> bool { self.next += 1; if self.next > 0 && m.random.next_int_bound(1000).unwrap_or(1000) < self.next { - self.next = -80; + self.next = -m.kind.ambient_interval; return m.random.next_int_bound(10).unwrap_or(1) == 0; } false diff --git a/crates/horizon-client/src/mobs/goals.rs b/crates/horizon-client/src/mobs/goals.rs index 0d13b0e81..9419a23ba 100644 --- a/crates/horizon-client/src/mobs/goals.rs +++ b/crates/horizon-client/src/mobs/goals.rs @@ -94,6 +94,10 @@ impl GoalSelector { .map(|g| g.goal.name()) .collect() } + /// Whether a goal of this name is registered, running or not. + pub fn has(&self, name: &str) -> bool { + self.goals.iter().any(|g| g.goal.name() == name) + } pub fn is_running(&self, name: &str) -> bool { self.goals .iter() diff --git a/crates/horizon-client/src/mobs/living.rs b/crates/horizon-client/src/mobs/living.rs index 6bf246541..ebbfabf6b 100644 --- a/crates/horizon-client/src/mobs/living.rs +++ b/crates/horizon-client/src/mobs/living.rs @@ -398,10 +398,7 @@ impl Mob { /// (touching water resets the fall), then Entity.checkFallDamage. fn check_fall_damage(&mut self, w: &MobWorld, moved: Vec3, events: &mut Vec) { if !self.fluids.in_water { - self.fluids = w.fluids(self.bounds(), self.eye_y()); - if self.fluids.in_water { - self.fall_distance = 0.0; - } + self.update_fluids(w, events); } if !self.fluids.in_water && moved.y < 0.0 { self.fall_distance -= f64::from(moved.y as f32); @@ -413,6 +410,23 @@ impl Mob { self.fall_distance = 0.0; } } + /// Entity.updateFluidInteraction: the fluid state, then touching water + /// resets the fall and entering it (after the first tick) splashes. + pub(super) fn update_fluids(&mut self, w: &MobWorld, events: &mut Vec) { + let was_touching_water = self.fluids.in_water; + self.fluids = w.fluids(self.bounds(), self.eye_y()); + if self.fluids.in_water { + self.fall_distance = 0.0; + if !was_touching_water && !self.first_tick { + // The splash is the mob's own: Horizon's mobs carry no + // controlling passenger here. + let _ = horizon_world::water_splash::water_splash( + &mut Splash { mob: self, events }, + 1_000_000, + ); + } + } + } /// Entity.applyMovementEmissionAndPlaySound: walked distance, footsteps /// and swimming sounds. fn movement_emission(&mut self, w: &MobWorld, moved: Vec3, events: &mut Vec) { @@ -811,7 +825,8 @@ impl Mob { self.velocity.y += if self.species() == super::Species::Bee { 0.01 } else if self.ai.nav.can_float { - 0.04 + // LivingEntity.jumpInLiquid adds 0.04F. + f64::from(0.04_f32) } else { 0.3 }; @@ -915,3 +930,93 @@ fn free_position( let free = allowed_shape.join(&collisions, ShapeOp::ONLY_FIRST).ok()?; free.closest_point(preferred) } + +/// `Entity.doWaterSplashEffect` for a mob: its own random, its splash sound +/// (`getSwimSplashSound`), particles for the client and the SPLASH game event. +struct Splash<'a> { + mob: &'a mut Mob, + events: &'a mut Vec, +} +impl horizon_world::water_splash::WaterSplashWorld for Splash<'_> { + type Error = std::convert::Infallible; + type Entity = (); + type Sound = &'static str; + fn this_entity(&self) {} + fn controlling_passenger(&mut self) -> Result, Self::Error> { + Ok(None) + } + fn velocity(&mut self, _: ()) -> Result { + Ok(self.mob.velocity) + } + fn splash_sound(&mut self, _high_speed: bool) -> Result<&'static str, Self::Error> { + use super::Species; + // Entity.getSwimSplashSound and getSwimHighSpeedSplashSound: the + // overrides are Monster's, the hoglin's, the dolphin's and the axolotl's. + let species = self.mob.species(); + Ok(match species { + Species::Dolphin => "entity.dolphin.splash", + Species::Axolotl => "entity.axolotl.splash", + _ if species == Species::Hoglin || super::ai::is_monster(species) => { + "entity.hostile.splash" + } + _ => "entity.generic.splash", + }) + } + fn random_float(&mut self) -> Result { + Ok(self.mob.random.next_float()) + } + fn random_double(&mut self) -> Result { + Ok(self.mob.random.next_double()) + } + fn play_sound( + &mut self, + sound: &'static str, + volume: f32, + pitch: f32, + ) -> Result<(), Self::Error> { + if !self.mob.silent { + let at = [ + self.mob.position.x, + self.mob.position.y, + self.mob.position.z, + ]; + self.events.push(MobEvent::Sound(sound, at, volume, pitch)); + } + Ok(()) + } + fn position(&self) -> Vec3 { + self.mob.position + } + fn width(&self) -> f32 { + self.mob.width() + } + fn particle( + &mut self, + kind: horizon_world::water_splash::SplashParticle, + position: Vec3, + velocity: Vec3, + ) -> Result<(), Self::Error> { + self.events.push(MobEvent::ParticleAt { + kind: match kind { + horizon_world::water_splash::SplashParticle::Bubble => "bubble", + horizon_world::water_splash::SplashParticle::Splash => "splash", + }, + at: [position.x, position.y, position.z], + velocity: [velocity.x, velocity.y, velocity.z], + }); + Ok(()) + } + fn splash_event(&mut self) -> Result<(), Self::Error> { + self.events.push(MobEvent::GameEvent { + event: "minecraft:splash", + at: [ + self.mob.position.x, + self.mob.position.y, + self.mob.position.z, + ], + source: self.mob.id, + state: horizon_world::registry::BlockStateId(0), + }); + Ok(()) + } +} diff --git a/crates/horizon-client/src/mobs/species.rs b/crates/horizon-client/src/mobs/species.rs index fcfd61992..28ea729b3 100644 --- a/crates/horizon-client/src/mobs/species.rs +++ b/crates/horizon-client/src/mobs/species.rs @@ -1634,7 +1634,16 @@ impl Def { use Species as S; match self.species { S::Turtle => 200, - S::Horse | S::Donkey | S::Mule | S::Llama | S::TraderLlama => 400, + // AbstractHorse.getAmbientSoundInterval, for every subclass. + S::Horse + | S::Donkey + | S::Mule + | S::ZombieHorse + | S::SkeletonHorse + | S::Llama + | S::TraderLlama + | S::Camel + | S::CamelHusk => 400, S::Ocelot => 900, S::Squid | S::GlowSquid diff --git a/crates/horizon-client/src/mobs/tame.rs b/crates/horizon-client/src/mobs/tame.rs index 4e5e3d290..1e725df80 100644 --- a/crates/horizon-client/src/mobs/tame.rs +++ b/crates/horizon-client/src/mobs/tame.rs @@ -855,8 +855,17 @@ impl Goal for CatSitOnBlock { JUMP | MOVE } fn can_use(&mut self, m: &mut Mob, cx: &mut Cx) -> bool { + if !m.extra.tame || m.extra.sitting { + return false; + } + // MoveToBlockGoal.canUse draws the next delay only once the last one + // has run out. + if self.0.next_start > 0 { + self.0.next_start -= 1; + return false; + } let next = reduced(200 + m.random.next_int_bound(200).unwrap_or(0)); - m.extra.tame && !m.extra.sitting && self.0.can_use(m, cx.w, next, can_sit_on) + self.0.can_use(m, cx.w, next, can_sit_on) } fn can_continue(&mut self, _: &mut Mob, cx: &mut Cx) -> bool { self.0.can_continue(cx.w, can_sit_on) diff --git a/tools/test_mob_ai_parity.py b/tools/test_mob_ai_parity.py index a32ec2cf9..9bb244ce9 100644 --- a/tools/test_mob_ai_parity.py +++ b/tools/test_mob_ai_parity.py @@ -262,6 +262,12 @@ def scenarios(): add('bee_hive_rain', 300, [HIVE, 'mob minecraft:bee 0.5 -58 0.5 0 162 persistent'], 'rain') add('bee_hive_morning', 1000, [HIVE, 'mob minecraft:bee 0.5 -58 0.5 0 163 persistent'], 'time=22900 daycycle') add('bee_hive_honey', 2600, [HIVE, 'mob minecraft:bee 0.5 -58 0.5 0 164 persistent nectar']) + # Mobs dropped into deep water (#542): FloatGoal users float at the surface (their navigation + # can float, so Mob.jumpInLiquid adds 0.04 a tick), zombies sink. + for species, seed in [('pig', 171), ('cow', 172), ('wolf', 173), ('cat', 174), ('horse', 175), + ('witch', 176), ('vindicator', 177), ('zombie', 178)]: + add(f'{species}_deep_water', 160, ['fill -4 -64 -4 4 -61 4 minecraft:water', + f'mob minecraft:{species} 0.5 -62 0.5 0 {seed} persistent']) return s From 69a0d13edafb9764cce33a7fc77bb2bd9b470c6a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 09:45:18 +0200 Subject: [PATCH 25/46] Raise the trident over the shoulder while charging a throw AvatarRenderer.getArmPose gives THROW_TRIDENT to the hand using a trident: HumanoidModel lifts that arm over the head (xRot * 0.5 - pi) and leaves the other arm's pose alone (affectsOffhandPose). Horizon used the plain item pose, so the held trident, drawn with its throwing model, pointed down through the body. An aggressive drowned raises its trident the same way (DrownedRenderer), and zombie arms leave that arm alone (AnimationUtils.animateZombieArms). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/mobs/anim.rs | 54 +++++++++++++++++++++----- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/crates/horizon-client/src/mobs/anim.rs b/crates/horizon-client/src/mobs/anim.rs index 161db24f9..b17eb8c1d 100644 --- a/crates/horizon-client/src/mobs/anim.rs +++ b/crates/horizon-client/src/mobs/anim.rs @@ -235,6 +235,8 @@ pub enum ArmPose { Bow, CrossbowHold, CrossbowCharge, + /// Raising a trident to throw it (or to launch with Riptide). + ThrowTrident, } /// HumanoidModel.setupAnim for piglins: `PiglinModel` poses the arms itself. pub fn humanoid_item(p: &mut Poses, s: &State, _holding: bool) { @@ -298,7 +300,7 @@ impl ArmPose { matches!(self, Self::Bow | Self::CrossbowHold | Self::CrossbowCharge) } fn affects_offhand(self) -> bool { - self.two_handed() + self.two_handed() || self == Self::ThrowTrident } } /// `AnimationUtils.animateCrossbowHold`. @@ -350,6 +352,11 @@ fn pose_arm(p: &mut Poses, pose: ArmPose, right: bool, h: &Hum) { p.xrot("right_arm", -PI / 2.0 + hx); p.xrot("left_arm", -PI / 2.0 + hx); } + ArmPose::ThrowTrident => { + let x = p.get(arm)[3]; + p.xrot(arm, x * 0.5 - PI); + p.yrot(arm, 0.0); + } ArmPose::CrossbowHold => crossbow_hold(p, hx, hy, right), ArmPose::CrossbowCharge => crossbow_charge(p, h.charge.0, h.charge.1, right), } @@ -435,12 +442,17 @@ pub(super) fn humanoid(p: &mut Poses, s: &State, h: &Hum) { let xm = ((1.0 - (1.0 - swing) * (1.0 - swing)) * PI).msin(); let x = drop + ym * 1.2 - xm * 0.4; let y = 0.1 - ym * 0.6; - p.xrot("right_arm", x); - p.yrot("right_arm", if raise { -y } else { y }); - p.zrot("right_arm", 0.0); - p.xrot("left_arm", x); - p.yrot("left_arm", if raise { y } else { -y }); - p.zrot("left_arm", 0.0); + // An arm raising a trident keeps its pose. + if h.right != ArmPose::ThrowTrident { + p.xrot("right_arm", x); + p.yrot("right_arm", if raise { -y } else { y }); + p.zrot("right_arm", 0.0); + } + if h.left != ArmPose::ThrowTrident { + p.xrot("left_arm", x); + p.yrot("left_arm", if raise { y } else { -y }); + p.zrot("left_arm", 0.0); + } } if h.crouching { p.xrot("body", 0.5); @@ -526,7 +538,21 @@ pub fn setup( | Anim::ZombieVillager | Anim::ZombifiedPiglin | Anim::Humanoid { zombie_arms: true } => { - let mut h = Hum::new(ArmPose::Empty, ArmPose::Empty); + // DrownedRenderer.getArmPose: an aggressive drowned raises the + // trident in its main arm. + let throwing = m.kind.anim == Anim::Drowned + && m.ai.aggressive + && m.extra.main_hand.as_deref() == Some("minecraft:trident"); + let main = if throwing { + ArmPose::ThrowTrident + } else { + ArmPose::Empty + }; + let mut h = if m.extra.main_hand_left { + Hum::new(ArmPose::Empty, main) + } else { + Hum::new(main, ArmPose::Empty) + }; h.zombie = Some(m.ai.aggressive); h.holding = m.extra.main_hand.is_some(); h.crouching = m.extra.crouching; @@ -549,6 +575,7 @@ pub fn setup( let pose = if player { match m.extra.main_hand.as_deref() { Some("minecraft:bow") if m.extra.using_item > 0 => ArmPose::Bow, + Some("minecraft:trident") if m.extra.using_item > 0 => ArmPose::ThrowTrident, Some("minecraft:crossbow") if m.extra.using_item > 0 && !m.extra.charged => { ArmPose::CrossbowCharge } @@ -561,7 +588,7 @@ pub fn setup( } else { right }; - let off = if player && m.extra.off_hand.is_some() && !pose.two_handed() { + let off = if player && m.extra.off_hand.is_some() && !pose.affects_offhand() { ArmPose::Item } else { ArmPose::Empty @@ -709,5 +736,14 @@ mod flight_pose_tests { humanoid(&mut flight, &state, &h); assert_eq!(flight.get("head")[3], -std::f32::consts::FRAC_PI_4); assert_eq!(flight.get("right_leg")[3], ground.get("right_leg")[3] / 8.0); + // THROW_TRIDENT: the arm goes up over the head, and zombie arms leave it there. + let mut throw = make(); + let mut h = Hum::new(ArmPose::ThrowTrident, ArmPose::Item); + h.zombie = Some(true); + humanoid(&mut throw, &state, &h); + let still = (state.pos * 0.6662 + PI).mcos() * 2.0 * 0.5; + assert_eq!(throw.get("right_arm")[3], still * 0.5 - PI); + assert_eq!(throw.get("right_arm")[4], 0.0); + assert_eq!(throw.get("left_arm")[3], -PI / 1.5); } } From b47f5658496cf787db06cdb46681c36d96bffbf6 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:04:25 -0400 Subject: [PATCH 26/46] Reclaim unused terrain GPU arena pages --- crates/horizon-client/src/gfx.rs | 2 + crates/horizon-client/src/gfx/arena.rs | 147 +++++++++++++++++++++---- 2 files changed, 128 insertions(+), 21 deletions(-) diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 7391ad8b9..6c4b89240 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -2181,6 +2181,8 @@ impl Renderer { ); } pub fn render(&mut self, frame: &Frame) -> Result { + self.arena.trim(); + self.sorted_indices.trim(); if self.suspended { return Ok(false); } diff --git a/crates/horizon-client/src/gfx/arena.rs b/crates/horizon-client/src/gfx/arena.rs index 233333e04..19576204c 100644 --- a/crates/horizon-client/src/gfx/arena.rs +++ b/crates/horizon-client/src/gfx/arena.rs @@ -49,9 +49,10 @@ struct Page { /// Terrain vertices in pages of at most `page_limit` vertices (devices cap /// buffer sizes): a section's vertices sit in one page. pub struct Arena { - pages: Vec, + pages: Vec>, stride: u64, page_limit: u64, + initial_capacity: u64, usage: wgpu::BufferUsages, } @@ -73,13 +74,10 @@ impl Arena { let page_limit = (bytes / stride) / GRAIN * GRAIN; let capacity = capacity.next_multiple_of(GRAIN).min(page_limit); Self { - pages: vec![Page { - buffer: Self::create(device, stride, capacity, usage), - capacity, - free: FreeList::new(capacity), - }], + pages: Vec::new(), stride, page_limit, + initial_capacity: capacity, usage, } } @@ -102,10 +100,13 @@ impl Arena { } /// Bytes of every page's buffer. pub fn bytes(&self) -> u64 { - self.pages.iter().map(|p| p.capacity).sum::() * self.stride + self.pages.iter().flatten().map(|p| p.capacity).sum::() * self.stride } pub fn buffer(&self, page: u32) -> &wgpu::Buffer { - &self.pages[page as usize].buffer + &self.pages[page as usize] + .as_ref() + .expect("live arena page") + .buffer } /// A range of `vertices`: (page, first vertex). Grows the newest page /// (copying its contents on the GPU) or starts a new one when nothing @@ -118,39 +119,62 @@ impl Arena { ) -> (u32, u64) { let len = Self::span(vertices).min(self.page_limit); for (i, page) in self.pages.iter_mut().enumerate() { - if let Some(start) = page.free.take(len) { + if let Some(page) = page + && let Some(start) = page.free.take(len) + { return (i as u32, start); } } - let last = self.pages.len() - 1; - let current = self.pages[last].capacity; - if current < self.page_limit { + let last = self.pages.len().saturating_sub(1); + if let Some(page) = self.pages.last().and_then(Option::as_ref) + && page.capacity < self.page_limit + { + let current = page.capacity; let grown = (current * 2).max(current + len).min(self.page_limit); if grown - current >= len || grown == self.page_limit { self.grow(device, queue, last, grown); - if let Some(start) = self.pages[last].free.take(len) { + if let Some(start) = self.pages[last].as_mut().unwrap().free.take(len) { return (last as u32, start); } } } - let capacity = (1 << 20u64).max(len).min(self.page_limit); + let capacity = if self.pages.is_empty() { + self.initial_capacity + } else { + 1 << 20 + } + .max(len) + .min(self.page_limit); let mut free = FreeList::new(capacity); let start = free.take(len).expect("a new page fits one section"); - self.pages.push(Page { + let page = Page { buffer: Self::create(device, self.stride, capacity, self.usage), capacity, free, - }); - ((self.pages.len() - 1) as u32, start) + }; + let index = self + .pages + .iter() + .position(Option::is_none) + .unwrap_or_else(|| { + self.pages.push(None); + self.pages.len() - 1 + }); + self.pages[index] = Some(page); + (index as u32, start) } pub fn release(&mut self, page: u32, start: u64, vertices: u64) { let len = Self::span(vertices).min(self.page_limit); - self.pages[page as usize].free.give(start, len); + self.pages[page as usize] + .as_mut() + .expect("live arena page") + .free + .give(start, len); } fn grow(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, page: usize, capacity: u64) { let capacity = capacity.next_multiple_of(GRAIN).min(self.page_limit); let buffer = Self::create(device, self.stride, capacity, self.usage); - let old = &mut self.pages[page]; + let old = self.pages[page].as_mut().expect("live arena page"); let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("Grow section arena"), }); @@ -162,10 +186,23 @@ impl Arena { old.capacity = capacity; old.free.give(previous, capacity - previous); } - pub fn clear(&mut self) { + /// Reclaim after an upload batch, so replacing a section can reuse its range. + pub fn trim(&mut self) { for page in &mut self.pages { - page.free = FreeList::new(page.capacity); + if let Some(p) = page + && p.free.0.len() == 1 + && p.free.0.get(&0) == Some(&p.capacity) + { + *page = None; + } } + // Keep live page indices stable; later allocations reuse interior holes. + while self.pages.last().is_some_and(Option::is_none) { + self.pages.pop(); + } + } + pub fn clear(&mut self) { + self.pages.clear(); } } @@ -173,6 +210,74 @@ impl Arena { mod tests { use super::*; + fn device() -> Option<(wgpu::Device, wgpu::Queue)> { + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle()); + let adapter = pollster::block_on(instance.request_adapter(&Default::default())).ok()?; + eprintln!("arena GPU regression: {}", adapter.get_info().name); + pollster::block_on(adapter.request_device(&Default::default())).ok() + } + + #[test] + fn empty_pages_are_reclaimed_without_moving_live_ranges() { + let Some((device, queue)) = device() else { + eprintln!("no GPU adapter: skipped"); + return; + }; + let mut arena = Arena::new(&device, 4, GRAIN); + arena.page_limit = 2 * GRAIN; + assert_eq!(arena.bytes(), 0); + let (first, a) = arena.alloc(&device, &queue, GRAIN); + let (_, b) = arena.alloc(&device, &queue, GRAIN); + let (live, c) = arena.alloc(&device, &queue, 2 * GRAIN); + let buffer = arena.buffer(live).clone(); + let data = [1u8, 2, 3, 4]; + queue.write_buffer(&buffer, c * 4, &data); + assert_eq!(arena.bytes(), 4 * GRAIN * 4); + arena.release(first, a, GRAIN); + arena.trim(); + assert_eq!(arena.bytes(), 4 * GRAIN * 4); + arena.release(first, b, GRAIN); + arena.trim(); + assert_eq!(arena.bytes(), 2 * GRAIN * 4); + assert_eq!(arena.buffer(live), &buffer); + let (reused, d) = arena.alloc(&device, &queue, GRAIN); + assert_eq!(reused, first); + + let (tx, rx) = std::sync::mpsc::channel(); + wgpu::util::DownloadBuffer::read_buffer( + &device, + &queue, + &arena.buffer(live).slice(c * 4..c * 4 + 4), + move |result| tx.send(result.unwrap().to_vec()).unwrap(), + ); + device.poll(wgpu::PollType::wait_indefinitely()).unwrap(); + assert_eq!(rx.recv().unwrap(), data); + arena.release(reused, d, GRAIN); + arena.release(live, c, 2 * GRAIN); + arena.trim(); + assert_eq!(arena.bytes(), 0); + assert!(arena.pages.is_empty()); + } + + #[test] + fn clearing_an_arena_releases_buffers_and_can_allocate_again() { + let Some((device, queue)) = device() else { + eprintln!("no GPU adapter: skipped"); + return; + }; + for mut arena in [ + Arena::new(&device, 28, GRAIN), + Arena::indices(&device, GRAIN), + ] { + arena.alloc(&device, &queue, GRAIN); + assert_eq!(arena.bytes(), arena.stride * GRAIN); + arena.clear(); + assert_eq!(arena.bytes(), 0); + assert_eq!(arena.alloc(&device, &queue, GRAIN), (0, 0)); + assert_eq!(arena.bytes(), arena.stride * GRAIN); + } + } + #[test] fn free_ranges_coalesce() { let mut free = FreeList::new(4 * GRAIN); From 171fbeb8ac4877109fc95e93c5db1b0f2360652b Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 10:14:34 +0200 Subject: [PATCH 27/46] Send vanilla clients the locator bar on dedicated and LAN servers Port 26.3's ServerWaypointManager for the players of a served world: each player who receives waypoints gets ClientboundTrackedWaypointPacket for every other player who transmits one, as a block (in view), a chunk (one chunk out) or an azimuth (really far), with the update thresholds, breaking rules and team colours vanilla uses. Crouching, invisibility and a carved pumpkin or mob head hide a player; spectators see everyone and are seen by no one; the locator_bar game rule turns it all off and on. tools/test_locator_bar_parity.py runs vanilla's server and Horizon's with two vanilla-codec players and compares every waypoint packet each receives. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 1 + crates/horizon-client/src/game/lan.rs | 7 + .../horizon-client/src/game/lan_waypoints.rs | 95 +++ crates/horizon-client/src/lan/mod.rs | 1 + crates/horizon-client/src/lan/waypoints.rs | 643 ++++++++++++++++++ crates/horizon-protocol/src/packets/play.rs | 150 ++++ .../horizonlab/parity/LocatorBarClient.java | 382 +++++++++++ tools/test_locator_bar_parity.py | 259 +++++++ 8 files changed, 1538 insertions(+) create mode 100644 crates/horizon-client/src/game/lan_waypoints.rs create mode 100644 crates/horizon-client/src/lan/waypoints.rs create mode 100644 mods/horizon/src/test/java/dev/horizonlab/parity/LocatorBarClient.java create mode 100644 tools/test_locator_bar_parity.py diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 117b83bc5..aca73d205 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -68,6 +68,7 @@ mod lan_mobs; mod lan_pvp; mod lan_screen; mod lan_trading; +mod lan_waypoints; mod leads; mod level_particles; mod lightning; diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index f6fc1e860..857728657 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -57,6 +57,10 @@ pub(super) struct LanHost { pub mob_players: HashMap, /// An integrated server's owner (game/integrated.rs). pub owner: Option, + /// The players' locator bars (game/lan_waypoints.rs), and the guests who + /// are dead, whose respawn replaces their waypoint. + pub waypoints: lan::waypoints::Waypoints, + pub waypoint_dead: std::collections::HashSet, } /// The player who owns an integrated server's world: a guest whose state is @@ -502,6 +506,8 @@ impl Game<'_> { mob_state: HashMap::new(), mob_players: HashMap::new(), owner: None, + waypoints: Default::default(), + waypoint_dead: Default::default(), }); self.audio.capture = Some(Vec::new()); Ok(()) @@ -785,6 +791,7 @@ impl Game<'_> { self.lan_swings(&mut host); self.lan_update_streaming(&host); self.lan_update_models(&mut host); + self.lan_update_waypoints(&mut host, state.as_ref()); drop(holding); for g in &host.hub.guests { g.sender.flush(); diff --git a/crates/horizon-client/src/game/lan_waypoints.rs b/crates/horizon-client/src/game/lan_waypoints.rs new file mode 100644 index 000000000..0d0ab69e4 --- /dev/null +++ b/crates/horizon-client/src/game/lan_waypoints.rs @@ -0,0 +1,95 @@ +//! The locator bar of the players on a served world (lan/waypoints.rs): what +//! each player looks like to the waypoint manager this tick. +use super::{Game, lan::LanHost}; +use horizon_client::{ + items::ItemStack, + lan::{ + hub::HostState, + waypoints::{self, HIDING_HEADS, Icon, PLAYER_RANGE}, + }, +}; + +/// `waypoint_transmit_range`: hidden by crouching, invisibility or a head worn. +fn transmit_range(crouching: bool, invisible: bool, head: Option<&ItemStack>) -> f64 { + let hiding_head = head.is_some_and(|s| HIDING_HEADS.contains(&&*s.item)); + if crouching || invisible || hiding_head { + 0.0 + } else { + PLAYER_RANGE + } +} + +impl Game<'_> { + /// The player's team and its colour, as the locator bar shows it. + fn waypoint_team(&self, name: &str) -> Option<(String, Option)> { + let team = self.score.board.players_team(name)?; + let color = team.color.as_deref().and_then(waypoints::team_rgb); + Some((team.name.clone(), color)) + } + + pub(super) fn lan_update_waypoints(&mut self, host: &mut LanHost, state: Option<&HostState>) { + let mut players = Vec::new(); + if let Some(h) = state { + let icon = self + .cmds + .waypoint_icons + .get(&super::commands::Target::Player) + .map(|i| Icon { + style: i.style.clone(), + 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, + }); + } + let mut respawned = Vec::new(); + for g in host.hub.guests.iter().filter(|g| g.placed) { + // PlayerList.respawn makes a new ServerPlayer. + if g.dead { + host.waypoint_dead.insert(g.uuid); + } else if host.waypoint_dead.remove(&g.uuid) { + respawned.push(g.uuid); + } + // 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(), + }); + } + host.waypoint_dead + .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) { + if let Some(g) = host.hub.guest(conn) { + g.send(&packet); + } + } + } +} diff --git a/crates/horizon-client/src/lan/mod.rs b/crates/horizon-client/src/lan/mod.rs index 58badc010..f074506b5 100644 --- a/crates/horizon-client/src/lan/mod.rs +++ b/crates/horizon-client/src/lan/mod.rs @@ -20,6 +20,7 @@ pub mod menu; pub mod playerdata; mod recipes; pub mod tracking; +pub mod waypoints; pub use conn::{Holding, PlayerSender}; use horizon_protocol::packets::play; diff --git a/crates/horizon-client/src/lan/waypoints.rs b/crates/horizon-client/src/lan/waypoints.rs new file mode 100644 index 000000000..a8797dbaf --- /dev/null +++ b/crates/horizon-client/src/lan/waypoints.rs @@ -0,0 +1,643 @@ +//! The locator bar for remote players: ServerWaypointManager and +//! WaypointTransmitter's connections, for players (the transmitters vanilla has +//! by default: `waypoint_transmit_range` is 0 for every other entity). +//! +//! Vanilla updates a player's connections each time the player's position +//! changes (`Entity.setPosRaw`, then `ServerChunkCache.move`). The hub sees the +//! position once a tick, after the moves it handled, and updates from there: +//! the same packets, since a client sends one move a tick. Hiding (crouching, +//! invisibility, a carved pumpkin or a mob head worn) changes +//! `waypoint_transmit_range` and tracks or untracks the waypoint, as +//! `LivingEntity.onAttributeUpdated` does; joining or leaving a team remakes the +//! connections with the team's colour (`ServerScoreboard.updatePlayerWaypoint`). +use horizon_protocol::packets::play::{ + Clientbound as C, TrackedWaypoint, WaypointId, WaypointTarget, waypoint_operation, +}; +use std::collections::HashMap; + +/// `Player.createAttributes`: both waypoint ranges. +pub const PLAYER_RANGE: f64 = 6.0e7; +/// `WaypointTransmitter.REALLY_FAR_DISTANCE`. +const REALLY_FAR: f32 = 332.0; +/// `EntityAzimuthConnection.update`: half a degree. +const AZIMUTH_STEP: f32 = 0.008_726_646; + +/// Items that hide their wearer (`Waypoint.addHideAttribute` on the head slot). +pub const HIDING_HEADS: [&str; 8] = [ + "minecraft:carved_pumpkin", + "minecraft:skeleton_skull", + "minecraft:wither_skeleton_skull", + "minecraft:player_head", + "minecraft:zombie_head", + "minecraft:creeper_head", + "minecraft:dragon_head", + "minecraft:piglin_head", +]; + +/// A team colour as the locator bar draws it (`Waypoint.Icon.cloneAndAssignStyle`: +/// `TeamColor.rgb()`, black lightened so it shows). +pub fn team_rgb(color: &str) -> Option { + let rgb = match color { + "black" => return Some(-13_619_152), + "dark_blue" => 0x0000AA, + "dark_green" => 0x00AA00, + "dark_aqua" => 0x00AAAA, + "dark_red" => 0xAA0000, + "dark_purple" => 0xAA00AA, + "gold" => 0xFFAA00, + "gray" => 0xAAAAAA, + "dark_gray" => 0x555555, + "blue" => 0x5555FF, + "green" => 0x55FF55, + "aqua" => 0x55FFFF, + "red" => 0xFF5555, + "light_purple" => 0xFF55FF, + "yellow" => 0xFFFF55, + "white" => 0xFFFFFF, + _ => return None, + }; + Some(rgb) +} + +/// Waypoint.Icon. +#[derive(Clone, Debug, PartialEq)] +pub struct Icon { + pub style: String, + pub color: Option, +} + +impl Default for Icon { + fn default() -> Self { + Self { + style: "minecraft:default".into(), + color: None, + } + } +} + +/// A player as the waypoint manager sees them this tick. +#[derive(Clone, Debug)] +pub struct Player { + pub uuid: u128, + /// The connection that receives the player's locator bar (None: the host, + /// whose own game draws it). + pub conn: Option, + pub position: [f64; 3], + pub spectator: bool, + /// `waypoint_transmit_range`: 0 while hidden. + pub transmit_range: f64, + pub receive_range: f64, + /// `Entity.firstTick`: the player has not ticked since joining. + pub first_tick: bool, + /// The chunk view radius (`ChunkMap.getPlayerViewDistance`). + pub view_distance: i32, + /// The player's team and its colour (`TeamColor.rgb`). + pub team: Option<(String, Option)>, + /// The icon `/waypoint modify` set. + pub icon: Icon, +} + +impl Player { + fn block(&self) -> [i32; 3] { + self.position.map(|v| v.floor() as i32) + } + fn chunk(&self) -> [i32; 2] { + let [x, _, z] = self.block(); + [x >> 4, z >> 4] + } + /// `Entity.distanceTo`. + fn distance_to(&self, other: &Player) -> f32 { + let d2: f64 = (0..3) + .map(|k| (self.position[k] - other.position[k]).powi(2)) + .sum(); + d2.sqrt() as f32 + } +} + +#[derive(Clone, Copy, Debug, PartialEq)] +enum Kind { + Block([i32; 3]), + Chunk([i32; 2]), + Azimuth(f32), +} + +#[derive(Clone, Debug)] +struct Connection { + kind: Kind, + icon: Icon, +} + +/// What the manager remembers of a player between ticks. +struct Memo { + position: [f64; 3], + /// The centre of the player's ChunkTrackingView (`ChunkMap.move`). + view_center: [i32; 2], + transmitting: bool, + team: Option<(String, Option)>, +} + +/// ServerWaypointManager for one level. +#[derive(Default)] +pub struct Waypoints { + /// The transmitters, in the order they were tracked. + waypoints: Vec, + /// The receivers, in the order they joined. + players: Vec, + /// Connections by receiver, then source. + connections: HashMap>, + memo: HashMap, + /// The `locator_bar` game rule as last seen. + enabled: Option, +} + +/// One tick's players, and the packets for their connections. +struct Tick<'a> { + players: HashMap, + view: HashMap, + /// Players a respawn replaced this tick: a new ServerPlayer, on its first tick. + fresh: &'a [u128], + enabled: bool, + out: Vec<(u32, C)>, +} + +impl Tick<'_> { + fn send( + &mut self, + receiver: u128, + source: u128, + operation: i32, + icon: &Icon, + target: WaypointTarget, + ) { + let Some(conn) = self.players.get(&receiver).and_then(|p| p.conn) else { + return; + }; + self.out.push(( + conn, + C::TrackedWaypoint(TrackedWaypoint { + operation, + id: WaypointId::Uuid(source), + style: icon.style.clone(), + color: icon.color, + target, + }), + )); + } + fn connect(&mut self, receiver: u128, source: u128, c: &Connection) { + let target = match c.kind { + Kind::Block(p) => WaypointTarget::Block(p), + Kind::Chunk(p) => WaypointTarget::Chunk(p), + Kind::Azimuth(a) => WaypointTarget::Azimuth(a), + }; + self.send(receiver, source, waypoint_operation::TRACK, &c.icon, target); + } + /// `ClientboundTrackedWaypointPacket.removeWaypoint`: an empty waypoint with the null icon. + fn disconnect(&mut self, receiver: u128, source: u128) { + self.send( + receiver, + source, + waypoint_operation::UNTRACK, + &Icon::default(), + WaypointTarget::Empty, + ); + } + /// `ChunkTrackingView.isInViewDistance` of the receiver's view. + fn chunk_visible(&self, [x, z]: [i32; 2], receiver: u128) -> bool { + let Some(&([cx, cz], r)) = self.view.get(&receiver) else { + return false; + }; + let dx = i64::from(((x - cx).abs() - 1).max(0)); + let dz = i64::from(((z - cz).abs() - 1).max(0)); + dx * dx + dz * dz < i64::from(r) * i64::from(r) + } + /// `WaypointTransmitter.doesSourceIgnoreReceiver`. + fn ignores(&self, source: &Player, receiver: &Player) -> bool { + if receiver.spectator { + return false; + } + if source.spectator { + return true; + } + let range = source.transmit_range.min(receiver.receive_range); + f64::from(source.distance_to(receiver)) >= range + } + fn really_far(source: &Player, receiver: &Player) -> bool { + source.distance_to(receiver) > REALLY_FAR + } + /// `EntityAzimuthConnection`: the angle of the receiver seen from the source, + /// `Mth.atan2` of the offset turned clockwise. + fn azimuth(source: &Player, receiver: &Player) -> f32 { + let d = [0, 1, 2].map(|k| receiver.position[k] - source.position[k]); + horizon_core::geometry::trig::atan2(d[0], -d[2]) as f32 + } + /// `LivingEntity.makeWaypointConnectionWith`. + fn make(&self, source: u128, receiver: u128) -> Option { + let (s, r) = (self.players.get(&source)?, self.players.get(&receiver)?); + if s.first_tick || self.fresh.contains(&source) || source == receiver || self.ignores(s, r) + { + return None; + } + // Waypoint.Icon.cloneAndAssignStyle: the icon's colour, else the team's. + let mut icon = s.icon.clone(); + if icon.color.is_none() { + icon.color = s.team.as_ref().and_then(|t| t.1); + } + let kind = if Self::really_far(s, r) { + Kind::Azimuth(Self::azimuth(s, r)) + } else if !self.chunk_visible(s.chunk(), receiver) { + Kind::Chunk(s.chunk()) + } else { + Kind::Block(s.block()) + }; + Some(Connection { kind, icon }) + } + /// `Connection.isBroken` for each kind. + fn broken(&self, c: &Connection, source: u128, receiver: u128) -> bool { + let (Some(s), Some(r)) = (self.players.get(&source), self.players.get(&receiver)) else { + return true; + }; + match c.kind { + Kind::Block(last) => { + let now = s.block(); + (0..3).map(|k| (now[k] - last[k]).abs()).sum::() > 1 || self.ignores(s, r) + } + Kind::Chunk(last) => { + let now = s.chunk(); + let moved = (now[0] - last[0]).abs().max((now[1] - last[1]).abs()); + moved > 1 || self.ignores(s, r) || self.chunk_visible(last, receiver) + } + Kind::Azimuth(_) => { + self.ignores(s, r) + || self.chunk_visible(s.chunk(), receiver) + || !Self::really_far(s, r) + } + } + } + /// `Connection.update`: the packet when the waypoint moved. + fn update(&mut self, c: &mut Connection, source: u128, receiver: u128) { + let (Some(s), Some(r)) = (self.players.get(&source), self.players.get(&receiver)) else { + return; + }; + let target = match &mut c.kind { + Kind::Block(last) => { + let now = s.block(); + if now == *last { + return; + } + *last = now; + WaypointTarget::Block(now) + } + Kind::Chunk(last) => { + let now = s.chunk(); + if now == *last { + return; + } + *last = now; + WaypointTarget::Chunk(now) + } + Kind::Azimuth(last) => { + let now = Self::azimuth(s, r); + if (now - *last).abs() <= AZIMUTH_STEP { + return; + } + *last = now; + WaypointTarget::Azimuth(now) + } + }; + let icon = c.icon.clone(); + self.send(receiver, source, waypoint_operation::UPDATE, &icon, target); + } +} + +impl Waypoints { + fn connection(&mut self, receiver: u128, source: u128) -> Option<&mut Connection> { + self.connections + .get_mut(&receiver)? + .iter_mut() + .find(|(s, _)| *s == source) + .map(|(_, c)| c) + } + fn put(&mut self, receiver: u128, source: u128, c: Connection) { + let row = self.connections.entry(receiver).or_default(); + match row.iter_mut().find(|(s, _)| *s == source) { + Some(slot) => slot.1 = c, + None => row.push((source, c)), + } + } + fn take(&mut self, receiver: u128, source: u128) -> Option { + let row = self.connections.get_mut(&receiver)?; + let i = row.iter().position(|(s, _)| *s == source)?; + Some(row.remove(i).1) + } + + /// `createConnection`. + fn create_connection(&mut self, t: &mut Tick, receiver: u128, source: u128) { + if receiver == source || !t.enabled { + return; + } + match t.make(source, receiver) { + Some(c) => { + t.connect(receiver, source, &c); + self.put(receiver, source, c); + } + None => { + if self.take(receiver, source).is_some() { + t.disconnect(receiver, source); + } + } + } + } + /// `updateConnection`. + fn update_connection(&mut self, t: &mut Tick, receiver: u128, source: u128) { + if receiver == source || !t.enabled { + return; + } + let Some(mut c) = self.connection(receiver, source).cloned() else { + return; + }; + if !t.broken(&c, source, receiver) { + t.update(&mut c, source, receiver); + self.put(receiver, source, c); + return; + } + match t.make(source, receiver) { + Some(new) => { + t.connect(receiver, source, &new); + self.put(receiver, source, new); + } + None => { + t.disconnect(receiver, source); + self.take(receiver, source); + } + } + } + /// `trackWaypoint`. + fn track(&mut self, t: &mut Tick, source: u128) { + if !self.waypoints.contains(&source) { + self.waypoints.push(source); + } + for receiver in self.players.clone() { + self.create_connection(t, receiver, source); + } + } + /// `updateWaypoint`. + fn update_waypoint(&mut self, t: &mut Tick, source: u128) { + if !self.waypoints.contains(&source) { + return; + } + for receiver in self.players.clone() { + if self.connection(receiver, source).is_some() { + self.update_connection(t, receiver, source); + } else { + self.create_connection(t, receiver, source); + } + } + } + /// `untrackWaypoint`. + fn untrack(&mut self, t: &mut Tick, source: u128) { + for receiver in self.players.clone() { + if self.take(receiver, source).is_some() { + t.disconnect(receiver, source); + } + } + self.waypoints.retain(|w| *w != source); + } + /// `addPlayer`. + fn add_player(&mut self, t: &mut Tick, player: u128, transmitting: bool) { + if !self.players.contains(&player) { + self.players.push(player); + } + for source in self.waypoints.clone() { + self.create_connection(t, player, source); + } + if transmitting { + self.track(t, player); + } + } + /// `updatePlayer`. + fn update_player(&mut self, t: &mut Tick, player: u128) { + for source in self.waypoints.clone() { + if self.connection(player, source).is_some() { + self.update_connection(t, player, source); + } else { + self.create_connection(t, player, source); + } + } + } + /// `removePlayer`. + fn remove_player(&mut self, t: &mut Tick, player: u128) { + for (source, _) in self.connections.remove(&player).unwrap_or_default() { + t.disconnect(player, source); + } + self.untrack(t, player); + self.players.retain(|p| *p != player); + } + /// `breakAllConnections`. + fn break_all(&mut self, t: &mut Tick) { + for receiver in self.players.clone() { + for (source, _) in self.connections.remove(&receiver).unwrap_or_default() { + t.disconnect(receiver, source); + } + } + self.connections.clear(); + } + + /// One tick: players who left, joined, moved, hid or changed team, and the + /// `locator_bar` game rule. `respawned` players are removed and added again, + /// as `PlayerList.respawn` replaces the ServerPlayer. Returns the packets for + /// each connection. + pub fn tick( + &mut self, + players: &[Player], + respawned: &[u128], + locator_bar: bool, + ) -> Vec<(u32, C)> { + let mut t = Tick { + players: players.iter().map(|p| (p.uuid, p)).collect(), + view: HashMap::new(), + fresh: respawned, + enabled: locator_bar, + out: Vec::new(), + }; + // Vanilla reads the rule when it connects; changing it breaks or remakes + // every connection (MinecraftServer.onGameRuleChanged). + let was = self.enabled.replace(locator_bar); + for (uuid, memo) in &self.memo { + if let Some(p) = t.players.get(uuid) { + t.view.insert(*uuid, (memo.view_center, p.view_distance)); + } + } + // Players who left, and the ServerPlayer a respawn replaced. + let gone: Vec = self + .players + .iter() + .copied() + .filter(|uuid| !t.players.contains_key(uuid) || respawned.contains(uuid)) + .collect(); + for uuid in gone { + self.remove_player(&mut t, uuid); + self.memo.remove(&uuid); + } + if was == Some(true) && !locator_bar { + self.break_all(&mut t); + } + // Players who joined (PlayerList.placeNewPlayer: addPlayer). + for p in players { + if self.memo.contains_key(&p.uuid) { + continue; + } + let center = p.chunk(); + t.view.insert(p.uuid, (center, p.view_distance)); + let transmitting = p.transmit_range > 0.0; + self.memo.insert( + p.uuid, + Memo { + position: p.position, + view_center: center, + transmitting, + team: p.team.clone(), + }, + ); + if p.receive_range > 0.0 { + self.add_player(&mut t, p.uuid, transmitting); + } else if transmitting { + self.track(&mut t, p.uuid); + } + } + if was == Some(false) && locator_bar { + for player in self.players.clone() { + self.update_player(&mut t, player); + } + } + for p in players { + let memo = &self.memo[&p.uuid]; + // Entity.setPosRaw, then ServerChunkCache.move. + if memo.position != p.position { + let moved_view = memo.view_center != p.chunk(); + let transmitting = memo.transmitting; + self.memo.get_mut(&p.uuid).unwrap().position = p.position; + if !p.first_tick { + if transmitting { + self.update_waypoint(&mut t, p.uuid); + } + if p.receive_range > 0.0 { + self.update_player(&mut t, p.uuid); + } + } + if moved_view { + self.memo.get_mut(&p.uuid).unwrap().view_center = p.chunk(); + t.view.insert(p.uuid, (p.chunk(), p.view_distance)); + } + if p.receive_range > 0.0 { + self.update_player(&mut t, p.uuid); + } + } + // LivingEntity.onAttributeUpdated(WAYPOINT_TRANSMIT_RANGE). + let transmitting = p.transmit_range > 0.0; + if transmitting != self.memo[&p.uuid].transmitting { + self.memo.get_mut(&p.uuid).unwrap().transmitting = transmitting; + if transmitting { + self.track(&mut t, p.uuid); + } else { + self.untrack(&mut t, p.uuid); + } + } + // ServerScoreboard: a team joined, left or recoloured remakes the connections. + if p.team != self.memo[&p.uuid].team { + self.memo.get_mut(&p.uuid).unwrap().team = p.team.clone(); + for receiver in self.players.clone() { + self.create_connection(&mut t, receiver, p.uuid); + } + } + } + t.out + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn player(uuid: u128, conn: u32, position: [f64; 3]) -> Player { + Player { + uuid, + conn: Some(conn), + position, + spectator: false, + transmit_range: PLAYER_RANGE, + receive_range: PLAYER_RANGE, + first_tick: false, + view_distance: 4, + team: None, + icon: Icon::default(), + } + } + + /// The packets to `conn`, as (operation, target). + fn to(out: &[(u32, C)], conn: u32) -> Vec<(i32, WaypointTarget)> { + out.iter() + .filter(|(c, _)| *c == conn) + .map(|(_, p)| match p { + C::TrackedWaypoint(w) => (w.operation, w.target), + other => panic!("{other:?}"), + }) + .collect() + } + + #[test] + fn a_new_player_shows_once_it_moves() { + let mut w = Waypoints::default(); + let a = player(1, 10, [0.5, 100.0, 0.5]); + let mut b = player(2, 20, [5.5, 100.0, 0.5]); + b.first_tick = true; + w.tick(std::slice::from_ref(&a), &[], true); + let out = w.tick(&[a.clone(), b.clone()], &[], true); + // B gets A at once; A sees nothing of B while B hasn't ticked. + assert_eq!(to(&out, 20), [(0, WaypointTarget::Block([0, 100, 0]))]); + assert!(to(&out, 10).is_empty()); + b.first_tick = false; + assert!(w.tick(&[a.clone(), b.clone()], &[], true).is_empty()); + b.position[0] += 1.0; + let out = w.tick(&[a.clone(), b.clone()], &[], true); + assert_eq!(to(&out, 10), [(0, WaypointTarget::Block([6, 100, 0]))]); + // One block: an update. Three: a new connection. Out of view: a chunk. + b.position[0] += 1.0; + let out = w.tick(&[a.clone(), b.clone()], &[], true); + assert_eq!(to(&out, 10), [(2, WaypointTarget::Block([7, 100, 0]))]); + b.position[0] += 3.0; + let out = w.tick(&[a.clone(), b.clone()], &[], true); + assert_eq!(to(&out, 10), [(0, WaypointTarget::Block([10, 100, 0]))]); + b.position[0] = 100.5; + let out = w.tick(&[a.clone(), b.clone()], &[], true); + assert_eq!(to(&out, 10), [(0, WaypointTarget::Chunk([6, 0]))]); + // Really far: an angle. + b.position[0] = 1000.5; + let out = w.tick(&[a.clone(), b.clone()], &[], true); + assert!(matches!( + to(&out, 10)[..], + [(0, WaypointTarget::Azimuth(_))] + )); + // Hidden: untracked; the rule off: every connection broken. + b.transmit_range = 0.0; + let out = w.tick(&[a.clone(), b.clone()], &[], true); + assert_eq!(to(&out, 10), [(1, WaypointTarget::Empty)]); + let out = w.tick(&[a.clone(), b.clone()], &[], false); + assert_eq!(to(&out, 20), [(1, WaypointTarget::Empty)]); + assert!(to(&out, 10).is_empty()); + // Leaving untracks what was left. + let out = w.tick(&[a.clone(), b.clone()], &[], true); + assert!(matches!( + to(&out, 20)[..], + [(0, WaypointTarget::Azimuth(_))] + )); + let out = w.tick(&[b.clone()], &[], true); + assert_eq!(to(&out, 20), [(1, WaypointTarget::Empty)]); + } + + #[test] + fn team_colours() { + assert_eq!(team_rgb("red"), Some(0xFF5555)); + assert_eq!(team_rgb("black"), Some(0xFF30_3030_u32 as i32)); + assert_eq!(team_rgb("reset"), None); + } +} diff --git a/crates/horizon-protocol/src/packets/play.rs b/crates/horizon-protocol/src/packets/play.rs index 2152d5716..b6fee1757 100644 --- a/crates/horizon-protocol/src/packets/play.rs +++ b/crates/horizon-protocol/src/packets/play.rs @@ -1068,12 +1068,126 @@ packet_enum!(Clientbound, crate::ids::play::clientbound { TeleportEntity(TeleportEntity) = TELEPORT_ENTITY, UpdateMobEffect(UpdateMobEffect) = UPDATE_MOB_EFFECT, UpdateTags(UpdateTags) = UPDATE_TAGS, + TrackedWaypoint(TrackedWaypoint) = WAYPOINT, }); packet!( /// ClientboundClearTitlesPacket: whether to also reset the timings. Bool1 { value: bool => Bool } ); +/// ClientboundTrackedWaypointPacket.Operation, by ordinal. +pub mod waypoint_operation { + pub const TRACK: i32 = 0; + pub const UNTRACK: i32 = 1; + pub const UPDATE: i32 = 2; +} + +/// TrackedWaypoint's identifier: `Either`. +#[derive(Clone, Debug, PartialEq)] +pub enum WaypointId { + Uuid(u128), + Name(String), +} + +/// What a TrackedWaypoint points at (its `Type` and contents). +#[derive(Clone, Copy, Debug, PartialEq)] +pub enum WaypointTarget { + /// `TrackedWaypoint.empty`: an untracked waypoint. + Empty, + /// A block position (`Vec3iWaypoint`). + Block([i32; 3]), + /// A chunk (`ChunkWaypoint`). + Chunk([i32; 2]), + /// An angle in radians (`AzimuthWaypoint`). + Azimuth(f32), +} + +/// ClientboundTrackedWaypointPacket: the locator bar's waypoints. +#[derive(Clone, Debug, PartialEq)] +pub struct TrackedWaypoint { + /// `waypoint_operation`. + pub operation: i32, + pub id: WaypointId, + /// Waypoint.Icon: the style (a `waypoint_style_asset` key) and an RGB colour. + pub style: String, + pub color: Option, + pub target: WaypointTarget, +} + +impl Codec for TrackedWaypoint { + fn read(r: &mut Reader) -> Result { + let operation = r.varint()?; + if !(0..=2).contains(&operation) { + return Err(Error::new(format!("waypoint operation {operation}"))); + } + let id = if r.bool()? { + WaypointId::Uuid(r.uuid()?) + } else { + WaypointId::Name(r.string(32767)?) + }; + let style = Ident::read(r)?; + // ByteBufCodecs.RGB_COLOR: three bytes, read back as an opaque ARGB colour. + let color = if r.bool()? { + let [red, green, blue] = [r.u8()?, r.u8()?, r.u8()?].map(i32::from); + Some(-16_777_216 | red << 16 | green << 8 | blue) + } else { + None + }; + let target = match r.varint()? { + 0 => WaypointTarget::Empty, + 1 => WaypointTarget::Block([r.varint()?, r.varint()?, r.varint()?]), + 2 => WaypointTarget::Chunk([r.varint()?, r.varint()?]), + 3 => WaypointTarget::Azimuth(r.f32()?), + other => return Err(Error::new(format!("waypoint type {other}"))), + }; + Ok(TrackedWaypoint { + operation, + id, + style, + color, + target, + }) + } + fn write(v: &TrackedWaypoint, w: &mut Writer) { + w.varint(v.operation); + match &v.id { + WaypointId::Uuid(uuid) => { + w.bool(true); + w.uuid(*uuid); + } + WaypointId::Name(name) => { + w.bool(false); + w.string(name); + } + } + w.string(&v.style); + w.bool(v.color.is_some()); + if let Some(color) = v.color { + for shift in [16, 8, 0] { + w.u8((color >> shift) as u8); + } + } + match v.target { + WaypointTarget::Empty => w.varint(0), + WaypointTarget::Block([x, y, z]) => { + w.varint(1); + w.varint(x); + w.varint(y); + w.varint(z); + } + WaypointTarget::Chunk([x, z]) => { + w.varint(2); + w.varint(x); + w.varint(z); + } + WaypointTarget::Azimuth(angle) => { + w.varint(3); + w.f32(angle); + } + } + } +} + // ---- serverbound ------------------------------------------------------- packet!(AcceptTeleportation { id: i32 => VarInt, x: f64 => Double, y: f64 => Double, z: f64 => Double, yaw: f32 => Float, pitch: f32 => Float }); @@ -1288,6 +1402,42 @@ mod tests { } } + #[test] + fn tracked_waypoint_bytes() { + // TRACK, a UUID, the default style, red (#FF5555), a block position. + let track = Clientbound::TrackedWaypoint(TrackedWaypoint { + operation: waypoint_operation::TRACK, + id: WaypointId::Uuid(0x0102_0304_0506_0708_090a_0b0c_0d0e_0f10), + style: "minecraft:default".into(), + color: Some(0xFFFF_5555_u32 as i32), + target: WaypointTarget::Block([1, -2, 300]), + }); + let mut expected = vec![141, 1, 0, 1]; + expected.extend(1..=16u8); + expected.push(17); + expected.extend(b"minecraft:default"); + expected.extend([ + 1, 0xFF, 0x55, 0x55, 1, 1, 0xFE, 0xFF, 0xFF, 0xFF, 0x0F, 0xAC, 0x02, + ]); + assert_eq!(track.encode(), expected); + assert_eq!(Clientbound::decode(141, &expected[2..]).unwrap(), track); + for target in [ + WaypointTarget::Empty, + WaypointTarget::Chunk([-3, 4]), + WaypointTarget::Azimuth(-1.25), + ] { + let packet = Clientbound::TrackedWaypoint(TrackedWaypoint { + operation: waypoint_operation::UPDATE, + id: WaypointId::Name("spawn".into()), + style: "minecraft:bowtie".into(), + color: None, + target, + }); + let bytes = packet.encode(); + assert_eq!(Clientbound::decode(141, &bytes[2..]).unwrap(), packet); + } + } + #[test] fn clientbound_round_trips() { let packets = vec![ diff --git a/mods/horizon/src/test/java/dev/horizonlab/parity/LocatorBarClient.java b/mods/horizon/src/test/java/dev/horizonlab/parity/LocatorBarClient.java new file mode 100644 index 000000000..e41c693ee --- /dev/null +++ b/mods/horizon/src/test/java/dev/horizonlab/parity/LocatorBarClient.java @@ -0,0 +1,382 @@ +package dev.horizonlab.parity; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.DataInputStream; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.zip.Deflater; +import java.util.zip.Inflater; +import net.minecraft.SharedConstants; +import net.minecraft.core.UUIDUtil; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.ProtocolInfo; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.common.ClientboundDisconnectPacket; +import net.minecraft.network.protocol.common.ClientboundKeepAlivePacket; +import net.minecraft.network.protocol.common.ClientboundPingPacket; +import net.minecraft.network.protocol.common.ServerboundClientInformationPacket; +import net.minecraft.network.protocol.common.ServerboundCustomPayloadPacket; +import net.minecraft.network.protocol.common.ServerboundKeepAlivePacket; +import net.minecraft.network.protocol.common.ServerboundPongPacket; +import net.minecraft.network.protocol.common.custom.BrandPayload; +import net.minecraft.network.protocol.configuration.ClientboundFinishConfigurationPacket; +import net.minecraft.network.protocol.configuration.ClientboundSelectKnownPacks; +import net.minecraft.network.protocol.configuration.ConfigurationProtocols; +import net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket; +import net.minecraft.network.protocol.configuration.ServerboundSelectKnownPacks; +import net.minecraft.network.protocol.game.ClientboundChunkBatchFinishedPacket; +import net.minecraft.network.protocol.game.ClientboundPlayerPositionPacket; +import net.minecraft.network.protocol.game.ClientboundSystemChatPacket; +import net.minecraft.network.protocol.game.ClientboundTrackedWaypointPacket; +import net.minecraft.network.protocol.game.GameProtocols; +import net.minecraft.network.protocol.game.ServerboundAcceptTeleportationPacket; +import net.minecraft.network.protocol.game.ServerboundChatCommandPacket; +import net.minecraft.network.protocol.game.ServerboundChunkBatchReceivedPacket; +import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket; +import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket; +import net.minecraft.network.protocol.game.ServerboundPlayerLoadedPacket; +import net.minecraft.network.protocol.handshake.ClientIntent; +import net.minecraft.network.protocol.handshake.ClientIntentionPacket; +import net.minecraft.network.protocol.handshake.HandshakeProtocols; +import net.minecraft.network.protocol.login.ClientboundLoginCompressionPacket; +import net.minecraft.network.protocol.login.ClientboundLoginDisconnectPacket; +import net.minecraft.network.protocol.login.ClientboundLoginFinishedPacket; +import net.minecraft.network.protocol.login.LoginProtocols; +import net.minecraft.network.protocol.login.ServerboundHelloPacket; +import net.minecraft.network.protocol.login.ServerboundLoginAcknowledgedPacket; +import net.minecraft.server.level.ClientInformation; +import net.minecraft.world.entity.PositionMoveRotation; +import net.minecraft.world.entity.player.Input; +import net.minecraft.world.phys.Vec3; + +/** + * Players made of vanilla's own protocol code, for the locator bar + * (tools/test_locator_bar_parity.py). Each joins in offline mode, answers + * keep-alives, pings, teleports and chunk batches, and records every + * ClientboundTrackedWaypointPacket it receives, decoded by vanilla's codec + * (a byte vanilla would not read is an error) and summarised from its bytes. + * + *

{@code LocatorBarClient HOST PORT OUT} takes its script on stdin, one + * line at a time: {@code step LABEL} (the label the next packets are recorded + * under), {@code join NAME}, {@code cmd NAME COMMAND...}, {@code shift NAME + * on|off} (the shift key, as ServerboundPlayerInputPacket), {@code fly NAME + * on|off} (ServerboundPlayerAbilitiesPacket), {@code quit NAME} and {@code + * end}, which writes each player's lines to OUT. + */ +public final class LocatorBarClient { + private static volatile String step = "start"; + private static final Map NAMES = new LinkedHashMap<>(); + + public static void main(String[] args) throws Exception { + ParityData.init(); + String host = args[0]; + int port = Integer.parseInt(args[1]); + Path output = Path.of(args[2]); + Map players = new LinkedHashMap<>(); + BufferedReader script = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); + String line; + while ((line = script.readLine()) != null) { + String[] w = line.trim().split(" ", 3); + try { + switch (w[0]) { + case "step" -> step = w[1]; + case "join" -> { + Player p = new Player(w[1]); + players.put(w[1], p); + NAMES.put(UUIDUtil.createOfflinePlayerUUID(w[1]), w[1]); + p.join(host, port); + } + case "cmd" -> players.get(w[1]).command(w[2]); + case "shift" -> players.get(w[1]).send(new ServerboundPlayerInputPacket( + new Input(false, false, false, false, false, w[2].equals("on"), false))); + case "fly" -> { + net.minecraft.world.entity.player.Abilities abilities = new net.minecraft.world.entity.player.Abilities(); + abilities.flying = w[2].equals("on"); + players.get(w[1]).send(new net.minecraft.network.protocol.game.ServerboundPlayerAbilitiesPacket(abilities)); + } + case "quit" -> players.get(w[1]).close(); + case "end" -> { + try (PrintWriter out = new PrintWriter(Files.newBufferedWriter(output, StandardCharsets.UTF_8))) { + for (Player p : players.values()) { + synchronized (p.lines) { + for (String l : p.lines) out.println(p.name + " " + l); + } + } + } + for (Player p : players.values()) p.close(); + System.exit(0); + } + default -> throw new IllegalArgumentException("unknown script line " + line); + } + } catch (Exception e) { + Player p = w.length > 1 ? players.get(w[1]) : null; + if (p != null) p.record("error " + w[0] + " " + e); + else System.err.println("error " + line + ": " + e); + } + } + System.exit(1); + } + + /** The waypoint packet's fields, read back from its bytes (the operation and type are private enums). */ + static String waypoint(byte[] payload) { + FriendlyByteBuf b = new FriendlyByteBuf(Unpooled.wrappedBuffer(payload)); + b.readVarInt(); // the packet id + String operation = switch (b.readVarInt()) { + case 0 -> "track"; + case 1 -> "untrack"; + case 2 -> "update"; + default -> "operation?"; + }; + String id = b.readBoolean() ? NAMES.getOrDefault(b.readUUID(), "uuid?") : "name:" + b.readUtf(); + String style = b.readUtf(); + String color = b.readBoolean() ? String.format("#%02x%02x%02x", b.readUnsignedByte(), b.readUnsignedByte(), b.readUnsignedByte()) : "-"; + String target = switch (b.readVarInt()) { + case 0 -> "empty"; + case 1 -> "block " + b.readVarInt() + " " + b.readVarInt() + " " + b.readVarInt(); + case 2 -> "chunk " + b.readVarInt() + " " + b.readVarInt(); + case 3 -> "azimuth " + b.readFloat(); + default -> "type?"; + }; + return operation + " " + id + " " + style + " " + color + " " + target; + } + + /** One connection: login and configuration in the caller's thread, then play on its own. */ + private static final class Player { + final String name; + final List lines = new ArrayList<>(); + private Socket socket; + private DataInputStream in; + private OutputStream out; + private int threshold = -1; + private ProtocolInfo inbound; + private ProtocolInfo outbound; + private PositionMoveRotation position = new PositionMoveRotation(Vec3.ZERO, Vec3.ZERO, 0, 0); + private boolean loaded; + private final Object replyLock = new Object(); + private int replies; + + Player(String name) { + this.name = name; + } + + /** Runs a command and waits for its feedback, so a slow server still takes each step in its step. */ + void command(String command) throws Exception { + synchronized (replyLock) { + int before = replies; + send(new ServerboundChatCommandPacket(command)); + long until = System.nanoTime() + 30_000_000_000L; + while (replies == before) { + long left = (until - System.nanoTime()) / 1_000_000L; + if (left <= 0) { + record("error no reply to /" + command); + return; + } + replyLock.wait(left); + } + } + } + + void record(String line) { + synchronized (lines) { + lines.add("step=" + step + " " + line); + } + } + + void close() throws Exception { + if (socket != null) socket.close(); + } + + void join(String host, int port) throws Exception { + socket = new Socket(); + socket.connect(new InetSocketAddress(host, port), 10_000); + socket.setTcpNoDelay(true); + in = new DataInputStream(socket.getInputStream()); + out = socket.getOutputStream(); + outbound = HandshakeProtocols.SERVERBOUND; + send(new ClientIntentionPacket(SharedConstants.getProtocolVersion(), host, port, ClientIntent.LOGIN)); + outbound = LoginProtocols.SERVERBOUND; + inbound = LoginProtocols.CLIENTBOUND; + send(new ServerboundHelloPacket(name, UUIDUtil.createOfflinePlayerUUID(name))); + while (true) { + Packet p = read().packet; + if (p instanceof ClientboundLoginCompressionPacket c) { + threshold = c.getCompressionThreshold(); + } else if (p instanceof ClientboundLoginFinishedPacket) { + send(ServerboundLoginAcknowledgedPacket.INSTANCE); + break; + } else if (p instanceof ClientboundLoginDisconnectPacket d) { + throw new IllegalStateException("login refused: " + d.reason().getString()); + } + } + outbound = ConfigurationProtocols.SERVERBOUND; + inbound = ConfigurationProtocols.CLIENTBOUND; + send(new ServerboundCustomPayloadPacket(new BrandPayload("vanilla"))); + send(new ServerboundClientInformationPacket(ClientInformation.createDefault())); + while (true) { + Packet p = read().packet; + if (p instanceof ClientboundSelectKnownPacks k) { + send(new ServerboundSelectKnownPacks(k.knownPacks())); + } else if (p instanceof ClientboundKeepAlivePacket k) { + send(new ServerboundKeepAlivePacket(k.getId())); + } else if (p instanceof ClientboundPingPacket k) { + send(new ServerboundPongPacket(k.getId())); + } else if (p instanceof ClientboundFinishConfigurationPacket) { + send(ServerboundFinishConfigurationPacket.INSTANCE); + break; + } else if (p instanceof ClientboundDisconnectPacket d) { + throw new IllegalStateException("disconnected: " + d.reason().getString()); + } + } + GameProtocols.Context context = new GameProtocols.Context() { + @Override + public boolean hasInfiniteMaterials() { + return true; + } + + @Override + public boolean canUseCommandBlocks() { + return true; + } + }; + outbound = GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(ParityData.access), context); + inbound = GameProtocols.CLIENTBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(ParityData.access)); + Thread reader = new Thread(this::play, name); + reader.setDaemon(true); + reader.start(); + } + + private void play() { + try { + while (true) { + Received r = read(); + Packet p = r.packet; + if (p instanceof ClientboundTrackedWaypointPacket) { + record(waypoint(r.payload)); + } else if (p instanceof ClientboundSystemChatPacket) { + synchronized (replyLock) { + replies++; + replyLock.notifyAll(); + } + } else if (p instanceof ClientboundKeepAlivePacket k) { + send(new ServerboundKeepAlivePacket(k.getId())); + } else if (p instanceof ClientboundPingPacket k) { + send(new ServerboundPongPacket(k.getId())); + } else if (p instanceof ClientboundPlayerPositionPacket t) { + position = PositionMoveRotation.calculateAbsolute(position, t.change(), t.relatives()); + Vec3 at = position.position(); + send(new ServerboundAcceptTeleportationPacket(t.id(), at.x, at.y, at.z, position.yRot(), position.xRot())); + // Only the spawn teleport is answered with a position too (VanillaProtocolClient). + if (!loaded) { + send(new ServerboundMovePlayerPacket.PosRot(at, position.yRot(), position.xRot(), false, false)); + send(new ServerboundPlayerLoadedPacket()); + loaded = true; + } + } else if (p instanceof ClientboundChunkBatchFinishedPacket) { + send(new ServerboundChunkBatchReceivedPacket(64.0F)); + } else if (p instanceof ClientboundDisconnectPacket d) { + record("disconnected " + d.reason().getString()); + return; + } + } + } catch (Exception e) { + if (!socket.isClosed()) record("error play " + e); + } + } + + private record Received(Packet packet, byte[] payload) {} + + private Received read() throws Exception { + byte[] payload = readFrame(); + ByteBuf buf = Unpooled.wrappedBuffer(payload); + Packet packet = inbound.codec().decode(buf); + if (buf.readableBytes() > 0) { + throw new IllegalStateException(packet.type().id() + " was larger than expected: " + buf.readableBytes() + " bytes left"); + } + return new Received(packet, payload); + } + + synchronized void send(Packet packet) throws Exception { + ByteBuf body = Unpooled.buffer(); + ((ProtocolInfo) outbound).codec().encode(body, packet); + byte[] raw = new byte[body.readableBytes()]; + body.readBytes(raw); + ByteBuf frame = Unpooled.buffer(); + if (threshold >= 0) { + ByteBuf inner = Unpooled.buffer(); + if (raw.length >= threshold) { + writeVarInt(inner, raw.length); + Deflater d = new Deflater(); + d.setInput(raw); + d.finish(); + byte[] tmp = new byte[raw.length + 64]; + while (!d.finished()) inner.writeBytes(tmp, 0, d.deflate(tmp)); + d.end(); + } else { + writeVarInt(inner, 0); + inner.writeBytes(raw); + } + writeVarInt(frame, inner.readableBytes()); + frame.writeBytes(inner); + } else { + writeVarInt(frame, raw.length); + frame.writeBytes(raw); + } + byte[] bytes = new byte[frame.readableBytes()]; + frame.readBytes(bytes); + out.write(bytes); + out.flush(); + } + + private byte[] readFrame() throws Exception { + byte[] frame = new byte[readVarInt(in)]; + in.readFully(frame); + if (threshold < 0) return frame; + ByteArrayInputStream header = new ByteArrayInputStream(frame); + int dataLength = readVarInt(header); + int skip = frame.length - header.available(); + if (dataLength == 0) return java.util.Arrays.copyOfRange(frame, skip, frame.length); + Inflater inflater = new Inflater(); + inflater.setInput(frame, skip, frame.length - skip); + byte[] raw = new byte[dataLength]; + int n = inflater.inflate(raw); + inflater.end(); + if (n != dataLength) throw new IllegalStateException("decompressed " + n + " of " + dataLength + " bytes"); + return raw; + } + } + + private static int readVarInt(InputStream in) throws Exception { + int value = 0; + for (int shift = 0; shift < 35; shift += 7) { + int b = in.read(); + if (b < 0) throw new java.io.EOFException(); + value |= (b & 0x7F) << shift; + if ((b & 0x80) == 0) return value; + } + throw new IllegalStateException("VarInt too big"); + } + + private static void writeVarInt(ByteBuf buf, int value) { + while ((value & ~0x7F) != 0) { + buf.writeByte((value & 0x7F) | 0x80); + value >>>= 7; + } + buf.writeByte(value); + } +} diff --git a/tools/test_locator_bar_parity.py b/tools/test_locator_bar_parity.py new file mode 100644 index 000000000..bc7d21750 --- /dev/null +++ b/tools/test_locator_bar_parity.py @@ -0,0 +1,259 @@ +#!/usr/bin/env python3 +"""The locator bar on a dedicated server, against vanilla's, seen by vanilla clients. + +A vanilla dedicated server and Horizon's (`horizon-client --dedicated --nogui`) each serve a copy of one flat +world vanilla generated first (players appear at its spawn), with the same server.properties (offline, +creative, view distance 4) and two operators. LocatorBarClient, two +players made of vanilla's protocol code (any byte vanilla would not read is an error), joins Alice and then +Bob, who fly as creative players do (a player floating without flying falls on the server every tick), and +records every ClientboundTrackedWaypointPacket each of them receives. Bob then: + +- teleports one block, three blocks, out of Alice's view, one chunk on, really far (an azimuth) and turns + around her, and back; +- turns invisible and visible, joins a red team (by the console), has it turned blue, leaves it; +- crouches and stands up, wears a carved pumpkin and takes it off; +- turns spectator and moves, then creative again; + +the console turns the `locator_bar` game rule off and on, and Bob leaves. The waypoint packets each player +received in each step are compared exactly: operation, player, style, colour and the block, chunk or angle. +""" +import os +from pathlib import Path +import platform +import shutil +import subprocess +import sys +import time + +try: + from . import lab, test_rust_parity as base + from .test_dedicated_server_parity import Server, free_port +except ImportError: + import lab + import test_rust_parity as base + from test_dedicated_server_parity import Server, free_port + +NAME = 'locator-bar-parity' +PROPERTIES = { + 'online-mode': 'false', + 'white-list': 'false', + 'level-seed': '12345', + 'level-type': 'minecraft\\:flat', + 'generate-structures': 'false', + 'gamemode': 'creative', + 'force-gamemode': 'true', + 'view-distance': '4', + 'simulation-distance': '4', + 'spawn-protection': '0', + 'max-players': '5', + 'pause-when-empty-seconds': '-1', +} +PLAYERS = ['Alice', 'Bob'] + +# (label, [what the console does], [what the players do]); every step then waits for its packets. +SCRIPT = [ + ('alice-joins', [], ['join Alice', 'fly Alice on', 'cmd Alice tp @s 0.5 100 0.5']), + ('bob-joins', [], ['join Bob', 'fly Bob on', 'cmd Bob tp @s 2.5 100 0.5']), + ('near', [], ['cmd Bob tp @s 5.5 100 0.5']), + ('one-block', [], ['cmd Bob tp @s 6.5 100 0.5']), + ('three-blocks', [], ['cmd Bob tp @s 9.5 100 0.5']), + ('out-of-view', [], ['cmd Bob tp @s 100.5 100 0.5']), + ('next-chunk', [], ['cmd Bob tp @s 116.5 100 0.5']), + ('really-far', [], ['cmd Bob tp @s 1000.5 100 0.5']), + ('turn-around', [], ['cmd Bob tp @s 1000.5 100 300.5']), + ('half-degree', [], ['cmd Bob tp @s 1000.5 100 302.5']), + ('invisible', [], ['cmd Bob effect give @s minecraft:invisibility infinite 0 true']), + ('visible', [], ['cmd Bob effect clear @s']), + ('back-near', [], ['cmd Bob tp @s 3.5 100 0.5']), + ('red-team', ['team add red', 'team modify red color red', 'team join red Bob'], []), + ('blue-team', ['team modify red color blue'], []), + ('no-team', ['team leave Bob'], []), + # Crouching needs the ground: a flying player who holds shift goes down instead. + ('landed', [], ['cmd Bob tp @s 3.5 -60 0.5', 'fly Bob off']), + ('crouch', [], ['shift Bob on']), + ('stand', [], ['shift Bob off']), + ('flying-again', [], ['fly Bob on', 'cmd Bob tp @s 3.5 100 0.5']), + ('pumpkin', [], ['cmd Bob item replace entity @s armor.head with minecraft:carved_pumpkin']), + ('no-pumpkin', [], ['cmd Bob item replace entity @s armor.head with minecraft:air']), + ('rule-off', ['gamerule locator_bar false'], []), + ('moves-without', [], ['cmd Bob tp @s 4.5 100 0.5']), + ('rule-on', ['gamerule locator_bar true'], []), + ('spectator', [], ['cmd Bob gamemode spectator', 'cmd Bob tp @s 5.5 100 0.5']), + ('creative', [], ['cmd Bob gamemode creative', 'cmd Bob tp @s 6.5 100 0.5']), + ('bob-leaves', [], ['quit Bob']), +] +STEP_SECONDS = 2.0 +# Vanilla's server moves a player who just joined on their own first ticks (a tiny step and back), which tracks +# them where they spawned; Horizon does not simulate its guests. These steps compare what the bar shows at +# their end (Bob has moved by then) rather than every packet. +SETTLING_STEPS = {'alice-joins', 'bob-joins'} + + +def shown(lines): + """The transcript with each settling step reduced to what each player's bar shows at its end.""" + out, state = [], {} + + def flush(step): + for (receiver, source), rest in sorted(state.items()): + out.append(f'{receiver} step={step} shows {source} {rest}') + state.clear() + + current = None + for line in lines: + receiver, step, *packet = line.split(' ') + step = step.removeprefix('step=') + if current in SETTLING_STEPS and step != current: + flush(current) + current = step + if step not in SETTLING_STEPS or len(packet) < 3: + out.append(line) + elif packet[0] == 'untrack': + state.pop((receiver, packet[1]), None) + else: + state[(receiver, packet[1])] = ' '.join(packet[2:]) + if current in SETTLING_STEPS: + flush(current) + return out + + +def ops_json(): + """Both players at level 4, by their offline UUIDs.""" + import hashlib + import json + import uuid as uuidlib + entries = [] + for name in PLAYERS: + digest = bytearray(hashlib.md5(f'OfflinePlayer:{name}'.encode()).digest()) + digest[6] = (digest[6] & 0x0F) | 0x30 + digest[8] = (digest[8] & 0x3F) | 0x80 + entries.append({'uuid': str(uuidlib.UUID(bytes=bytes(digest))), 'name': name, 'level': 4, + 'bypassesPlayerLimit': False}) + return json.dumps(entries, indent=2) + + +def server_dir(directory, world=None): + if directory.exists(): + shutil.rmtree(directory) + directory.mkdir(parents=True) + port = free_port() + props = dict(PROPERTIES, **{'server-port': str(port)}) + (directory / 'server.properties').write_text(''.join(f'{k}={v}\n' for k, v in props.items()), + encoding='iso-8859-1') + (directory / 'eula.txt').write_text('eula=true\n') + (directory / 'ops.json').write_text(ops_json()) + if world is not None: + shutil.copytree(world, directory / 'world') + (directory / 'world' / 'session.lock').unlink(missing_ok=True) + return port + + +def generate_world(server_command, build): + """The flat world both servers load, made once by vanilla: players appear at its spawn itself + (respawn_radius 0), on the ground at 0 -60 0, and the chunks around it are saved.""" + directory = build / 'generate' + server_dir(directory) + server = Server(server_command, directory, 'generate') + try: + server.wait_for(r'Done \(') + for command, reply in [('gamerule respawn_radius 0', 'respawn_radius'), + ('setworldspawn 0 -60 0', 'Set the world spawn'), + ('forceload add -96 -96 96 96', 'force loaded'), + ('save-all flush', 'Saved the game')]: + server.console(command) + server.wait_for(reply, timeout=120) + server.console('forceload remove all') + finally: + server.stop() + return directory / 'world' + + +def run_side(label, server_command, client_command, build, world): + directory = build / label + port = server_dir(directory, world) + out = build / f'{label}.txt' + out.unlink(missing_ok=True) + server = Server(server_command, directory, label) + try: + server.wait_for(r'Done \(') + with (build / f'{label}-client.log').open('w') as log: + client = subprocess.Popen([*map(str, client_command), '127.0.0.1', str(port), str(out)], + cwd=lab.ROOT, stdin=subprocess.PIPE, stdout=log, stderr=subprocess.STDOUT, + text=True) + try: + for step, console, actions in SCRIPT: + client.stdin.write(f'step {step}\n') + client.stdin.flush() + for command in console: + server.console(command) + for action in actions: + client.stdin.write(action + '\n') + client.stdin.flush() + if action.startswith('join'): + # Joining takes the world's first chunks: wait for the server to place the player. + server.wait_for(rf'{action.split()[1]} joined the game', timeout=120) + time.sleep(STEP_SECONDS) + client.stdin.write('end\n') + client.stdin.flush() + client.wait(timeout=60) + finally: + if client.poll() is None: + client.kill() + finally: + server.stop() + if not out.exists(): + raise AssertionError(f'{label}: the client wrote no transcript (see {build}/{label}-client.log)') + return out.read_text(encoding='utf-8').splitlines() + + +def main(): + lock, jars, libraries = base.verify_artifacts() + build = lab.LOCAL / NAME + build.mkdir(parents=True, exist_ok=True) + report = build / 'report.json' + report.unlink(missing_ok=True) + oracle = lab.ROOT / 'mods/horizon/src/test/java/dev/horizonlab/parity/LocatorBarClient.java' + classes = build / 'classes' + shutil.rmtree(classes, ignore_errors=True) + classes.mkdir() + dependencies = os.pathsep.join(map(str, [jars['server'], *libraries])) + subprocess.run(['javac', '--release', str(lock['minecraft']['java_major']), '-proc:none', '-nowarn', '-sourcepath', + lab.ROOT / 'mods/horizon/src/test/java', '-cp', dependencies, '-d', classes, oracle], + cwd=lab.ROOT, check=True, capture_output=True) + subprocess.run(['cargo', 'build', '--release', '-p', 'horizon-client', '--bin', 'horizon-client'], cwd=lab.ROOT, + check=True, capture_output=True) + import json + metadata = json.loads(subprocess.check_output(['cargo', 'metadata', '--no-deps', '--format-version', '1'], + cwd=lab.ROOT, text=True)) + binary = Path(metadata['target_directory']) / 'release' / ('horizon-client.exe' if os.name == 'nt' else 'horizon-client') + vanilla_server = ['java', '-Xmx2g', '-Duser.timezone=UTC', '-cp', dependencies, 'net.minecraft.server.Main', 'nogui'] + horizon_server = [binary, '--resources', lab.LOCAL / 'horizon-client/26.3', '--dedicated', '--nogui'] + client = ['java', '-Xmx1g', '-cp', str(classes) + os.pathsep + dependencies, 'dev.horizonlab.parity.LocatorBarClient'] + + world = generate_world(vanilla_server, build) + vanilla = run_side('vanilla', vanilla_server, client, build, world) + horizon = run_side('horizon', horizon_server, client, build, world) + errors = [l for l in vanilla + horizon if ' error ' in f' {l} ' or 'disconnected' in l] + vanilla, horizon = shown(vanilla), shown(horizon) + # Each player's packets in their order; which player's line comes first in a step doesn't matter. + if errors or vanilla != horizon: + import difflib + diff = '\n'.join(difflib.unified_diff(vanilla, horizon, 'vanilla', 'horizon', n=1, lineterm='')) + raise AssertionError(f'{len(errors)} errors, transcripts differ (see {build}/vanilla.txt and horizon.txt):\n' + + '\n'.join(errors[:10]) + '\n' + diff[:6000]) + if len(vanilla) < 20: + raise AssertionError(f'only {len(vanilla)} waypoint packets: the script did not run (see {build})') + lab.write_json(report, dict( + schema=1, minecraft=lock['minecraft']['version'], platform=platform.platform(), + java=subprocess.check_output(['java', '--version'], text=True).splitlines()[0], + packets=len(vanilla), output_sha256=lab.digest(build / 'horizon.txt', 'sha256'), + scope='Locator bar waypoints (ClientboundTrackedWaypointPacket) two vanilla-codec players receive on a ' + 'dedicated server: block, chunk and azimuth connections as one moves, invisibility, team colours, ' + 'crouching, a carved pumpkin, the locator_bar game rule, spectator mode and leaving.')) + print(f'locator bar: {len(vanilla)} waypoint packets identical') + + +if __name__ == '__main__': + try: + main() + except AssertionError as error: + sys.exit(f'{NAME}: {error}') From 516661592f8aaa337d2183799b654ef3345e4c50 Mon Sep 17 00:00:00 2001 From: Cosmic <84875247+Online5277@users.noreply.github.com> Date: Sat, 17 Oct 2026 04:41:31 -0400 Subject: [PATCH 28/46] Keep sleeping input camera and HUD in bed state --- crates/horizon-client/src/game.rs | 121 +++++++++++++++--- crates/horizon-client/src/game/fov.rs | 8 +- crates/horizon-client/src/game/hand.rs | 2 +- crates/horizon-client/src/game/perspective.rs | 2 +- 4 files changed, 109 insertions(+), 24 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 745644f2d..412c71c22 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -967,8 +967,9 @@ struct Game<'a> { /// `ClientAvatarState`: walked distance and view bob. avatar: horizon_client::camera::AvatarBob, flash: u32, - /// Sleeping in a bed: (bed head position, ticks asleep). - sleeping: Option<([i32; 3], u32)>, + /// The head of the bed while sleeping; the visual timer also survives waking. + sleeping: Option<[i32; 3]>, + sleep_timer: u32, dim: Dim, world_root: PathBuf, /// A player carried through a portal, re-placed once the destination loads. @@ -3182,7 +3183,7 @@ impl Game<'_> { if !self.streaming.is_lit(cx, cz) { return Ok(()); } - let playing = self.screen == Screen::Playing; + let playing = self.screen == Screen::Playing && self.sleeping.is_none(); let held = |k| playing && self.keys.contains(&k); let keys = Keys { forward: held(KeyCode::KeyW), @@ -3276,7 +3277,12 @@ impl Game<'_> { let feet = [player.position.x, player.position.y, player.position.z]; let player_velocity = [player.velocity.x, player.velocity.y, player.velocity.z]; self.previous_eye = self.eye; - self.eye += (camera_eye.unwrap_or(player.dimensions.eye_height) - self.eye) * 0.5; + let eye_height = if self.sleeping.is_some() { + 0.2 + } else { + player.dimensions.eye_height + }; + self.eye += (camera_eye.unwrap_or(eye_height) - self.eye) * 0.5; let crouching = player.pose == horizon_client::pose::Pose::Crouching; self.tick_avatar(before, riding); self.record_combat(&events); @@ -3539,7 +3545,11 @@ impl Game<'_> { }); horizon_client::spans::time("tick_particles", || self.tick_particles()); } - if self.right && self.use_delay == 0 && self.screen == Screen::Playing { + if self.right + && self.use_delay == 0 + && self.screen == Screen::Playing + && self.sleeping.is_none() + { self.use_with_hand()?; self.use_delay = 4; } @@ -3922,15 +3932,7 @@ impl Game<'_> { self.draw_boss_bars(&mut batch); self.draw_extras(&mut batch); } - // Hud.extractSleepOverlay, under the sidebar, titles and chat. - if let Some((_, ticks)) = self.sleeping { - let draws = hud_overlays::sleep_overlay(wi, hi, ticks as i32); - hud_layout::paint(&mut batch, &self.atlas, &draws); - } if show_hud { - self.draw_titles(&mut batch); - self.draw_scoreboard(&mut batch); - self.draw_subtitles(&mut batch); // The mount's hearts (and the jump bar that replaces the experience bar). let (vehicle_hearts, jump_bar) = if spectator { (0, false) @@ -4002,6 +4004,14 @@ impl Game<'_> { self.draw_selected_name(&mut batch, !self.creative); } } + // Hud.extractSleepOverlay: over all health/food bars, under titles and chat. + let draws = hud_overlays::sleep_overlay(wi, hi, self.sleep_timer as i32); + hud_layout::paint(&mut batch, &self.atlas, &draws); + if show_hud { + self.draw_titles(&mut batch); + self.draw_scoreboard(&mut batch); + self.draw_subtitles(&mut batch); + } let atlas = &self.atlas; if show_hud && let Some((text, at)) = &self.message @@ -6327,6 +6337,8 @@ impl Game<'_> { self.clear_entities(); self.travelling = None; self.player = None; + self.sleeping = None; + self.sleep_timer = 0; self.spawn = None; self.respawn_travel = None; self.respawn_config = @@ -6684,6 +6696,8 @@ impl Game<'_> { self.streaming.paused = true; self.world = World::new(self.res.facts.air, 0); self.player = None; + self.sleeping = None; + self.sleep_timer = 0; self.clear_entities(); self.screen = Screen::Playing; if let Some(r) = self.renderer.as_mut() { @@ -7513,6 +7527,7 @@ impl Game<'_> { // GameRenderer.renderItemInHand: F1 hides the hand with the HUD. if self.spectator() || self.ui.hide_gui + || self.sleeping.is_some() || !self.camera_type.first_person() || self .player @@ -7988,13 +8003,23 @@ impl Game<'_> { return; } self.message = Some(("Respawn point set".into(), Instant::now())); - self.sleeping = Some((head, 0)); + self.stop_mining(); + self.left = false; + self.right = false; + self.using = None; + self.sleeping = Some(head); + self.sleep_timer = 0; self.stats.custom("sleep_in_bed", 1); self.trigger_player("minecraft:slept_in_bed"); self.stats.reset("custom", "minecraft:time_since_rest"); } + fn wake_up(&mut self) { + self.sleeping = None; + self.sleep_timer = 100; + } fn tick_sleep(&mut self) { - let Some((head, ticks)) = self.sleeping else { + self.sleep_timer = tick_sleep_timer(self.sleep_timer, self.sleeping.is_some()); + let Some(head) = self.sleeping else { return; }; if self.keys.contains(&KeyCode::ShiftLeft) @@ -8003,7 +8028,7 @@ impl Game<'_> { .as_ref() .is_none_or(|p| p.health.dead_or_dying()) { - self.sleeping = None; + self.wake_up(); return; } if let Some(p) = self.player.as_mut() { @@ -8014,18 +8039,15 @@ impl Game<'_> { ); p.velocity = Vec3::ZERO; } - let ticks = ticks + 1; // ServerLevel: once everyone has slept 100 ticks, skip to morning and clear weather. - if ticks >= 100 { + if self.sleep_timer >= 100 { let t = self.world.day_time; self.world.day_time = t + 24000 - t.rem_euclid(24000); self.world.weather.raining = false; self.world.weather.thundering = false; self.world.weather.rain_time = 0; self.world.weather.thunder_time = 0; - self.sleeping = None; - } else { - self.sleeping = Some((head, ticks)); + self.wake_up(); } } fn creative_origin(batch: &HudBatch) -> (f32, f32) { @@ -8833,6 +8855,18 @@ impl Game<'_> { } /// A key press while a world is open (keyboard or control socket). fn key_pressed(&mut self, key: KeyCode) -> Result<()> { + if self.sleeping.is_some() + && self.screen == Screen::Playing + && !matches!( + key, + KeyCode::F1 | KeyCode::F2 | KeyCode::F11 | KeyCode::KeyT | KeyCode::Slash + ) + { + if matches!(key, KeyCode::Escape | KeyCode::ShiftLeft) { + self.wake_up(); + } + return Ok(()); + } if self.sort_key_press(key) { return Ok(()); } @@ -8963,6 +8997,9 @@ impl Game<'_> { } /// A mouse button while playing (window or control socket). fn play_mouse(&mut self, button: MouseButton, pressed: bool) -> Result<()> { + if self.sleeping.is_some() { + return Ok(()); + } if self.remote.is_some() { return self.remote_mouse(button, pressed); } @@ -9292,6 +9329,7 @@ impl ApplicationHandler for Game<'_> { title.scroll_worlds(d, self.cursor, (batch.width, batch.height)); } if self.screen == Screen::Playing + && self.sleeping.is_none() && self.player.is_some() && !self.extras_scroll(d) && let Some((wheel, _)) = @@ -10083,6 +10121,7 @@ impl<'a> Game<'a> { avatar: Default::default(), flash: 0, sleeping: None, + sleep_timer: 0, dim: Dim::Overworld, world_root: PathBuf::new(), travelling: None, @@ -10478,6 +10517,17 @@ pub fn run() -> Result<()> { Ok(()) } +// Player.tick: cap the sleeping fade at 100, then fade out over 10 waking ticks. +fn tick_sleep_timer(timer: u32, sleeping: bool) -> u32 { + if sleeping { + (timer + 1).min(100) + } else if (1..109).contains(&timer) { + timer + 1 + } else { + 0 + } +} + fn reset_world_progress(adv: &mut advancements::AdvState, stats: &mut stats::Stats) { *adv = Default::default(); *stats = Default::default(); @@ -10512,6 +10562,35 @@ mod tests { use horizon_client::container_screen::{Button, Clicks, Release, Target}; use horizon_client::keymapping::{KeyAction, SPRINT, ToggleKeys}; + #[test] + fn sleep_fade_lasts_ten_ticks_after_waking() { + let alpha = |timer| match hud_overlays::sleep_overlay(320, 240, timer).first() { + Some(hud_layout::GuiDraw::Fill { color, .. }) => color >> 24, + None => 0, + _ => panic!("sleep overlay must be a full-screen fill"), + }; + assert_eq!(tick_sleep_timer(0, false), 0); + let mut timer = 0; + for _ in 0..50 { + timer = tick_sleep_timer(timer, true); + } + assert_eq!(alpha(timer as i32), 110); + for _ in 0..100 { + timer = tick_sleep_timer(timer, true); + } + assert_eq!(timer, 100); + assert_eq!(alpha(timer as i32), 220); + for _ in 0..5 { + timer = tick_sleep_timer(timer, false); + } + assert_eq!(alpha(timer as i32), 110); + for _ in 0..5 { + timer = tick_sleep_timer(timer, false); + } + assert_eq!(timer, 0); + assert!(hud_overlays::sleep_overlay(320, 240, timer as i32).is_empty()); + } + /// An integrated server thread shares the loaded resources with the client. #[test] fn shared_resources_can_cross_threads() { diff --git a/crates/horizon-client/src/game/fov.rs b/crates/horizon-client/src/game/fov.rs index 7825d6514..71b18a97c 100644 --- a/crates/horizon-client/src/game/fov.rs +++ b/crates/horizon-client/src/game/fov.rs @@ -55,7 +55,13 @@ impl Game<'_> { .fov_player() .map_or(1.0, |p| field_of_view_modifier(&p, first_person, effect)); let target = self.zoomed_fov_target(target); - let eye = self.player.as_ref().map(|p| p.dimensions.eye_height); + let eye = self.player.as_ref().map(|p| { + if self.sleeping.is_some() { + 0.2 + } else { + p.dimensions.eye_height + } + }); self.view.tick(eye, target); } /// The player's `deathTime` while dead or dying. diff --git a/crates/horizon-client/src/game/hand.rs b/crates/horizon-client/src/game/hand.rs index a932913af..19e66174b 100644 --- a/crates/horizon-client/src/game/hand.rs +++ b/crates/horizon-client/src/game/hand.rs @@ -67,7 +67,7 @@ impl Game<'_> { /// attack clicks since the last tick and the held attack button. pub(super) fn tick_local_hand(&mut self) -> Result<()> { let attack_clicks = std::mem::take(&mut self.attack_clicks); - if self.screen == Screen::Playing && self.title.is_none() { + if self.screen == Screen::Playing && self.title.is_none() && self.sleeping.is_none() { let mut clicks = std::mem::take(&mut self.clicks); // keyAttack.isDown(); playing implies the grabbed mouse here // (scripts under --control hold buttons without grabbing it). diff --git a/crates/horizon-client/src/game/perspective.rs b/crates/horizon-client/src/game/perspective.rs index bb463547f..61b35d48d 100644 --- a/crates/horizon-client/src/game/perspective.rs +++ b/crates/horizon-client/src/game/perspective.rs @@ -201,7 +201,7 @@ impl Game<'_> { ) }; let p = self.player.as_ref()?; - let sleeping = self.sleeping.map(|(head, _)| { + let sleeping = self.sleeping.map(|head| { let state = self.world.block(head[0], head[1], head[2]); let props = self .pack From 1f1d5a5aa413e9d4c0f0171b934cd2d96b7f64ee Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 10:53:46 +0200 Subject: [PATCH 29/46] Carry: leave out the files the content loader would refuse Vanilla skips a resource with an invalid path, a data file that does not parse, one at a time; Horizon's content loader refuses the whole mod set. carry now keeps them in outside/ with the reason (report `unreadable`): upper-case paths, JSON that does not parse, shared tags with "replace": true. A byte-order mark is dropped. ATM10's 42 carried mods: 19 such files in 7 mods (Mekanism Tools' ry_UA lang, CTOV's empty tag, Towns and Towers' replacing tags, broken template pools, recipes and a lang file), and the 42 load as carried. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-port-pack/Cargo.toml | 5 +- crates/horizon-port-pack/src/carry.rs | 69 ++++++++++++++++++++++++++- docs/modpacks.md | 8 +++- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/crates/horizon-port-pack/Cargo.toml b/crates/horizon-port-pack/Cargo.toml index 3b903ad03..775a853a8 100644 --- a/crates/horizon-port-pack/Cargo.toml +++ b/crates/horizon-port-pack/Cargo.toml @@ -7,6 +7,8 @@ rust-version = "1.86" description = "Port a Java modpack to Horizon: import, inventory, classification and data carry-over (docs/modpacks.md)" [dependencies] +# Content path rules only (no runtime): what the game's content loader accepts. +horizon-mods = { path = "../horizon-mods", default-features = false } serde = { version = "1", features = ["derive"] } serde_json = "1" sha1 = "0.10" @@ -14,8 +16,5 @@ toml = "1.1.6" ureq = { version = "2", default-features = false, features = ["tls"] } zip = { version = "2", default-features = false, features = ["deflate"] } -[dev-dependencies] -horizon-mods = { path = "../horizon-mods", default-features = false } - [lints] workspace = true diff --git a/crates/horizon-port-pack/src/carry.rs b/crates/horizon-port-pack/src/carry.rs index a637d6246..dfe4d3dbc 100644 --- a/crates/horizon-port-pack/src/carry.rs +++ b/crates/horizon-port-pack/src/carry.rs @@ -19,6 +19,10 @@ pub struct Report { /// Files outside what a content mod may hold (other namespaces, vanilla /// data other than tags), kept in `outside/` for review. pub outside: Vec, + /// Files of the mod's own content the game would refuse, kept in + /// `outside/` too, with why: a path vanilla does not read (upper case), + /// JSON that does not parse, a vanilla tag the mod replaces. + pub unreadable: BTreeMap, pub recipes_upgraded: usize, pub loot_tables_upgraded: usize, /// Worldgen and structure files (`data//worldgen/`, `structure/`). @@ -291,6 +295,32 @@ fn place(name: &str, id: &str) -> Option { Some(ns == id || shared_tags) } +/// Why the game would refuse a file of the mod's own content, if it would. +/// Vanilla skips such files one by one (an invalid resource path, a data +/// file that does not parse); Horizon's content loader refuses the whole +/// set, so they stay out of the carry. +fn unreadable(name: &str, bytes: &mut Vec) -> Option { + if let Err(e) = horizon_mods::content::check_path(name) { + return Some(e); + } + if !(name.ends_with(".json") || name.ends_with(".mcmeta")) { + return None; + } + // A byte-order mark: Horizon's JSON readers take the file without it. + if bytes.starts_with(b"\xEF\xBB\xBF") { + bytes.drain(..3); + } + let value: Value = match serde_json::from_slice(bytes) { + Ok(v) => v, + Err(e) => return Some(format!("does not parse as JSON: {e}")), + }; + let shared_tag = name.starts_with("data/minecraft/tags/") || name.starts_with("data/c/tags/"); + if shared_tag && value.get("replace").and_then(Value::as_bool) == Some(true) { + return Some("replaces a shared tag; a content mod may only add to it".into()); + } + None +} + /// Carries `jar` over into `out/carry/`. With the oracle's `facts`, blocks /// and items are the ones the mod registers, with the templates and numbers /// the facts give; `allowed` says which vanilla blocks the game has. @@ -334,6 +364,15 @@ pub fn carry( entry .read_to_end(&mut bytes) .map_err(|e| format!("{name}: {e}"))?; + let unreadable = if keep { + unreadable(&name, &mut bytes) + } else { + None + }; + let keep = keep && unreadable.is_none(); + if let Some(why) = unreadable { + report.unreadable.insert(name.clone(), why); + } let dest = if keep { report.copied += 1; inside.join(&name) @@ -716,6 +755,17 @@ mod tests { r#"{"values": ["gem:gem_block"]}"#, ), ("data/c/tags/item/gems.json", r#"{"values": ["gem:gem"]}"#), + // What the game would refuse: vanilla skips these files alone. + ("assets/gem/lang/ry_UA.json", r#"{"item.gem.gem": "Gem"}"#), + ("data/gem/tags/item/empty.json", ""), + ( + "data/minecraft/tags/worldgen/biome/has_structure/village_plains.json", + r#"{"replace": true, "values": []}"#, + ), + ( + "assets/gem/lang/de_de.json", + "\u{feff}{\"item.gem.gem\": \"Juwel\"}", + ), ]; for (name, text) in files { zip.start_file(*name, zip::write::SimpleFileOptions::default()) @@ -732,8 +782,23 @@ mod tests { assert_eq!(info.census.classes, 1); let out = dir.join("work/mods/gem"); let report = carry(&jar, &info, &out, None, &|_| true).unwrap(); - assert_eq!(report.copied, 12); - assert!(report.outside.is_empty()); + assert_eq!(report.copied, 13); + let unreadable: Vec<&str> = report.unreadable.keys().map(String::as_str).collect(); + assert_eq!( + unreadable, + [ + "assets/gem/lang/ry_UA.json", + "data/gem/tags/item/empty.json", + "data/minecraft/tags/worldgen/biome/has_structure/village_plains.json", + ] + ); + assert_eq!(report.outside.len(), 3); + assert!(!out.join("carry/data/gem/tags/item/empty.json").exists()); + // A byte-order mark is dropped, the file kept. + assert_eq!( + fs::read(out.join("carry/assets/gem/lang/de_de.json")).unwrap()[0], + b'{' + ); assert_eq!((report.recipes_upgraded, report.recipes_kept.len()), (1, 1)); assert_eq!(report.item_definitions_added, 2); assert_eq!(report.blocks["gem_door"], "minecraft:oak_door"); diff --git a/docs/modpacks.md b/docs/modpacks.md index fb9bca5f4..a70bf03b7 100644 --- a/docs/modpacks.md +++ b/docs/modpacks.md @@ -302,8 +302,12 @@ only): content 54, library 33, client-ui 26, performance 25, other 14, unknown 2 `carry` copies a jar's `assets//`, `data//`, `data/minecraft/tags/` and `data/c/tags/` into `mods//carry/`, a folder content mod (API 0.2) the game loads with `--dev-mod`, and -keeps what a content mod may not hold (other namespaces, vanilla data) in `outside/`. No class -file is copied. It upgrades from 1.21.1 to 26.3: vanilla-type recipes (ingredients), loot tables +keeps what a content mod may not hold (other namespaces, vanilla data) in `outside/`. Files of +the mod's own content that the game's content loader would refuse whole also go to `outside/`, +listed with the reason in the report's `unreadable`: paths vanilla does not read (upper case), +JSON that does not parse, and shared tags with `"replace": true`. Vanilla skips them one by one. +A byte-order mark is dropped. For ATM10's 42 mods that is 19 files in 7 mods, and the 42 load as +carried. No class file is copied. It upgrades from 1.21.1 to 26.3: vanilla-type recipes (ingredients), loot tables (`conditions` lists become one `condition`, `functions` become `modifier`, kinds move to `type`, tool matches on silk touch or shears become `minecraft:tool/can_silk_touch` and `minecraft:tool/can_shear`), and the `items/` definitions 1.21.4 introduced. From 814b70b8c2d89eff954ac442f79c08bad0a565b4 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 09:19:07 +0200 Subject: [PATCH 30/46] Keep terrain in system memory when video memory is full instead of crashing (#600) At render distance 32 the section arena holds about 1.5 GB of vertices (2.1 GB of GPU memory in all while flying). Vulkan drivers fail an allocation once video memory is full instead of paging like OpenGL drivers, and wgpu's default error handler turns that into a panic: a 4 GB laptop GPU that also drives the desktop crashed a few seconds into an RD32 world. Arena pages are now created inside an out-of-memory error scope. A page that doesn't fit in video memory is created mappable, which the allocator places in host-visible system memory, so the terrain still draws (more slowly) as OpenGL drivers do. A page that can't grow keeps its contents and a smaller new page is tried; with no memory left at all, the section is skipped rather than the game ending. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx.rs | 27 +++- crates/horizon-client/src/gfx/arena.rs | 190 +++++++++++++++++++++---- 2 files changed, 181 insertions(+), 36 deletions(-) diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 6c4b89240..c0e6a0895 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -615,8 +615,12 @@ impl Renderer { adapter .request_device(&wgpu::DeviceDescriptor { label: Some("Horizon device"), + // Mappable primary buffers: section pages that no + // longer fit in video memory go to system memory. required_features: timing::GpuTimer::features(&adapter) - | (adapter.features() & wgpu::Features::INDIRECT_FIRST_INSTANCE), + | (adapter.features() + & (wgpu::Features::INDIRECT_FIRST_INSTANCE + | wgpu::Features::MAPPABLE_PRIMARY_BUFFERS)), required_limits: limits.clone(), ..Default::default() }) @@ -1921,11 +1925,22 @@ impl Renderer { self.indices = Self::quad_indices(&self.device, self.index_quads); } let vertices = (mesh.solid.len() + mesh.translucent.len()) as u64; - let (page, start) = self.arena.alloc(&self.device, &self.queue, vertices); - let sorted_indices = (translucent > 0).then(|| { - self.sorted_indices - .alloc(&self.device, &self.queue, u64::from(translucent) * 6) - }); + // With video and system memory both full, the section is not drawn. + let Some((page, start)) = self.arena.alloc(&self.device, &self.queue, vertices) else { + return; + }; + let sorted_indices = if translucent > 0 { + let indices = + self.sorted_indices + .alloc(&self.device, &self.queue, u64::from(translucent) * 6); + if indices.is_none() { + self.arena.release(page, start, vertices); + return; + } + indices + } else { + None + }; let stride = std::mem::size_of::() as u64; for (offset, part) in [(0, &mesh.solid), (mesh.solid.len(), &mesh.translucent)] { if !part.is_empty() { diff --git a/crates/horizon-client/src/gfx/arena.rs b/crates/horizon-client/src/gfx/arena.rs index 19576204c..8becb6499 100644 --- a/crates/horizon-client/src/gfx/arena.rs +++ b/crates/horizon-client/src/gfx/arena.rs @@ -54,6 +54,11 @@ pub struct Arena { page_limit: u64, initial_capacity: u64, usage: wgpu::BufferUsages, + /// A page had to go to system memory (logged once). + spilled: bool, + /// Tests: GPU-local pages fail as if video memory were full. + #[cfg(test)] + video_memory_full: bool, } impl Arena { @@ -79,19 +84,44 @@ impl Arena { page_limit, initial_capacity: capacity, usage, + spilled: false, + #[cfg(test)] + video_memory_full: false, } } - fn create( - device: &wgpu::Device, - stride: u64, - capacity: u64, - usage: wgpu::BufferUsages, - ) -> wgpu::Buffer { - device.create_buffer(&wgpu::BufferDescriptor { - label: Some("Section buffer arena"), - size: capacity * stride, - usage: usage | wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::COPY_SRC, - mapped_at_creation: false, + /// A buffer of `capacity` vertices in video memory or, when that is full + /// and the device allows it, in system memory: Vulkan drivers fail an + /// allocation rather than page like OpenGL ones, and wgpu's default error + /// handler panics. `None` when neither has room. + fn create(&mut self, device: &wgpu::Device, capacity: u64) -> Option { + let usage = self.usage | wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::COPY_SRC; + #[cfg(test)] + let local = (!self.video_memory_full) + .then(|| try_create(device, capacity * self.stride, usage)) + .flatten(); + #[cfg(not(test))] + let local = try_create(device, capacity * self.stride, usage); + local.or_else(|| { + // Mappable buffers are placed in host-visible memory, which the + // allocator takes from system memory once video memory is full. + if !device + .features() + .contains(wgpu::Features::MAPPABLE_PRIMARY_BUFFERS) + { + return None; + } + let buffer = try_create( + device, + capacity * self.stride, + usage | wgpu::BufferUsages::MAP_WRITE, + )?; + if !std::mem::replace(&mut self.spilled, true) { + log::warn!( + "Horizon: video memory is full; more terrain is kept in system memory \ + (lower the render distance if frames slow down)" + ); + } + Some(buffer) }) } /// The rounded length a request of `vertices` occupies. @@ -110,19 +140,19 @@ impl Arena { } /// A range of `vertices`: (page, first vertex). Grows the newest page /// (copying its contents on the GPU) or starts a new one when nothing - /// free is large enough. + /// free is large enough; `None` when no memory is left for it. pub fn alloc( &mut self, device: &wgpu::Device, queue: &wgpu::Queue, vertices: u64, - ) -> (u32, u64) { + ) -> Option<(u32, u64)> { let len = Self::span(vertices).min(self.page_limit); for (i, page) in self.pages.iter_mut().enumerate() { if let Some(page) = page && let Some(start) = page.free.take(len) { - return (i as u32, start); + return Some((i as u32, start)); } } let last = self.pages.len().saturating_sub(1); @@ -131,11 +161,11 @@ impl Arena { { let current = page.capacity; let grown = (current * 2).max(current + len).min(self.page_limit); - if grown - current >= len || grown == self.page_limit { - self.grow(device, queue, last, grown); - if let Some(start) = self.pages[last].as_mut().unwrap().free.take(len) { - return (last as u32, start); - } + if (grown - current >= len || grown == self.page_limit) + && self.grow(device, queue, last, grown) + && let Some(start) = self.pages[last].as_mut().unwrap().free.take(len) + { + return Some((last as u32, start)); } } let capacity = if self.pages.is_empty() { @@ -145,10 +175,16 @@ impl Arena { } .max(len) .min(self.page_limit); + // A page just large enough when memory is short. + let (buffer, capacity) = match self.create(device, capacity) { + Some(buffer) => (buffer, capacity), + None if capacity > len => (self.create(device, len)?, len), + None => return None, + }; let mut free = FreeList::new(capacity); let start = free.take(len).expect("a new page fits one section"); let page = Page { - buffer: Self::create(device, self.stride, capacity, self.usage), + buffer, capacity, free, }; @@ -161,7 +197,7 @@ impl Arena { self.pages.len() - 1 }); self.pages[index] = Some(page); - (index as u32, start) + Some((index as u32, start)) } pub fn release(&mut self, page: u32, start: u64, vertices: u64) { let len = Self::span(vertices).min(self.page_limit); @@ -171,9 +207,19 @@ impl Arena { .free .give(start, len); } - fn grow(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, page: usize, capacity: u64) { + /// Moves a page into a larger buffer; false (the page unchanged) when + /// there is no memory for it. + fn grow( + &mut self, + device: &wgpu::Device, + queue: &wgpu::Queue, + page: usize, + capacity: u64, + ) -> bool { let capacity = capacity.next_multiple_of(GRAIN).min(self.page_limit); - let buffer = Self::create(device, self.stride, capacity, self.usage); + let Some(buffer) = self.create(device, capacity) else { + return false; + }; let old = self.pages[page].as_mut().expect("live arena page"); let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("Grow section arena"), @@ -185,6 +231,7 @@ impl Arena { old.buffer = buffer; old.capacity = capacity; old.free.give(previous, capacity - previous); + true } /// Reclaim after an upload batch, so replacing a section can reuse its range. pub fn trim(&mut self) { @@ -206,15 +253,39 @@ impl Arena { } } +/// `create_buffer` with an out-of-memory failure returned instead of raised +/// (raised errors are fatal). +fn try_create(device: &wgpu::Device, size: u64, usage: wgpu::BufferUsages) -> Option { + let scope = device.push_error_scope(wgpu::ErrorFilter::OutOfMemory); + let buffer = device.create_buffer(&wgpu::BufferDescriptor { + label: Some("Section buffer arena"), + size, + usage, + mapped_at_creation: false, + }); + // Native error scopes resolve at once. + pollster::block_on(scope.pop()).is_none().then_some(buffer) +} + #[cfg(test)] mod tests { use super::*; fn device() -> Option<(wgpu::Device, wgpu::Queue)> { + device_with(wgpu::Features::empty()) + } + + /// A device with those of `features` the adapter has. + fn device_with(features: wgpu::Features) -> Option<(wgpu::Device, wgpu::Queue)> { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle()); let adapter = pollster::block_on(instance.request_adapter(&Default::default())).ok()?; eprintln!("arena GPU regression: {}", adapter.get_info().name); - pollster::block_on(adapter.request_device(&Default::default())).ok() + let required_features = adapter.features() & features; + pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor { + required_features, + ..Default::default() + })) + .ok() } #[test] @@ -226,9 +297,9 @@ mod tests { let mut arena = Arena::new(&device, 4, GRAIN); arena.page_limit = 2 * GRAIN; assert_eq!(arena.bytes(), 0); - let (first, a) = arena.alloc(&device, &queue, GRAIN); - let (_, b) = arena.alloc(&device, &queue, GRAIN); - let (live, c) = arena.alloc(&device, &queue, 2 * GRAIN); + let (first, a) = arena.alloc(&device, &queue, GRAIN).unwrap(); + let (_, b) = arena.alloc(&device, &queue, GRAIN).unwrap(); + let (live, c) = arena.alloc(&device, &queue, 2 * GRAIN).unwrap(); let buffer = arena.buffer(live).clone(); let data = [1u8, 2, 3, 4]; queue.write_buffer(&buffer, c * 4, &data); @@ -240,7 +311,7 @@ mod tests { arena.trim(); assert_eq!(arena.bytes(), 2 * GRAIN * 4); assert_eq!(arena.buffer(live), &buffer); - let (reused, d) = arena.alloc(&device, &queue, GRAIN); + let (reused, d) = arena.alloc(&device, &queue, GRAIN).unwrap(); assert_eq!(reused, first); let (tx, rx) = std::sync::mpsc::channel(); @@ -269,11 +340,11 @@ mod tests { Arena::new(&device, 28, GRAIN), Arena::indices(&device, GRAIN), ] { - arena.alloc(&device, &queue, GRAIN); + arena.alloc(&device, &queue, GRAIN).unwrap(); assert_eq!(arena.bytes(), arena.stride * GRAIN); arena.clear(); assert_eq!(arena.bytes(), 0); - assert_eq!(arena.alloc(&device, &queue, GRAIN), (0, 0)); + assert_eq!(arena.alloc(&device, &queue, GRAIN), Some((0, 0))); assert_eq!(arena.bytes(), arena.stride * GRAIN); } } @@ -302,4 +373,63 @@ mod tests { free.give(a, GRAIN); assert_eq!(free.take(GRAIN), Some(a)); } + + fn read(device: &wgpu::Device, queue: &wgpu::Queue, buffer: &wgpu::Buffer, offset: u64) -> u32 { + let (tx, rx) = std::sync::mpsc::channel(); + wgpu::util::DownloadBuffer::read_buffer( + device, + queue, + &buffer.slice(offset..offset + 4), + move |result| tx.send(result.unwrap().to_vec()).unwrap(), + ); + device.poll(wgpu::PollType::wait_indefinitely()).unwrap(); + u32::from_le_bytes(rx.recv().unwrap()[..4].try_into().unwrap()) + } + + #[test] + fn full_video_memory_spills_to_system_memory() { + let Some((device, queue)) = device_with(wgpu::Features::MAPPABLE_PRIMARY_BUFFERS) else { + return; + }; + if !device + .features() + .contains(wgpu::Features::MAPPABLE_PRIMARY_BUFFERS) + { + return; + } + let mut arena = Arena::indices(&device, GRAIN); + let (page, start) = arena.alloc(&device, &queue, GRAIN).unwrap(); + queue.write_buffer(arena.buffer(page), start * 4, &7u32.to_le_bytes()); + arena.video_memory_full = true; + // The full page can't grow in video memory: it moves to system + // memory with its contents, and new ranges come from there. + let (grown, next) = arena.alloc(&device, &queue, GRAIN).unwrap(); + assert!(arena.spilled); + assert_eq!(grown, page); + assert!( + arena + .buffer(page) + .usage() + .contains(wgpu::BufferUsages::MAP_WRITE) + ); + queue.write_buffer(arena.buffer(grown), next * 4, &9u32.to_le_bytes()); + assert_eq!(read(&device, &queue, arena.buffer(page), start * 4), 7); + assert_eq!(read(&device, &queue, arena.buffer(grown), next * 4), 9); + } + + #[test] + fn no_memory_left_is_not_an_error() { + let Some((device, queue)) = device() else { + return; + }; + let mut arena = Arena::indices(&device, GRAIN); + arena.alloc(&device, &queue, GRAIN).unwrap(); + arena.video_memory_full = true; + // Without mappable primary buffers nothing can spill: the request + // fails, and the arena keeps what it has. + assert_eq!(arena.alloc(&device, &queue, GRAIN), None); + assert_eq!(arena.bytes(), GRAIN * 4); + arena.release(0, 0, GRAIN); + assert_eq!(arena.alloc(&device, &queue, GRAIN), Some((0, 0))); + } } From 22bb18d67a62600ddbea898b935387e83a393391 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:24:31 +0200 Subject: [PATCH 31/46] Carry: the oracle's facts only for the mods it loaded With oracle/facts.json, a mod the oracle did not load (a library it needs is missing) lost every block: none of its ids were in the facts. It now keeps the guesses from its blockstates, as without an oracle. ATM10: Regions Unexplored (TerraBlender is CurseForge-only) gets its 805 blocks back. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-port-pack/src/pipeline.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/horizon-port-pack/src/pipeline.rs b/crates/horizon-port-pack/src/pipeline.rs index ddb39bf66..80a88ee18 100644 --- a/crates/horizon-port-pack/src/pipeline.rs +++ b/crates/horizon-port-pack/src/pipeline.rs @@ -139,11 +139,20 @@ pub fn carry( if !chosen { continue; } + // The oracle's facts for the mods it ran; a mod it did not load (a + // library missing) keeps the guesses from its blockstates. + let prefix = format!("{}:", info.mod_id); + let seen = |f: &&oracle::Facts| { + f.blocks + .keys() + .chain(f.items.keys()) + .any(|k| k.starts_with(&prefix)) + }; match carry::carry( jar, info, &work.join("mods").join(&r.key), - facts.as_ref(), + facts.as_ref().filter(seen), &allowed, ) { Ok(report) => { From b859b22111536811139069326de7ff8be1d2d1a3 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:22:28 +0200 Subject: [PATCH 32/46] Keep usercache.json and find console players through it, as vanilla Port CachedUserNameToIdResolver to the dedicated server, in place of the in-memory name cache: usercache.json in the universe folder is loaded at startup (bad entries skipped, a bad date warned about), players are added when they join and kept for a month, and the file keeps the 1000 most recently used, newest first, as Gson writes it. The console's op, deop, ban, pardon and whitelist find players by name through it, in any case. A name it doesn't hold is asked of the profile service (profiles::find_by_name) on offline servers too, as vanilla does; one the service doesn't know is the offline player of the lower-case name on an offline server, and "That player does not exist" on an online one. tools/test_user_cache_parity.py runs vanilla's server and Horizon's with a mock profile service and compares the replies, the names looked up and the files; the dedicated-server harness now compares usercache.json too. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/dedicated.rs | 80 ++--- crates/horizon-client/src/game/lan.rs | 2 +- crates/horizon-server-files/src/json.rs | 37 ++ crates/horizon-server-files/src/lib.rs | 5 +- crates/horizon-server-files/src/user_cache.rs | 318 ++++++++++++++++++ crates/horizon-server-files/src/user_lists.rs | 4 +- docs/server.md | 6 + tools/test_dedicated_server_parity.py | 9 +- tools/test_user_cache_parity.py | 246 ++++++++++++++ 9 files changed, 657 insertions(+), 50 deletions(-) create mode 100644 crates/horizon-server-files/src/user_cache.rs create mode 100644 tools/test_user_cache_parity.py diff --git a/crates/horizon-client/src/game/dedicated.rs b/crates/horizon-client/src/game/dedicated.rs index d0efd898b..b27fc47a5 100644 --- a/crates/horizon-client/src/game/dedicated.rs +++ b/crates/horizon-client/src/game/dedicated.rs @@ -13,7 +13,9 @@ use horizon_client::{ server::{ eula, java_properties::now_millis, + profiles, properties::{GAME_MODES, ServerProperties, SystemEntropy}, + user_cache::UserCache, user_lists::{ BanEntry, BanList, IpBanList, NameAndId, OpEntry, OpList, WhiteEntry, WhiteList, format_date, @@ -57,20 +59,17 @@ struct Setup { started: Instant, } static SETUP: OnceLock>> = OnceLock::new(); +/// usercache.json (Services.nameToIdCache): used by the server thread only. +static USER_CACHE: Mutex> = Mutex::new(None); -/// CachedUserNameToIdResolver, kept in memory only (vanilla also saves it to -/// usercache.json): players who joined, and accounts found by name, by name -/// in lower case. -static USER_CACHE: OnceLock>> = OnceLock::new(); - -/// PlayerList.placeNewPlayer adds the player to the name cache. -pub(super) fn remember(name: &str, uuid: u128) { - let user = NameAndId { - id: uuid, - name: name.to_owned(), - }; - let cache = USER_CACHE.get_or_init(Default::default); - cache.lock().unwrap().insert(name.to_lowercase(), user); +/// PlayerList.placeNewPlayer: a player who joined is cached (and the file saved). +pub(super) fn player_joined(id: u128, name: &str) { + if let Some(cache) = USER_CACHE.lock().unwrap().as_mut() { + cache.add(NameAndId { + id, + name: name.to_owned(), + }); + } } /// Log4j's console pattern: `[HH:mm:ss] [thread/LEVEL]: message`. @@ -331,8 +330,6 @@ struct ServerState { /// When the last passes of the loop ended, for the tick rate horizon-server shows. ticks: std::collections::VecDeque, paused: bool, - /// online-mode: names given to commands are looked up as accounts. - online: bool, } impl Game<'_> { @@ -365,6 +362,14 @@ impl Game<'_> { line.clear(); } })?; + // Main: Services.create loads the universe's usercache.json. + let (mut cache, warnings) = UserCache::load(universe.join("usercache.json")); + for warning in warnings { + log_from("main", "WARN", &warning); + } + // DedicatedServer.initServer: names nobody has resolve offline only without authentication. + cache.resolve_offline_users = !props.online_mode; + *USER_CACHE.lock().unwrap() = Some(cache); log("INFO", "Starting minecraft server version 26.3"); log("INFO", "Loading properties"); let game_mode = props.game_mode; @@ -530,7 +535,6 @@ impl Game<'_> { empty_ticks: 0, ticks: Default::default(), paused: false, - online: props.online_mode, }; let pause_after = props.pause_when_empty_seconds * 20; let idle_timeout = props.player_idle_timeout; @@ -672,33 +676,23 @@ impl Game<'_> { }) } - /// GameProfileArgument: a player on the server, else one seen since the - /// start, else the name resolved as the server's mode says (an online - /// server asks the services, an offline one makes the offline profile). - /// None, told to the console: no such account. - fn resolve(&self, name: &str, online: bool) -> Option { - let user = self.online_player(name).or_else(|| { - let key = name.to_lowercase(); - let cache = USER_CACHE.get_or_init(Default::default); - if let Some(user) = cache.lock().unwrap().get(&key) { - return Some(user.clone()); - } - let user = horizon_server_files::profiles::resolve(name, online); - let Some(user) = user else { - if online { - log("WARN", &format!("Couldn't find profile with name: {key}")); + /// GameProfileArgument for a name: the user cache, else the profile + /// service, else (offline) the offline player. None, told to the console: + /// no such player. + fn resolve(&self, name: &str) -> Option { + let found = USER_CACHE.lock().unwrap().as_mut().and_then(|cache| { + cache.get_by_name(name, |lower| { + let found = profiles::find_by_name(&profiles::discovery_url(), lower); + if found.is_none() { + log("WARN", &format!("Couldn't find profile with name: {lower}")); } - return None; - }; - if online { - cache.lock().unwrap().insert(key, user.clone()); - } - Some(user) + found + }) }); - if user.is_none() { + if found.is_none() { self.console_reply(Text::translate("argument.player.unknown", &[])); } - user + found } /// MinecraftServer.sendSystemMessage: what the console is told. @@ -781,7 +775,7 @@ impl Game<'_> { )); } "op" | "deop" if !rest.is_empty() => { - let Some(user) = self.resolve(rest[0], state.online) else { + let Some(user) = self.resolve(rest[0]) else { return; }; let level = 4; @@ -813,7 +807,7 @@ impl Game<'_> { } "whitelist" => self.console_whitelist(state, &rest), "ban" if !rest.is_empty() => { - let Some(user) = self.resolve(rest[0], state.online) else { + let Some(user) = self.resolve(rest[0]) else { return; }; let reason = (rest.len() > 1).then(|| rest[1..].join(" ")); @@ -905,7 +899,7 @@ impl Game<'_> { } } "pardon" if !rest.is_empty() => { - let Some(user) = self.resolve(rest[0], state.online) else { + let Some(user) = self.resolve(rest[0]) else { return; }; let removed = state.lists.lock().unwrap().bans.remove(&user); @@ -1056,7 +1050,7 @@ impl Game<'_> { self.console_reply(Text::translate("commands.whitelist.reloaded", &[])); } ["add", name] | ["remove", name] => { - let Some(user) = self.resolve(name, state.online) else { + let Some(user) = self.resolve(name) else { return; }; let mut l = state.lists.lock().unwrap(); diff --git a/crates/horizon-client/src/game/lan.rs b/crates/horizon-client/src/game/lan.rs index a8b5758ad..c2f369b62 100644 --- a/crates/horizon-client/src/game/lan.rs +++ b/crates/horizon-client/src/game/lan.rs @@ -729,7 +729,7 @@ impl Game<'_> { && let Some(g) = host.hub.guest(conn) { // PlayerList.placeNewPlayer, then the broadcast join message. - super::dedicated::remember(&g.name, g.uuid); + super::dedicated::player_joined(g.uuid, &g.name); let [x, y, z] = g.position; super::dedicated::log( "INFO", diff --git a/crates/horizon-server-files/src/json.rs b/crates/horizon-server-files/src/json.rs index 8e1d865b2..47fe6d5d3 100644 --- a/crates/horizon-server-files/src/json.rs +++ b/crates/horizon-server-files/src/json.rs @@ -78,6 +78,43 @@ impl Json { } } + /// `new GsonBuilder().create().toJson(element)`: compact, HTML-safe + /// strings, null members skipped. + pub fn gson(&self) -> String { + let mut out = String::new(); + self.write_gson(&mut out); + out + } + fn write_gson(&self, out: &mut String) { + match self { + Json::String(s) => quote(out, s, true), + Json::Array(items) => { + out.push('['); + for (i, v) in items.iter().enumerate() { + if i > 0 { + out.push(','); + } + v.write_gson(out); + } + out.push(']'); + } + Json::Object(m) => { + out.push('{'); + let members = m.iter().filter(|(_, v)| *v != Json::Null); + for (i, (k, v)) in members.enumerate() { + if i > 0 { + out.push(','); + } + quote(out, k, true); + out.push(':'); + v.write_gson(out); + } + out.push('}'); + } + other => other.write_compact(out), + } + } + /// `new GsonBuilder().setPrettyPrinting().create().toJson(element, writer)`: /// two-space indents, HTML-safe strings, null members skipped. pub fn pretty(&self) -> String { diff --git a/crates/horizon-server-files/src/lib.rs b/crates/horizon-server-files/src/lib.rs index babb02771..08c059905 100644 --- a/crates/horizon-server-files/src/lib.rs +++ b/crates/horizon-server-files/src/lib.rs @@ -1,7 +1,7 @@ //! The dedicated server's files and settings, ported from //! net.minecraft.server.dedicated and net.minecraft.server.players: -//! server.properties, eula.txt, the four user lists and looking players up -//! by name in online mode. The game's dedicated server +//! server.properties, eula.txt, the four user lists, usercache.json and +//! looking players up by name. The game's dedicated server //! (`horizon-client --dedicated`) reads them, and `horizon-server` manages //! them; this crate needs neither a window nor the game. pub mod eula; @@ -9,4 +9,5 @@ pub mod java_properties; pub mod json; pub mod profiles; pub mod properties; +pub mod user_cache; pub mod user_lists; diff --git a/crates/horizon-server-files/src/user_cache.rs b/crates/horizon-server-files/src/user_cache.rs new file mode 100644 index 000000000..c8ccd6cf0 --- /dev/null +++ b/crates/horizon-server-files/src/user_cache.rs @@ -0,0 +1,318 @@ +//! usercache.json (CachedUserNameToIdResolver): the players the server has +//! seen join or has looked up by name, so commands find a player by name +//! without asking the profile service again. Each entry expires a month after +//! it was added; the file keeps the 1000 most recently used. +use crate::{ + java_properties::{civil_from_days, days_from_civil, now_millis}, + json::{self, Json}, + profiles::valid_player_name, + user_lists::{NameAndId, format_date, parse_date}, +}; +use std::{collections::HashMap, path::PathBuf}; + +const MRU_LIMIT: usize = 1000; + +#[derive(Clone, Debug)] +struct Info { + user: NameAndId, + expires: i64, + last_access: u64, +} + +/// `Calendar.add(MONTH, 1)` on a UTC time: the same day and time a month +/// later, the day clamped to the end of a shorter month. +pub fn one_month_later(millis: i64) -> i64 { + let days = millis.div_euclid(86_400_000); + let time = millis.rem_euclid(86_400_000); + let (y, m, d) = civil_from_days(days); + let (y, m) = if m == 12 { (y + 1, 1) } else { (y, m + 1) }; + let last = days_from_civil( + if m == 12 { y + 1 } else { y }, + if m == 12 { 1 } else { m + 1 }, + 1, + ) - days_from_civil(y, m, 1); + let d = d.min(last as u32); + days_from_civil(y, m, d) * 86_400_000 + time +} + +pub struct UserCache { + file: PathBuf, + /// Every entry ever added; the maps point into it, as vanilla's two maps + /// share their GameProfileInfo objects. + infos: Vec, + by_name: HashMap, + by_uuid: HashMap, + operations: u64, + /// Off on an online-mode server: a name the profile service doesn't know + /// is then no player at all, rather than an offline one. + pub resolve_offline_users: bool, +} + +impl UserCache { + /// The cache in `file`, loaded; also returns the warnings vanilla logs. + pub fn load(file: impl Into) -> (Self, Vec) { + let mut cache = Self { + file: file.into(), + infos: Vec::new(), + by_name: HashMap::new(), + by_uuid: HashMap::new(), + operations: 0, + resolve_offline_users: true, + }; + let mut warnings = Vec::new(); + let entries = match std::fs::read_to_string(&cache.file) { + Ok(text) => cache.parse(&text, &mut warnings), + Err(_) => Vec::new(), + }; + for info in entries.into_iter().rev() { + cache.safe_add(info); + } + (cache, warnings) + } + + fn parse(&self, text: &str, warnings: &mut Vec) -> Vec { + let items = match json::parse(text, false) { + Ok(Json::Array(items)) => items, + // An empty file is Gson's null. + Ok(Json::Null) => return Vec::new(), + _ if text.trim().is_empty() => return Vec::new(), + _ => { + warnings.push(format!( + "Failed to load profile cache {}", + self.file.display() + )); + return Vec::new(); + } + }; + let mut out = Vec::new(); + for item in &items { + if !matches!(item, Json::Object(_)) { + continue; + } + let Some(user) = NameAndId::from_json(item) else { + continue; + }; + let Some(date) = item.get("expiresOn").and_then(Json::as_string) else { + continue; + }; + match parse_date(&date) { + Some(expires) => out.push(Info { + user, + expires, + last_access: 0, + }), + None => warnings.push(format!("Failed to parse date {date}")), + } + } + out + } + + fn safe_add(&mut self, mut info: Info) -> usize { + self.operations += 1; + info.last_access = self.operations; + let index = self.infos.len(); + self.by_name.insert(info.user.name.to_lowercase(), index); + self.by_uuid.insert(info.user.id, index); + self.infos.push(info); + index + } + + /// `add`: a player who joined, remembered for a month; saves the file. + pub fn add(&mut self, user: NameAndId) { + self.add_internal(user, now_millis()); + } + + fn add_internal(&mut self, user: NameAndId, now: i64) -> NameAndId { + let index = self.safe_add(Info { + user, + expires: one_month_later(now), + last_access: 0, + }); + self.save(); + self.infos[index].user.clone() + } + + /// `get(String)`: the player with this name (any case). An expired entry is + /// dropped; a name not cached is asked of `lookup` (the profile service, + /// given the lower-case name) and, failing that, made an offline player + /// when offline users resolve. What is found is cached. + pub fn get_by_name( + &mut self, + name: &str, + lookup: impl FnOnce(&str) -> Option, + ) -> Option { + self.get_by_name_at(name, now_millis(), lookup) + } + + fn get_by_name_at( + &mut self, + name: &str, + now: i64, + lookup: impl FnOnce(&str) -> Option, + ) -> Option { + let name = name.to_lowercase(); + let mut found = self.by_name.get(&name).copied(); + let mut needs_save = false; + if let Some(index) = found + && now >= self.infos[index].expires + { + let user = self.infos[index].user.clone(); + self.by_uuid.remove(&user.id); + self.by_name.remove(&user.name.to_lowercase()); + needs_save = true; + found = None; + } + let result = if let Some(index) = found { + self.operations += 1; + self.infos[index].last_access = self.operations; + Some(self.infos[index].user.clone()) + } else { + let profile = if valid_player_name(&name) { + lookup(&name) + } else { + None + }; + let profile = profile.or_else(|| { + self.resolve_offline_users + .then(|| NameAndId::offline(&name)) + }); + match profile { + Some(profile) => { + needs_save = false; + Some(self.add_internal(profile, now)) + } + None => None, + } + }; + if needs_save { + self.save(); + } + result + } + + /// `get(UUID)`: a cached player by id (expired or not). + pub fn get_by_id(&mut self, id: u128) -> Option { + let index = *self.by_uuid.get(&id)?; + self.operations += 1; + self.infos[index].last_access = self.operations; + Some(self.infos[index].user.clone()) + } + + /// The file's text: the 1000 most recently used entries, most recent + /// first, as Gson writes them (compact, HTML-safe). + pub fn to_json(&self) -> String { + let mut entries: Vec<&Info> = self.by_uuid.values().map(|&i| &self.infos[i]).collect(); + entries.sort_by_key(|info| std::cmp::Reverse(info.last_access)); + let items = entries + .into_iter() + .take(MRU_LIMIT) + .map(|info| { + let mut o = Json::Object(Vec::new()); + info.user.append_to(&mut o); + o.add("expiresOn", Json::String(format_date(info.expires))); + o + }) + .collect(); + Json::Array(items).gson() + } + + /// `save`: errors are ignored, as vanilla does. + pub fn save(&self) { + let _ = std::fs::write(&self.file, self.to_json()); + } +} + +#[cfg(test)] +mod tests { + use super::*; + + const DAY: i64 = 86_400_000; + + fn cache(text: &str) -> (UserCache, Vec) { + let dir = std::env::temp_dir().join(format!( + "horizon-usercache-{}-{}", + std::process::id(), + text.len() + )); + std::fs::create_dir_all(&dir).unwrap(); + let file = dir.join("usercache.json"); + std::fs::write(&file, text).unwrap(); + UserCache::load(file) + } + + #[test] + fn months() { + let jan31 = days_from_civil(2026, 1, 31) * DAY + 3_723_000; + assert_eq!( + format_date(one_month_later(jan31)), + "2026-02-28 01:02:03 +0000" + ); + let dec15 = days_from_civil(2026, 12, 15) * DAY; + assert_eq!( + format_date(one_month_later(dec15)), + "2027-01-15 00:00:00 +0000" + ); + let jan31_leap = days_from_civil(2028, 1, 31) * DAY; + assert_eq!( + format_date(one_month_later(jan31_leap)), + "2028-02-29 00:00:00 +0000" + ); + } + + #[test] + fn keeps_order_and_skips_bad_entries() { + let (c, warnings) = cache( + r#"[{"uuid":"069a79f4-44e9-4726-a5be-fca90e38aaf5","name":"Notch","expiresOn":"2099-01-01 00:00:00 +0000"}, + 1, {"name":"NoId"}, {"uuid":"853c80ef-3c37-49fd-aa49-938b674adae6","name":"NoDate"}, + {"uuid":"853c80ef-3c37-49fd-aa49-938b674adae6","name":"BadDate","expiresOn":"soon"}, + {"uuid":"61699b2e-d327-4a01-9f1e-0ea8c3f06bc6","name":"Alex","expiresOn":"2099-01-01 00:00:00 +0000"}]"#, + ); + assert_eq!(warnings, vec!["Failed to parse date soon".to_owned()]); + assert_eq!( + c.to_json(), + r#"[{"uuid":"069a79f4-44e9-4726-a5be-fca90e38aaf5","name":"Notch","expiresOn":"2099-01-01 00:00:00 +0000"},{"uuid":"61699b2e-d327-4a01-9f1e-0ea8c3f06bc6","name":"Alex","expiresOn":"2099-01-01 00:00:00 +0000"}]"# + ); + } + + #[test] + fn names_resolve_through_the_cache() { + let (mut c, _) = cache( + r#"[{"uuid":"069a79f4-44e9-4726-a5be-fca90e38aaf5","name":"Notch","expiresOn":"2099-01-01 00:00:00 +0000"}, + {"uuid":"61699b2e-d327-4a01-9f1e-0ea8c3f06bc6","name":"Old","expiresOn":"2000-01-01 00:00:00 +0000"}]"#, + ); + let now = days_from_civil(2026, 10, 17) * DAY; + let never = |_: &str| -> Option { panic!("looked up") }; + // A hit in any case, and it becomes the most recent. + let notch = c.get_by_name_at("NOTCH", now, never).unwrap(); + assert_eq!(notch.name, "Notch"); + // Expired: dropped and looked up again, by its lower-case name. + let mut asked = Vec::new(); + let old = c + .get_by_name_at("Old", now, |n| { + asked.push(n.to_owned()); + None + }) + .unwrap(); + assert_eq!(asked, ["old"]); + assert_eq!(old, NameAndId::offline("old")); + // Not a valid name: never looked up. + let odd = c.get_by_name_at("a b", now, never).unwrap(); + assert_eq!(odd, NameAndId::offline("a b")); + c.resolve_offline_users = false; + assert_eq!(c.get_by_name_at("Nobody", now, |_| None), None); + let found = NameAndId { + id: 7, + name: "Steve".into(), + }; + let steve = c.get_by_name_at("steve", now, |_| Some(found.clone())); + assert_eq!(steve, Some(found)); + let json = c.to_json(); + let names: Vec<&str> = json + .split("\"name\":\"") + .skip(1) + .map(|s| s.split('"').next().unwrap()) + .collect(); + assert_eq!(names, ["Steve", "a b", "old", "Notch"]); + assert!(json.contains(r#""name":"Steve","expiresOn":"2026-11-17 00:00:00 +0000"}"#)); + } +} diff --git a/crates/horizon-server-files/src/user_lists.rs b/crates/horizon-server-files/src/user_lists.rs index 3d35aa62f..77de64e31 100644 --- a/crates/horizon-server-files/src/user_lists.rs +++ b/crates/horizon-server-files/src/user_lists.rs @@ -39,7 +39,7 @@ impl NameAndId { name: name.to_owned(), } } - fn from_json(o: &Json) -> Option { + pub(crate) fn from_json(o: &Json) -> Option { let uuid = o.get("uuid")?.as_string()?; let name = o.get("name")?.as_string()?; Some(Self { @@ -47,7 +47,7 @@ impl NameAndId { name, }) } - fn append_to(&self, o: &mut Json) { + pub(crate) fn append_to(&self, o: &mut Json) { o.add("uuid", Json::String(uuid_string(self.id))); o.add("name", Json::String(self.name.clone())); } diff --git a/docs/server.md b/docs/server.md index 0eb0aaf35..f3640c8b9 100644 --- a/docs/server.md +++ b/docs/server.md @@ -33,6 +33,12 @@ The dedicated server is the game itself, run headless: `whitelist on|off|list|reload|add|remove`, `ban`, `ban-ip`, `pardon`, `pardon-ip`, `banlist`, `kick` and `say` behave as in `DedicatedServer`. Every other command goes to the game's own dispatcher as the server (permission level 4). The log follows vanilla's Log4j pattern, in `logs/latest.log` and on stdout. +- **Player names.** `usercache.json` in the universe folder works as vanilla's `CachedUserNameToIdResolver`. + Players are added when they join and kept for a month, and the file keeps the 1000 most recently used, + newest first. The console finds a player by name in it, in any case. A name it doesn't hold is asked of the + profile service (`getByName`). If the service doesn't know the name, an offline server uses the offline + player of the lower-case name; an online server answers "That player does not exist". + `tools/test_user_cache_parity.py` checks this against vanilla, with a mock profile service. ### Measured (2026-10-16, Mac mini M4 Pro, main at bd8dff20, release build) diff --git a/tools/test_dedicated_server_parity.py b/tools/test_dedicated_server_parity.py index c30abe4b0..0f40893c8 100644 --- a/tools/test_dedicated_server_parity.py +++ b/tools/test_dedicated_server_parity.py @@ -35,7 +35,8 @@ exactly: shift-click changes and its lit and cooking totals; - the console lines about the player, the chat, `list`, `say` and `stop`; - the files the servers leave: server.properties (but the date line), - eula.txt, ops.json, whitelist.json, banned-players.json, banned-ips.json. + eula.txt, ops.json, whitelist.json, banned-players.json, banned-ips.json, + usercache.json (but the date the player's entry expires). Online mode needs Mojang's session servers and is not tested. """ @@ -238,7 +239,8 @@ def console_lines(lines): def server_files(directory): out = [] - for name in ['server.properties', 'eula.txt', 'ops.json', 'whitelist.json', 'banned-players.json', 'banned-ips.json']: + for name in ['server.properties', 'eula.txt', 'ops.json', 'whitelist.json', 'banned-players.json', 'banned-ips.json', + 'usercache.json']: path = directory / name if not path.exists(): out.append(f'{name}: missing') @@ -249,6 +251,9 @@ def server_files(directory): text = re.sub(r'^(#[^\n]*\n)#[^\n]*\n', r'\1#\n', text) # Random per server, and each side has its own port. text = re.sub(r'\n(management-server-secret|server-port)=[^\n]*', r'\n\1=', text) + if name == 'usercache.json': + # A month from when the player joined. + text = re.sub(r'"expiresOn":"[^"]*"', '"expiresOn":""', text) out.append(f'{name}: {text!r}') return out diff --git a/tools/test_user_cache_parity.py b/tools/test_user_cache_parity.py new file mode 100644 index 000000000..621514cc8 --- /dev/null +++ b/tools/test_user_cache_parity.py @@ -0,0 +1,246 @@ +#!/usr/bin/env python3 +"""usercache.json and the console's player names, against vanilla's dedicated server. + +The console finds a player by name through the user cache (CachedUserNameToIdResolver): a name it holds +in any case, else the profile service's `getByName` (asked with the lower-case name), else, in offline +mode, the offline player of that lower-case name; what it finds is cached for a month and the file +rewritten, most recently used first. A small mock of the Minecraft services (dev only: the discovery +document and `getByName`, which knows one account) stands in for Mojang's; vanilla finds it through +`-Dminecraft.api.discovery.host`, Horizon through `HORIZON_API_DISCOVERY`. + +Each server starts in offline mode in a folder holding a usercache.json with a live entry, an expired +one, entries without a date, with a bad date, without an id, and not an object. The console then +whitelists, ops, deops and bans players: the cached one in another case, the expired one, the account the +service knows, names it doesn't know, a name too long to ask about. The server restarts in online mode, +where a name nobody knows is no player at all, and stops. Compared exactly: the console's replies, the +names asked of the service in order, and usercache.json, whitelist.json, ops.json and +banned-players.json after each run (the dates the servers wrote are placeholders). + +Players who join are added by the dedicated-server harness, which compares usercache.json too. +""" +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +import json +import os +from pathlib import Path +import platform +import re +import shutil +import subprocess +import sys +import threading +import time +import urllib.parse + +try: + from . import lab, test_rust_parity as base + from .test_dedicated_server_parity import Server, free_port +except ImportError: + import lab + import test_rust_parity as base + from test_dedicated_server_parity import Server, free_port + +NAME = 'user-cache-parity' +PROPERTIES = { + 'online-mode': 'false', + 'level-seed': '12345', + 'generate-structures': 'false', + 'view-distance': '2', + 'simulation-distance': '2', + 'spawn-protection': '0', + 'pause-when-empty-seconds': '-1', +} +NOTCH = '069a79f444e94726a5befca90e38aaf5' +SEEDED = [ + {'uuid': '853c80ef-3c37-49fd-aa49-938b674adae6', 'name': 'Seeded', 'expiresOn': '2099-01-01 00:00:00 +0000'}, + {'uuid': '61699b2e-d327-4a01-9f1e-0ea8c3f06bc6', 'name': 'Expired', 'expiresOn': '2001-02-03 04:05:06 +0000'}, + {'uuid': '00000000-0000-0000-0000-000000000001', 'name': 'NoDate'}, + {'uuid': '00000000-0000-0000-0000-000000000002', 'name': 'BadDate', 'expiresOn': 'tomorrow'}, + {'name': 'NoId', 'expiresOn': '2099-01-01 00:00:00 +0000'}, + 'not an object', + {'uuid': '00000000-0000-0000-0000-000000000003', 'name': 'Later', 'expiresOn': '2098-05-06 07:08:09 +0100'}, +] +# (console command, the reply it waits for) +OFFLINE = [ + ('whitelist add SEEDED', r'System chat: (Added|Player is already)'), + ('whitelist add Notch', r'System chat: (Added|Player is already)'), + ('op expired', r'System chat: (Made|Nothing changed)'), + ('ban Nobody_Here', r'System chat: (Banned|Nothing changed)'), + ('whitelist add NameMuchTooLongForMinecraft', r'System chat: (Added|Player is already)'), + ('deop NOTCH', r'System chat: (Made|Nothing changed)'), + ('whitelist add later', r'System chat: (Added|Player is already)'), + ('whitelist remove notch', r'System chat: (Removed|Player is not)'), +] +ONLINE = [ + ('whitelist add Somebody_Else', r'System chat: (Added|That player does not exist)'), + ('whitelist add nobody_here', r'System chat: (Added|Player is already)'), +] +FILES = ['usercache.json', 'whitelist.json', 'ops.json', 'banned-players.json'] + + +class Services: + """The mock discovery document and profile lookup by name.""" + + def __init__(self): + self.asked = [] + self.lock = threading.Lock() + services = self + + class Handler(BaseHTTPRequestHandler): + def log_message(self, *args): + pass + + def reply(self, status, body): + data = json.dumps(body).encode() + self.send_response(status) + self.send_header('Content-Type', 'application/json') + self.send_header('Content-Length', str(len(data))) + self.end_headers() + self.wfile.write(data) + + def do_GET(self): + url = urllib.parse.urlparse(self.path) + if url.path == '/minecraft/client': + return self.reply(200, services.discovery()) + if url.path.startswith('/profiles/name/'): + name = urllib.parse.unquote(url.path.removeprefix('/profiles/name/')) + with services.lock: + services.asked.append(name) + if name.lower() == 'notch': + return self.reply(200, {'id': NOTCH, 'name': 'Notch'}) + return self.reply(404, {'path': url.path, 'errorMessage': f"Couldn't find any profile with name {name}"}) + self.reply(404, {'error': 'NotFound', 'path': url.path}) + + self.server = ThreadingHTTPServer(('127.0.0.1', 0), Handler) + self.url = f'http://127.0.0.1:{self.server.server_address[1]}' + threading.Thread(target=self.server.serve_forever, daemon=True).start() + + def discovery(self): + def endpoints(**names): + return {'endpoints': {k: {'uri': self.url + v} for k, v in names.items()}} + return {'environment': 'mock', 'product': 'minecraft', 'discovery': { + 'authentication': endpoints(getPublicKeys='/publickeys'), + 'session': endpoints(join='/session/minecraft/join', verify='/session/minecraft/hasJoined', + getProfileById='/session/minecraft/profile/{profileId}'), + 'player': endpoints(), + 'profiles': endpoints(getByName='/profiles/name/{name}'), + 'telemetry': endpoints(), + }} + + def take(self): + with self.lock: + asked, self.asked = self.asked, [] + return asked + + def stop(self): + self.server.shutdown() + + +def write_properties(directory, online): + props = dict(PROPERTIES, **{'server-port': str(free_port()), 'online-mode': str(online).lower()}) + (directory / 'server.properties').write_text(''.join(f'{k}={v}\n' for k, v in props.items()), + encoding='iso-8859-1') + + +def files(directory): + out = [] + for name in FILES: + path = directory / name + if not path.exists(): + out.append(f'{name}: missing') + continue + text = path.read_text(encoding='utf-8') + # The dates written now: a month on for the cache, the ban's creation. + text = re.sub(r'"(expiresOn|created)": ?"20[2-3]\d-[^"]*"', r'"\1":""', text) + out.append(f'{name}: {text}') + return out + + +def wait_after(server, seen, pattern, timeout=60): + """Waits for a line matching `pattern` after the first `seen` lines.""" + deadline = time.time() + timeout + regex = re.compile(pattern) + while not any(regex.search(l) for l in server.lines[seen:]): + if time.time() > deadline or server.process.poll() is not None: + raise AssertionError(f'{server.log_path.name}: no reply matching {pattern!r}:\n' + + '\n'.join(server.lines[-20:])) + time.sleep(0.1) + + +def run(label, command, build, services, steps, online, transcript): + directory = build / label + write_properties(directory, online) + server = Server(command, directory, f'{label}-{"online" if online else "offline"}') + try: + server.wait_for(r'Done \(') + services.take() + for line, reply in steps: + seen = len(server.lines) + server.console(line) + wait_after(server, seen, reply) + replies = [l for l in server.lines[seen:] if 'System chat:' in l] + transcript.append(f'> {line}') + transcript += [re.sub(r'^\[[^]]*\] ', '', l) for l in replies] + transcript.append(f'asked: {services.take()}') + finally: + server.stop() + transcript += files(directory) + + +def run_side(label, command, build, services): + directory = build / label + if directory.exists(): + shutil.rmtree(directory) + directory.mkdir(parents=True) + (directory / 'eula.txt').write_text('eula=true\n') + (directory / 'usercache.json').write_text(json.dumps(SEEDED), encoding='utf-8') + transcript = [] + run(label, command, build, services, OFFLINE, False, transcript) + run(label, command, build, services, ONLINE, True, transcript) + return transcript + + +def main(): + lock, jars, libraries = base.verify_artifacts() + build = lab.LOCAL / NAME + build.mkdir(parents=True, exist_ok=True) + report = build / 'report.json' + report.unlink(missing_ok=True) + subprocess.run(['cargo', 'build', '--release', '-p', 'horizon-client', '--bin', 'horizon-client'], cwd=lab.ROOT, + check=True, capture_output=True) + metadata = json.loads(subprocess.check_output(['cargo', 'metadata', '--no-deps', '--format-version', '1'], + cwd=lab.ROOT, text=True)) + binary = Path(metadata['target_directory']) / 'release' / ('horizon-client.exe' if os.name == 'nt' else 'horizon-client') + services = Services() + discovery = services.url + '/minecraft/client' + dependencies = os.pathsep.join(map(str, [jars['server'], *libraries])) + vanilla_server = ['java', '-Xmx2g', '-Duser.timezone=UTC', f'-Dminecraft.api.discovery.host={discovery}', + '-cp', dependencies, 'net.minecraft.server.Main', 'nogui'] + horizon_server = [binary, '--resources', lab.LOCAL / 'horizon-client/26.3', '--dedicated', '--nogui'] + os.environ['HORIZON_API_DISCOVERY'] = discovery + try: + vanilla = run_side('vanilla', vanilla_server, build, services) + horizon = run_side('horizon', horizon_server, build, services) + finally: + services.stop() + (build / 'vanilla.txt').write_text('\n'.join(vanilla) + '\n', encoding='utf-8') + (build / 'horizon.txt').write_text('\n'.join(horizon) + '\n', encoding='utf-8') + if vanilla != horizon: + import difflib + diff = '\n'.join(difflib.unified_diff(vanilla, horizon, 'vanilla', 'horizon', n=1, lineterm='')) + raise AssertionError(f'transcripts differ (see {build}/vanilla.txt and horizon.txt):\n' + diff[:6000]) + if not any('Notch' in l for l in vanilla if l.startswith('usercache.json')): + raise AssertionError(f'the cache never held the looked-up account (see {build})') + lab.write_json(report, dict( + schema=1, minecraft=lock['minecraft']['version'], platform=platform.platform(), + java=subprocess.check_output(['java', '--version'], text=True).splitlines()[0], + lines=len(vanilla), output_sha256=lab.digest(build / 'horizon.txt', 'sha256'), + scope='usercache.json (load, expiry, most recently used order, Gson output) and the console finding ' + 'players by name through it and the profile service, offline and online.')) + print(f'user cache: {len(vanilla)} lines identical') + + +if __name__ == '__main__': + try: + main() + except AssertionError as error: + sys.exit(f'{NAME}: {error}') From c3e5a20488295b9a959883e73896a8021dd921d2 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:51:51 +0200 Subject: [PATCH 33/46] Dedicated/LAN server: send tab-list latency every 601 ticks, as vanilla PlayerList.tick broadcasts UPDATE_LATENCY once ++sendAllPlayerInfoIn > 600; the hub sent it every 100 ticks. The extra updates landed in the dedicated_server harness's respawn window and failed it at random. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/hub.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index 83f745dd4..8fcc41329 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -936,7 +936,9 @@ impl Hub { .iter() .map(|g| (g.uuid, g.latency.load(Ordering::Relaxed))) .collect(); - if self.ticks.is_multiple_of(100) && !latencies.is_empty() { + // PlayerList.tick: UPDATE_LATENCY once `++sendAllPlayerInfoIn > 600`, + // so on the 601st tick, then every 601. + if self.ticks.is_multiple_of(601) && !latencies.is_empty() { let entries = latencies .iter() .map(|(uuid, latency)| play::PlayerInfo { From 15b26795e626903bc61fcac9165e7efdf779dc95 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:52:45 +0200 Subject: [PATCH 34/46] Blend animated sprite frames without a roundf call per byte on x86 Interpolated animated sprites (`"interpolate": true`) mix two frames into every mip level with `f32::round`. Baseline x86-64 has no rounding instruction (it needs SSE4.1), so each byte was a call into libm's roundf: 7.8 to 8.5% of the render thread's samples on a Kaby Lake laptop. Round with a truncation and an exact fraction test instead. The result is bit-identical to `f32::round` for every value the blend can produce, checked over all frame byte pairs at 144 blend times. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index 7391ad8b9..536f7ad0a 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -3490,13 +3490,39 @@ fn mix_frames(current: &mut [u8], next: &[u8], millis: u32) { let t = millis as f32 / 1000.0; for (c, n) in current.iter_mut().zip(next) { let (a, b) = (f32::from(*c) / 255.0, f32::from(*n) / 255.0); - *c = ((a * (1.0 - t) + b * t) * 255.0).round() as u8; + *c = round_unorm8((a * (1.0 - t) + b * t) * 255.0); } } +/// `x.round() as u8` for `x >= 0`, without the `roundf` library call that +/// x86-64 makes for every `f32::round` (it has no rounding instruction before +/// SSE4.1): the fraction `x - trunc(x)` is exact below 2^23, so rounding half +/// away from zero is adding one when it is at least a half. +#[inline] +fn round_unorm8(x: f32) -> u8 { + let whole = x as u8; + whole.saturating_add(u8::from(x - f32::from(whole) >= 0.5)) +} #[cfg(test)] mod sprite_upload_tests { use super::*; #[test] + fn blended_frames_round_like_f32_round() { + for millis in (0..1000).step_by(7).chain([999]) { + let t = millis as f32 / 1000.0; + for a in 0..=255u8 { + for b in 0..=255u8 { + let x = (f32::from(a) / 255.0 * (1.0 - t) + f32::from(b) / 255.0 * t) * 255.0; + assert_eq!(round_unorm8(x), x.round() as u8, "{a} {b} {millis}"); + } + } + } + for x in [ + 0.0, 0.49999997, 0.5, 1.5, 2.5, 254.49998, 254.5, 255.0, 255.00002, 300.0, + ] { + assert_eq!(round_unorm8(x), x.round() as u8, "{x}"); + } + } + #[test] fn real_rail_mips_do_not_change_with_larger_array_layers() { let root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) .join("../../.local/horizon-client/26.3"); From c98a4f7a58c2f2f945ef7801ab4dd9711bd54d6c Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:07:14 +0200 Subject: [PATCH 35/46] Server advancements: flushDirty skips players whose progress didn't change PlayerAdvancements.flushDirty only works when it is the first packet or progress changed. Horizon walked the whole advancement tree for every network player every tick to find nothing new: a fifth of the server tick with 50 players. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/advancements.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/horizon-client/src/lan/advancements.rs b/crates/horizon-client/src/lan/advancements.rs index 0e0caf7ff..e0b8ad450 100644 --- a/crates/horizon-client/src/lan/advancements.rs +++ b/crates/horizon-client/src/lan/advancements.rs @@ -144,6 +144,13 @@ impl ServerAdvancements { ) -> Option> { let n = self.tree.list.len(); let first = visible.len() != n; + // flushDirty does nothing unless it is the first packet or progress + // changed: visibility follows progress alone, and every grant and + // revoke is in `changed`. This skips walking the whole tree for + // every player every tick. + if !first && changed.is_empty() { + return None; + } let now = self .tree .visible(&self.kids, |i| progress.done(&self.tree.list[i])); From 47a00d283dde557496639ac438a3372be042d746 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:07:58 +0200 Subject: [PATCH 36/46] Hoppers: look up the block only under container block entities tick_hoppers read the block under every block entity in the loaded world each tick to find the hoppers. A hopper's block entity is always a plain container (BlockEntity::Chest), so only those need the lookup. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/machines.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/horizon-client/src/game/machines.rs b/crates/horizon-client/src/game/machines.rs index 0d334d248..6947041f2 100644 --- a/crates/horizon-client/src/game/machines.rs +++ b/crates/horizon-client/src/game/machines.rs @@ -506,11 +506,15 @@ impl Game<'_> { .default_state("minecraft:hopper") .map(|s| self.res.facts.get(s).name.clone()); let Some(hopper) = hopper else { return Ok(()) }; + // A hopper's block entity is a plain container (`Chest`): only those + // need their block looked up (the ticker runs for a HopperBlockEntity + // whose block is still a hopper, `BlockEntityType.isValid`). let mut positions: Vec = self .world .block_entities - .keys() - .copied() + .iter() + .filter(|(_, e)| matches!(e, BlockEntity::Chest(_))) + .map(|(p, _)| *p) .filter(|p| self.res.facts.get(self.world.block(p.0, p.1, p.2)).name == hopper) .collect(); positions.sort_unstable(); From 690e656048f9ad8b85cd3892dae7d2140c05f29d Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 11:23:09 +0200 Subject: [PATCH 37/46] Chunk streaming: look at each column once when players' areas overlap The generation scan walked every area's square of columns, so with 50 players standing near each other it tested about 100,000 columns a tick (each against every player's range) to find the few hundred around them. The squares are now merged into one run per row first. The candidates are the same: they were sorted and deduplicated before. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/streaming.rs | 75 ++++++++++++++++++++------ 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/crates/horizon-client/src/streaming.rs b/crates/horizon-client/src/streaming.rs index 1754f1550..38fa33c7d 100644 --- a/crates/horizon-client/src/streaming.rs +++ b/crates/horizon-client/src/streaming.rs @@ -264,25 +264,34 @@ impl GenerationScan { } { let mut wanted = Vec::new(); - let areas: Vec<((i32, i32), i32)> = - std::iter::once((input.ranges.center, input.ranges.radius)) - .chain(input.ranges.extra.iter().copied()) - .collect(); - for (center, radius) in areas { + // Each area's square of columns, as one run per row. Players' + // areas overlap (a server's players often stand together), so + // the runs of a row are merged and each column is looked at once. + let mut runs: Vec<(i32, i32, i32)> = Vec::new(); + for (center, radius) in std::iter::once((input.ranges.center, input.ranges.radius)) + .chain(input.ranges.extra.iter().copied()) + { let r = radius + margin.max(reach + 1); - for dz in -r..=r { - for dx in -r..=r { - let (x, z) = (center.0 + dx, center.1 + dz); - if !input.ranges.requested(x, z, input.decorates) - || input.world.chunks.contains_key(&(x, z)) - || input.generating.contains(&(x, z)) - || input.protos.contains_key(&(x, z)) - || input.finishing.contains(&(x, z)) - { - continue; - } - wanted.push((input.ranges.distance(x, z), x, z)); + runs.extend((center.1 - r..=center.1 + r).map(|z| (z, center.0 - r, center.0 + r))); + } + runs.sort_unstable(); + let mut runs = runs.into_iter().peekable(); + while let Some((z, x0, mut x1)) = runs.next() { + while let Some((_, _, next_x1)) = + runs.next_if(|&(nz, nx0, _)| nz == z && nx0 <= x1.saturating_add(1)) + { + x1 = x1.max(next_x1); + } + for x in x0..=x1 { + if !input.ranges.requested(x, z, input.decorates) + || input.world.chunks.contains_key(&(x, z)) + || input.generating.contains(&(x, z)) + || input.protos.contains_key(&(x, z)) + || input.finishing.contains(&(x, z)) + { + continue; } + wanted.push((input.ranges.distance(x, z), x, z)); } } // Forced chunks and their generation neighbourhood. @@ -1569,6 +1578,38 @@ mod tests { } } + #[test] + fn generation_scan_looks_at_overlapping_areas_once() { + // A server's players: many areas around one spot, some apart, one + // touching another only at a corner, and part of the land present. + for decorates in [false, true] { + let mut f = GenerationFixture::new(10, decorates); + for i in 0..40 { + f.extra.push(((i % 7 - 3, i / 7 - 3), 19)); + } + f.extra.push(((200, -150), 19)); + f.extra.push(((243, -107), 19)); + f.extra.push(((-60, 5), 4)); + f.forced.insert((90, 90)); + let chunk = Arc::new(Chunk::empty(0, 0)); + for x in -40i32..40 { + for z in -40i32..40 { + match (x * 7 + z * 13).rem_euclid(5) { + 0 => drop(f.world.chunks.insert((x, z), chunk.clone())), + 1 => drop(f.protos.insert((x, z), None)), + 2 if x % 3 == 0 => drop(f.generating.insert((x, z))), + _ => {} + } + } + } + assert!(baseline_candidates(f.input(), usize::MAX).len() > 1000); + for capacity in [usize::MAX, f.generating.len() + 7] { + let mut gate = GenerationScan::default(); + assert!(f.assert_same(&mut gate, capacity)); + } + } + } + #[test] #[ignore = "reproducible actual generation scheduler benchmark; run with --ignored --nocapture"] fn generation_scan_benchmark() { From 66a8fa118187115643b5e3385697601bd6da8fc6 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 12:13:39 +0200 Subject: [PATCH 38/46] Entity tracking: each entity type's range once per tick, not per player The hub looked up an entity's tracking range (a binary search over type names) for every player and every entity each tick: about 87,000 string comparisons a tick with 50 players. The ranges are now worked out once per entity per tick; the visibility test is the same. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/entity.rs | 10 +++++----- crates/horizon-client/src/lan/hub.rs | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/horizon-client/src/lan/entity.rs b/crates/horizon-client/src/lan/entity.rs index 3b926b372..39c2c4571 100644 --- a/crates/horizon-client/src/lan/entity.rs +++ b/crates/horizon-client/src/lan/entity.rs @@ -66,11 +66,11 @@ fn encode(v: f64) -> i64 { (v * 4096.0).round() as i64 } -/// The horizontal range within which a client sees an entity of `kind` -/// (TrackedEntity.updatePlayer: the type's range, capped by the view distance). -pub fn visible_range(kind: &str, view_distance: i32) -> f64 { - let chunks = i32::from(tracking::settings(kind).0); - f64::from(chunks.min(view_distance) * 16) +/// The type's tracking range in chunks: a client sees an entity of `kind` +/// within it, capped by the view distance, horizontally +/// (TrackedEntity.updatePlayer). +pub fn tracking_chunks(kind: &str) -> i32 { + i32::from(tracking::settings(kind).0) } impl Tracker { diff --git a/crates/horizon-client/src/lan/hub.rs b/crates/horizon-client/src/lan/hub.rs index 8fcc41329..4b3acea4c 100644 --- a/crates/horizon-client/src/lan/hub.rs +++ b/crates/horizon-client/src/lan/hub.rs @@ -1362,6 +1362,12 @@ impl Hub { all.extend(ctx.entities.iter().cloned()); let by_id: std::collections::HashMap = all.iter().enumerate().map(|(i, e)| (e.id, i)).collect(); + // Each entity type's tracking range, looked up once rather than for + // every player. + let ranges: Vec = all + .iter() + .map(|e| super::entity::tracking_chunks(&e.kind)) + .collect(); for gi in 0..self.guests.len() { if !self.guests[gi].placed { continue; @@ -1371,8 +1377,9 @@ impl Hub { let origin = self.guests[gi].position; // TrackedEntity.updatePlayer: within the type's range (capped by the // view distance) horizontally, in a chunk the client has. - let visible = |g: &Guest, e: &EntityState| { - let range = super::entity::visible_range(&e.kind, view); + let visible = |g: &Guest, ei: usize| { + let e = &all[ei]; + let range = f64::from(ranges[ei].min(view) * 16); let (dx, dz) = (origin[0] - e.position[0], origin[2] - e.position[2]); let chunk = ( (e.position[0].floor() as i32) >> 4, @@ -1384,7 +1391,7 @@ impl Hub { let mut removed = Vec::new(); for id in self.guests[gi].tracker.ids() { match by_id.get(&id) { - Some(&ei) if visible(&self.guests[gi], &all[ei]) => {} + Some(&ei) if visible(&self.guests[gi], ei) => {} _ => removed.push(id), } } @@ -1394,14 +1401,14 @@ impl Hub { } self.guests[gi].send(&C::RemoveEntities(play::RemoveEntities { ids: removed })); } - for e in &all { + for (ei, e) in all.iter().enumerate() { if e.id == me { continue; } if self.guests[gi].tracker.is_tracking(e.id) { let packets = self.guests[gi].tracker.update(e); self.guests[gi].send_all(&packets); - } else if visible(&self.guests[gi], e) { + } else if visible(&self.guests[gi], ei) { let Some(kind) = self.entity_type(&e.kind) else { continue; }; From 4cdad5aae68cb3ace52f156d81a3a74c8922c871 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 13:00:27 +0200 Subject: [PATCH 39/46] Chunk packets: one cache lock per column for its non-air sections encode_in asks whether each of the nine surrounding columns' 24 sections holds anything, to decide which light layers exist: 216 cache lookups, each locking the cache and SipHashing a section's address. The column's sections now share one lock, and the cache uses the Fx hash. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/chunks.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/horizon-client/src/lan/chunks.rs b/crates/horizon-client/src/lan/chunks.rs index 6b8c41e55..7d09427f7 100644 --- a/crates/horizon-client/src/lan/chunks.rs +++ b/crates/horizon-client/src/lan/chunks.rs @@ -4,6 +4,7 @@ use crate::{ chunk::{Chunk, Light, MIN_Y, SECTIONS, Section}, containers::BlockEntity, + fast_hash::FxHashMap, }; use horizon_protocol::{ buf::set_bit, @@ -91,7 +92,7 @@ pub struct ChunkEncoder { /// The save's tables, for the heightmaps. pub tables: Option>, /// Sections already looked at, by address (see `Encoded`). - cache: std::sync::Mutex>, + cache: std::sync::Mutex>, /// Each column's heightmaps, with the sections they were made from. heights: std::sync::Mutex>, /// The level's sections among a column's: all of them in the Overworld, @@ -258,22 +259,29 @@ impl ChunkEncoder { /// The cached entry for a section, made with `non_air` when missing. fn cached(&self, section: &Arc

, read: impl FnOnce(&mut Encoded) -> T) -> T { - let mut cache = self.cache.lock().unwrap(); + read(self.entry(&mut self.cache.lock().unwrap(), section)) + } + + /// A section's entry in the locked cache, made with `non_air` when missing. + fn entry<'a>( + &self, + cache: &'a mut FxHashMap, + section: &Arc
, + ) -> &'a mut Encoded { if cache.len() >= CACHE_SWEEP { cache.retain(|_, e| e.section.strong_count() > 0); if cache.len() >= CACHE_SWEEP / 2 { cache.clear(); } } - let entry = cache + cache .entry(Arc::as_ptr(section) as usize) .or_insert_with(|| Encoded { section: Arc::downgrade(section), non_air: self.non_air(section), wire: None, light: None, - }); - read(entry) + }) } /// LevelChunkSection.hasOnlyAir, negated. @@ -382,8 +390,10 @@ impl ChunkEncoder { /// The non-air sections of a column as bits (LevelChunkSection.hasOnlyAir). fn occupied(&self, chunk: &Chunk) -> u64 { let mut bits = 0u64; + // One lock for the column: encode_in asks for nine columns' sections. + let mut cache = self.cache.lock().unwrap(); for (i, s) in chunk.sections[self.sections.clone()].iter().enumerate() { - if self.cached(s, |e| e.non_air) { + if self.entry(&mut cache, s).non_air { bits |= 1 << i; } } From a7af5b76cf8c2d1c83361ea618de3e171b054ce1 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 13:03:47 +0200 Subject: [PATCH 40/46] Chunk packets: keep each section's block entity blocks with its bytes Every chunk packet scanned all 4,096 blocks of each section holding a block entity block to list them, though the section's wire bytes were already cached. The cache now keeps those blocks (index and state, in scan order) beside the bytes, made in the same pass that encodes them. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/chunks.rs | 140 ++++++++++++++++++------ 1 file changed, 108 insertions(+), 32 deletions(-) diff --git a/crates/horizon-client/src/lan/chunks.rs b/crates/horizon-client/src/lan/chunks.rs index 6b8c41e55..ab440af42 100644 --- a/crates/horizon-client/src/lan/chunks.rs +++ b/crates/horizon-client/src/lan/chunks.rs @@ -115,12 +115,16 @@ struct Heights { struct Encoded { section: std::sync::Weak
, non_air: bool, - /// LevelChunkSection.write, and whether it holds block entity blocks. - wire: Option<(Arc<[u8]>, bool)>, + /// LevelChunkSection.write, and its block entity blocks. + wire: Option<(Arc<[u8]>, Entities)>, /// The section's light as the wire's two DataLayers, when not uniform. light: Option>, } +/// A section's blocks that have a block entity type, as (index, state) in +/// index order (y, then z, then x). +type Entities = Arc<[(u16, u16)]>; + /// One section's light as DataLayers (two blocks per byte, the even one in /// the low nibble), and whether each holds any light. struct Layers { @@ -291,14 +295,14 @@ impl ChunkEncoder { } /// A section on the wire, from the cache or encoded now. - fn section_wire(&self, section: &Arc
) -> (Arc<[u8]>, bool) { + fn section_wire(&self, section: &Arc
) -> (Arc<[u8]>, Entities) { if let Some(wire) = self.cached(section, |e| e.wire.clone()) { return wire; } let (encoded, entities) = self.section(section); let mut w = horizon_protocol::buf::Writer::new(); encoded.write(&mut w); - let wire: (Arc<[u8]>, bool) = (w.data.into(), entities); + let wire: (Arc<[u8]>, Entities) = (w.data.into(), entities.into()); self.cached(section, |e| e.wire = Some(wire.clone())); wire } @@ -326,9 +330,9 @@ impl ChunkEncoder { .is_none_or(|f| f & NON_AIR == 0) } - fn section(&self, section: &Section) -> (horizon_protocol::chunk::Section, bool) { + fn section(&self, section: &Section) -> (horizon_protocol::chunk::Section, Vec<(u16, u16)>) { let mut values = Vec::with_capacity(BLOCKS); - let (mut non_empty, mut fluids, mut entities) = (0i16, 0i16, false); + let (mut non_empty, mut fluids, mut entities) = (0i16, 0i16, Vec::new()); let mut count = |state: u16, n: i16| { let f = self.flags.get(usize::from(state)).copied().unwrap_or(0); if f & NON_AIR != 0 { @@ -342,12 +346,16 @@ impl ChunkEncoder { // One block everywhere (all air, mostly): what from_values would give. let uniform = section.blocks.uniform(); if let Some(v) = uniform { - entities = count(v as u16, BLOCKS as i16); + if count(v as u16, BLOCKS as i16) { + entities = (0..BLOCKS as u16).map(|i| (i, v as u16)).collect(); + } } else { let mut unpacked = [0u16; BLOCKS]; section.unpack(&mut unpacked); - for &v in &unpacked { - entities |= count(v, 1); + for (i, &v) in unpacked.iter().enumerate() { + if count(v, 1) { + entities.push((i as u16, v)); + } values.push(i32::from(v)); } } @@ -431,29 +439,30 @@ impl ChunkEncoder { .skip(self.sections.start) .take(self.sections.len()) { - let (encoded, has_entities) = self.section_wire(s); - if has_entities { - for y in 0..16 { - for z in 0..16 { - for x in 0..16 { - let state = s.get(crate::chunk::index(x, y, z)); - if let Some(kind) = self.entity_type(state) { - let wy = MIN_Y + (i as i32) * 16 + y; - let pos = (chunk.x * 16 + x, wy, chunk.z * 16 + z); - entity_infos.push(BlockEntityInfo { - packed_xz: ((x << 4) | z) as i8, - y: wy as i16, - kind, - // BlockEntityInfo.create: an empty update tag is not sent. - tag: block_entities - .get(&pos) - .and_then(entity_tag) - .unwrap_or(Tag::End), - }); - } - } - } - } + let (encoded, entities) = self.section_wire(s); + // The section's block entity blocks, kept with its bytes, in the + // order a scan of every block would find them. + for &(index, state) in entities.iter() { + let Some(kind) = self.entity_type(state) else { + continue; + }; + let (x, y, z) = ( + i32::from(index & 15), + i32::from(index >> 8), + i32::from(index >> 4 & 15), + ); + let wy = MIN_Y + (i as i32) * 16 + y; + let pos = (chunk.x * 16 + x, wy, chunk.z * 16 + z); + entity_infos.push(BlockEntityInfo { + packed_xz: ((x << 4) | z) as i8, + y: wy as i16, + kind, + // BlockEntityInfo.create: an empty update tag is not sent. + tag: block_entities + .get(&pos) + .and_then(entity_tag) + .unwrap_or(Tag::End), + }); } buffer.extend_from_slice(&encoded); } @@ -669,6 +678,73 @@ mod tests { assert_eq!(block_entity_type("minecraft:stone"), None); } + #[test] + fn block_entities_come_from_the_cached_section_in_scan_order() { + let builtin = Builtin::parse( + r#"{"minecraft:block_entity_type": {"entries": { + "minecraft:chest": {"protocol_id": 1}, + "minecraft:sign": {"protocol_id": 7}}}}"#, + ) + .unwrap(); + let states = [ + "minecraft:air", + "minecraft:stone", + "minecraft:chest", + "minecraft:oak_sign", + ] + .map(|n| (Arc::::from(n), false)); + let encoder = ChunkEncoder::new(states, &builtin, &[], &[]); + let mut chunk = Chunk::empty(2, -3); + for (x, y, z, state) in [(15, 3, 0, 2), (0, 3, 15, 3), (4, 3, 4, 1), (7, 40, 2, 2)] { + chunk.set(x, MIN_Y + y, z, state); + } + // Every block of a section looked at, as the scan did before the cache. + let scan = |chunk: &Chunk| { + let mut found = Vec::new(); + for (i, s) in chunk.sections.iter().enumerate() { + for y in 0..16 { + for z in 0..16 { + for x in 0..16 { + let state = s.get(crate::chunk::index(x, y, z)); + if let Some(kind) = encoder.entity_type(state) { + found.push((x, MIN_Y + i as i32 * 16 + y, z, kind)); + } + } + } + } + } + // Then the order the packet gives them, as encode_blocks does. + java_hash_order(&mut found, |e| { + (chunk.x * 16 + e.0, e.1, chunk.z * 16 + e.2) + }); + found + }; + let sent = |chunk: &Chunk| { + let packet = encoder.encode(chunk, &HashMap::new()); + let infos = packet.chunk.block_entities; + infos + .iter() + .map(|e| { + let xz = e.packed_xz as u8; + ( + i32::from(xz >> 4), + i32::from(e.y), + i32::from(xz & 15), + e.kind, + ) + }) + .collect::>() + }; + let expected = scan(&chunk); + assert_eq!(expected.len(), 3); + assert_eq!(sent(&chunk), expected); + // From the cache the second time, and after an edit. + assert_eq!(sent(&chunk), expected); + chunk.set(15, MIN_Y + 3, 0, 0); + chunk.set(9, MIN_Y + 3, 9, 3); + assert_eq!(sent(&chunk), scan(&chunk)); + } + fn encoder() -> ChunkEncoder { let states = ["minecraft:air", "minecraft:stone", "minecraft:water"] .map(|n| (Arc::::from(n), n.ends_with("water"))); From 1ac9c72ea31e6110386ee97b24a78d6291ed24cc Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 13:15:36 +0200 Subject: [PATCH 41/46] Server: Fx hashing for each player's sent chunks and tracked entities The hub tests every player's sent-chunk set for every entity and every column of the view each tick, and each player's tracked-entity map for every entity: tens of thousands of SipHash lookups a tick with 50 players. Both now use the Fx hash. Their iteration order was random before and carries no meaning. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/lan/entity.rs | 2 +- crates/horizon-client/src/lan/guest.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/horizon-client/src/lan/entity.rs b/crates/horizon-client/src/lan/entity.rs index 3b926b372..0f82ea60c 100644 --- a/crates/horizon-client/src/lan/entity.rs +++ b/crates/horizon-client/src/lan/entity.rs @@ -58,7 +58,7 @@ struct Sent { #[derive(Default)] pub struct Tracker { - sent: std::collections::HashMap, + sent: crate::fast_hash::FxHashMap, } /// VecDeltaCodec.encode. diff --git a/crates/horizon-client/src/lan/guest.rs b/crates/horizon-client/src/lan/guest.rs index db426ca21..720cb53d6 100644 --- a/crates/horizon-client/src/lan/guest.rs +++ b/crates/horizon-client/src/lan/guest.rs @@ -8,7 +8,7 @@ use horizon_protocol::{ packets::{configuration::ClientInformation, play}, }; use std::{ - collections::{HashSet, VecDeque}, + collections::VecDeque, sync::{Arc, atomic::AtomicI32}, }; @@ -77,7 +77,7 @@ pub struct Guest { pub loaded: bool, // Chunks. pub center: Option<(i32, i32)>, - pub sent_chunks: HashSet<(i32, i32)>, + pub sent_chunks: crate::fast_hash::FxHashSet<(i32, i32)>, pub chunk_queue: Vec<(i32, i32)>, pub unacknowledged: u32, pub chunks_per_tick: f32, @@ -189,7 +189,7 @@ impl Guest { teleport_counter: 0, loaded: false, center: None, - sent_chunks: HashSet::new(), + sent_chunks: Default::default(), chunk_queue: Vec::new(), unacknowledged: 0, chunks_per_tick: 9.0, From d989d4033f2ce9bdc31d72328aeb534c949e5d3c Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 14:16:54 +0200 Subject: [PATCH 42/46] Advancements: read the tree on another thread while the world loads The first criterion trigger of a world's first tick loaded the advancement tree: about 1,400 JSON files read and parsed on the game thread, about 60 ms of a 125 ms first tick. open_world now starts that read on a thread, and the first advancement_tree() takes its result, the same tree as before. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 1 + .../horizon-client/src/game/advancements.rs | 22 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 0f898f8bf..ba1aab9e0 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -6231,6 +6231,7 @@ impl Game<'_> { self.fns = Default::default(); self.bosses = Default::default(); reset_world_progress(&mut self.adv, &mut self.stats); + self.prefetch_advancement_tree(); self.restore_player_environment = true; // RandomSequences: the world's data/minecraft/random_sequences.dat. self.rand_sequences = diff --git a/crates/horizon-client/src/game/advancements.rs b/crates/horizon-client/src/game/advancements.rs index 22d9a4da0..5cf09bc44 100644 --- a/crates/horizon-client/src/game/advancements.rs +++ b/crates/horizon-client/src/game/advancements.rs @@ -88,6 +88,9 @@ pub(super) struct AdvState { pub(super) changed: BTreeSet, pub(super) unlocked: Vec, pub(super) announced: Vec, + /// The tree being read on another thread since the world opened + /// (`prefetch_advancement_tree`), taken by the first `advancement_tree`. + pub(super) pending_tree: Option>, } /// The game's world for predicates. struct View<'a, 'g>(&'a Game<'g>); @@ -221,10 +224,27 @@ impl Game<'_> { /// The advancement tree, loaded once. pub(super) fn advancement_tree(&mut self) -> Arc { if self.adv.tree.list.is_empty() { - self.adv.tree = Arc::new(Tree::load(&self.options.resources.join("data"))); + let tree = match self.adv.pending_tree.take().map(|h| h.join()) { + Some(Ok(tree)) => tree, + _ => Tree::load(&self.options.resources.join("data")), + }; + self.adv.tree = Arc::new(tree); } self.adv.tree.clone() } + /// Start reading the advancement files on another thread while the world + /// loads. The first tick's first criterion trigger used to read and parse + /// all of them on the game thread (about 60 ms). + pub(super) fn prefetch_advancement_tree(&mut self) { + if !self.adv.tree.list.is_empty() || self.adv.pending_tree.is_some() { + return; + } + let data = self.options.resources.join("data"); + self.adv.pending_tree = std::thread::Builder::new() + .name("horizon-advancements".into()) + .spawn(move || Tree::load(&data)) + .ok(); + } pub(super) fn load_advancements(&mut self) { if self.adv.loaded || self.remote.is_some() || self.no_player_here() { return; From 05821d4e621c438e7a1ed933adb9f451ee323185 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 14:38:54 +0200 Subject: [PATCH 43/46] Launcher: Windows tests check behaviour, not symlink paths On Windows the launcher links another launcher's client jar with a hard link (a copy across volumes) and its libraries and assets with a junction, since symlinks need developer mode. canonicalize() of a hard link is its own path, so the sources tests, which compared canonical paths, failed on Windows and blocked every launcher release since launcher-v0.4.0. They now check that the linked jar is the launcher's file (a byte written through one shows in the other), which holds for a symlink and a hard link alike. The modpack profile test compares paths as paths rather than strings ending in "a/carry". mklink /J's paths are always quoted: Rust only quotes arguments with spaces, and cmd reads an unquoted & or ^ in a user folder as its own syntax. CI runs every launcher test target, not just the library's. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/launcher.yml | 3 ++- launcher/src/modpacks.rs | 3 ++- launcher/src/sources.rs | 16 +++++++++++--- launcher/src/sources_tests.rs | 38 +++++++++++++++++++++++++++------- 4 files changed, 47 insertions(+), 13 deletions(-) diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml index 2ab491207..4f2a6076c 100644 --- a/.github/workflows/launcher.yml +++ b/.github/workflows/launcher.yml @@ -138,7 +138,8 @@ jobs: echo "::notice::No Metal toolchain on this runner: GPUI compiles its shaders at run time" echo "LAUNCHER_FEATURES=gpui/runtime_shaders" >> "$GITHUB_ENV" fi - - run: cargo test --release --locked --lib ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"} + # Every test target (the library, the binary, tests/), on each system the launcher ships for. + - run: cargo test --release --locked ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"} - run: cargo build --release --locked ${LAUNCHER_FEATURES:+--features "$LAUNCHER_FEATURES"} - name: The version is the release's run: | diff --git a/launcher/src/modpacks.rs b/launcher/src/modpacks.rs index 6d4553a14..6ff53e4be 100644 --- a/launcher/src/modpacks.rs +++ b/launcher/src/modpacks.rs @@ -241,7 +241,8 @@ mod tests { .map(|a| a.to_string_lossy().into_owned()) .collect(); assert_eq!(args.len(), 4); - assert!(args[1].ends_with("a/carry") && args[3].ends_with("b/carry")); + assert_eq!(Path::new(&args[1]), work.join("mods").join("a").join("carry")); + assert_eq!(Path::new(&args[3]), work.join("mods").join("b").join("carry")); assert_eq!(cmd.get_current_dir(), Some(profile_home(&work).as_path())); assert!(profile_home(&work).is_dir()); fs::remove_dir_all(&root).unwrap(); diff --git a/launcher/src/sources.rs b/launcher/src/sources.rs index aafdb51e4..f6a9753ea 100644 --- a/launcher/src/sources.rs +++ b/launcher/src/sources.rs @@ -426,16 +426,26 @@ fn make_link(target: &Path, link: &Path) -> std::io::Result<()> { std::os::unix::fs::symlink(target, link) } -/// Symlinks need developer mode on Windows: a junction for a folder, a hard link for a file. +/// Symlinks need developer mode on Windows: a junction for a folder, a hard link for a file (a +/// copy on another volume). #[cfg(windows)] fn make_link(target: &Path, link: &Path) -> std::io::Result<()> { + use std::os::windows::process::CommandExt; if !target.is_dir() { return fs::hard_link(target, link).or_else(|_| fs::copy(target, link).map(|_| ())); } + // Always quoted: cmd reads `&`, `^` or `(` in an unquoted path (a user folder may have + // them) as its own syntax. A Windows path never holds a quote. + let quoted = |path: &Path| { + let mut arg = std::ffi::OsString::from("\""); + arg.push(path); + arg.push("\""); + arg + }; let status = std::process::Command::new("cmd") .args(["/C", "mklink", "/J"]) - .arg(link) - .arg(target) + .raw_arg(quoted(link)) + .raw_arg(quoted(target)) .stdout(std::process::Stdio::null()) .status()?; match status.success() { diff --git a/launcher/src/sources_tests.rs b/launcher/src/sources_tests.rs index f603aaf0a..381d19f27 100644 --- a/launcher/src/sources_tests.rs +++ b/launcher/src/sources_tests.rs @@ -94,15 +94,25 @@ fn resolve_with( } } +/// Whether `a` and `b` are one file, as a symlink (Unix) or a hard link (Windows) makes them: +/// a byte written through `a` shows in `b`. Both are left as they were. +fn same_file(a: &Path, b: &Path) -> bool { + use std::io::Write; + let (before_a, before_b) = (fs::read(a).unwrap(), fs::read(b).unwrap()); + let mut file = fs::OpenOptions::new().write(true).open(a).unwrap(); + file.write_all(&[!before_a[0]]).unwrap(); + drop(file); + let same = fs::read(b).unwrap() != before_b; + fs::write(a, &before_a).unwrap(); + same +} + /// The linked folder is the official layout, pointing at the launcher's files. fn assert_linked(linked: &Path, base: &Path, jar: &str) { let v = linked.join("versions/26.3"); assert_eq!(fs::read(v.join("26.3.jar")).unwrap(), CLIENT); assert_eq!(fs::read(v.join("26.3.json")).unwrap(), MANIFEST); - assert_eq!( - fs::canonicalize(v.join("26.3.jar")).unwrap(), - fs::canonicalize(base.join(jar)).unwrap() - ); + assert!(same_file(&v.join("26.3.jar"), &base.join(jar))); assert_eq!( fs::read(linked.join("libraries/org/lib/1/lib-1.jar")).unwrap(), b"lib" @@ -110,6 +120,19 @@ fn assert_linked(linked: &Path, base: &Path, jar: &str) { assert!(linked.join("assets/indexes/30.json").is_file()); } +/// Folders whose names cmd would read as its own syntax unquoted are still linked (Windows makes +/// a junction through `mklink /J`; a name without spaces isn't quoted by itself). +#[test] +fn folders_with_ampersands_are_linked() { + let s = Scratch::new("a&b(c)"); + let jar = "libraries/com/mojang/minecraft/26.3/minecraft-26.3-client.jar"; + let dir = s.launcher("Prism&Co", "", jar); + let linked = s.0.join("linked&here"); + let got = resolve_with(&dir, &[], &linked, &Mojang::new(MANIFEST)).unwrap(); + assert_eq!(got, linked); + assert_linked(&linked, &dir, jar); +} + #[test] fn maven_names_become_repository_paths() { assert_eq!( @@ -295,10 +318,9 @@ fn relinking_follows_the_launcher_the_files_now_come_from() { let modrinth = s.0.join("ModrinthApp"); s.write("ModrinthApp/meta/versions/26.3/26.3.jar", CLIENT); resolve_with(&modrinth, &[], &linked, &mojang).unwrap(); - assert_eq!( - fs::canonicalize(linked.join("versions/26.3/26.3.jar")).unwrap(), - fs::canonicalize(modrinth.join("meta/versions/26.3/26.3.jar")).unwrap() - ); + let jar = linked.join("versions/26.3/26.3.jar"); + assert!(same_file(&jar, &modrinth.join("meta/versions/26.3/26.3.jar"))); + assert!(!same_file(&jar, &prism.join(prism_jar))); // The Modrinth App folder has no libraries or assets: the old links are gone, and the // folders they pointed at are untouched. assert!(fs::symlink_metadata(linked.join("libraries")).is_err()); From bff5891073489bd2bcd850869c071e5942498cbe Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 14:46:16 +0200 Subject: [PATCH 44/46] Launcher: Cargo.lock has horizon-port-pack's horizon-mods dependency horizon-port-pack now depends on horizon-mods (1f1d5a5a), which the launcher's own lock file didn't have, so every --locked build of the launcher failed. Co-Authored-By: Claude Opus 5.5 --- launcher/Cargo.lock | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/launcher/Cargo.lock b/launcher/Cargo.lock index af0588af6..bde1037b3 100644 --- a/launcher/Cargo.lock +++ b/launcher/Cargo.lock @@ -2681,10 +2681,22 @@ dependencies = [ "zip", ] +[[package]] +name = "horizon-mods" +version = "0.1.0" +dependencies = [ + "log", + "serde", + "serde_json", + "toml 1.1.8+spec-1.1.0", + "zip", +] + [[package]] name = "horizon-port-pack" version = "0.1.0" dependencies = [ + "horizon-mods", "serde", "serde_json", "sha1", From f49af8d995b2908f167e8a42c8363e00f9d65911 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 14:59:01 +0200 Subject: [PATCH 45/46] Launcher releases: count every crate the launcher builds in LAUNCHER_PATHS and launcher.yml's push paths now list horizon-bench, horizon-friends, horizon-mods and horizon-port-pack too, the launcher's path packages per cargo metadata. A change there (like the horizon-mods dependency that left launcher/Cargo.lock stale) then builds and releases the launcher instead of going unnoticed. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/launcher.yml | 10 +++++++--- launcher/Cargo.lock | 12 ++++++++++++ tools/release_train.py | 12 +++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml index 2ab491207..55db3965a 100644 --- a/.github/workflows/launcher.yml +++ b/.github/workflows/launcher.yml @@ -1,7 +1,6 @@ name: launcher # Builds the launcher on Linux, macOS and Windows, and releases it by itself (docs/release-flow.md): after a -# push to main that changes the launcher or what it builds in (crates/horizon-prepare, crates/horizon-theme, -# crates/horizon-telemetry), +# push to main that changes the launcher or a crate it builds in (the paths below), # every 10 minutes (a release waiting for merges to settle goes out) and by hand, tools/release_train.py decides as # for the game. # A release is launcher-vX.Y.Z: the patch after the last launcher tag, or the next minor when a merged pull @@ -14,10 +13,15 @@ on: push: branches: [main, launcher, 'launcher-*'] paths: + # Every crate the launcher builds in, as tools/release_train.py's LAUNCHER_PATHS. - 'launcher/**' + - 'crates/horizon-bench/**' + - 'crates/horizon-friends/**' + - 'crates/horizon-mods/**' + - 'crates/horizon-port-pack/**' - 'crates/horizon-prepare/**' - - 'crates/horizon-theme/**' - 'crates/horizon-telemetry/**' + - 'crates/horizon-theme/**' - '.github/workflows/launcher.yml' schedule: - cron: '7-59/10 * * * *' diff --git a/launcher/Cargo.lock b/launcher/Cargo.lock index af0588af6..bde1037b3 100644 --- a/launcher/Cargo.lock +++ b/launcher/Cargo.lock @@ -2681,10 +2681,22 @@ dependencies = [ "zip", ] +[[package]] +name = "horizon-mods" +version = "0.1.0" +dependencies = [ + "log", + "serde", + "serde_json", + "toml 1.1.8+spec-1.1.0", + "zip", +] + [[package]] name = "horizon-port-pack" version = "0.1.0" dependencies = [ + "horizon-mods", "serde", "serde_json", "sha1", diff --git a/tools/release_train.py b/tools/release_train.py index a1af28449..70e7b0287 100644 --- a/tools/release_train.py +++ b/tools/release_train.py @@ -39,7 +39,17 @@ EXPORTERS = "mods/horizon/src/test/java/dev/horizonlab/parity/" # What players run. Documentation (*.md), tests, benchmarks and harness probes (examples/) never count. GAME_PATHS = ["crates/", "xtask/", "packaging/", "Cargo.toml", "Cargo.lock", "research-lock.json"] -LAUNCHER_PATHS = ["launcher/", "crates/horizon-prepare/", "crates/horizon-theme/", "crates/horizon-telemetry/"] +# Every crate the launcher builds in (cargo metadata --manifest-path launcher/Cargo.toml: the path packages). +LAUNCHER_PATHS = [ + "launcher/", + "crates/horizon-bench/", + "crates/horizon-friends/", + "crates/horizon-mods/", + "crates/horizon-port-pack/", + "crates/horizon-prepare/", + "crates/horizon-telemetry/", + "crates/horizon-theme/", +] LAUNCHER_IGNORED = ["launcher/links.json", "launcher/docs/", "launcher/tests/"] FOOTER = { From bbde190f06c66764b26d4e919ac371567c7b38b5 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sat, 17 Oct 2026 16:51:53 +0200 Subject: [PATCH 46/46] Merge main into feat/server-move-checks TickCtx gained `collision` here; main's two newer initializers (lan_actions respawn, server_travel's server_ctx) now pass it too, as every other one does. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/lan_actions.rs | 1 + crates/horizon-client/src/game/server_travel.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/horizon-client/src/game/lan_actions.rs b/crates/horizon-client/src/game/lan_actions.rs index 1d3433cf0..7cd4b0474 100644 --- a/crates/horizon-client/src/game/lan_actions.rs +++ b/crates/horizon-client/src/game/lan_actions.rs @@ -944,6 +944,7 @@ impl Game<'_> { }, tick_rate: self.clock.rate(), tick_frozen: self.clock.frozen(), + collision: Some(self.collision), }; host.hub.respawn(i, spawn, &ctx); } diff --git a/crates/horizon-client/src/game/server_travel.rs b/crates/horizon-client/src/game/server_travel.rs index d5b1e4d95..e82291978 100644 --- a/crates/horizon-client/src/game/server_travel.rs +++ b/crates/horizon-client/src/game/server_travel.rs @@ -243,6 +243,7 @@ impl Game<'_> { }, tick_rate: self.clock.rate(), tick_frozen: self.clock.frozen(), + collision: Some(self.collision), } } }