From 71edc9d41ce51c555f4c80b630a6e7c3f533d1b8 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 22 Oct 2026 13:18:54 +0000 Subject: [PATCH 1/2] Prepare with Minecraft's own Java 25 when no JDK is installed On a Mac without a JDK, preparing failed with "Java 25 is needed ... /usr/bin/javac -version printed no version: Unable to locate a Java Runtime": /usr/bin/javac is macOS's placeholder. Mojang's Java runtimes are whole JDKs, javac included (java-runtime-epsilon is 25.0.1 on every platform), and the official launcher has already downloaded one for anyone who played 26.3. - horizon-prepare: java::find also tries Minecraft's runtimes (/runtime///, jre.bundle on macOS) and the launcher's pick (Options::java_home), and names the macOS placeholder for what it is. - launcher: when no JDK is found, downloads the runtime the version JSON names (javaVersion.component) from Mojang into its own game folder, every file checked against its sha1, executables and links as the official launcher lays them out. A version's own preparer binary or Python script gets it through JAVA_HOME and the PATH. Checked for real on Linux: the download is 147 files, its javac 25.0.1 compiles and runs a class with --release 25. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01AxbYUJt4ShJFCdyLNCxF21 --- crates/horizon-prepare/src/java.rs | 96 ++++++++++++++++++++++-- crates/horizon-prepare/src/lib.rs | 9 ++- crates/horizon-prepare/src/main.rs | 1 + launcher/src/backend.rs | 97 +++++++++++++++++++----- launcher/src/mojang.rs | 116 +++++++++++++++++++++++++++++ launcher/src/mojang_tests.rs | 96 ++++++++++++++++++++++++ website/docs/install.md | 2 +- website/docs/troubleshooting.md | 2 +- 8 files changed, 390 insertions(+), 29 deletions(-) diff --git a/crates/horizon-prepare/src/java.rs b/crates/horizon-prepare/src/java.rs index d54ef0949..a159fb055 100644 --- a/crates/horizon-prepare/src/java.rs +++ b/crates/horizon-prepare/src/java.rs @@ -41,11 +41,19 @@ fn javac_major(javac: &Path) -> Result { .skip_while(|w| *w != "javac") .nth(1) .ok_or_else(|| { - format!( - "{} -version printed no version: {}", - javac.display(), - text.trim() - ) + // macOS ships /usr/bin/javac as a placeholder that only says no Java is installed. + if text.contains("Unable to locate a Java Runtime") { + format!( + "{} is macOS's placeholder (no Java installed)", + javac.display() + ) + } else { + format!( + "{} -version printed no version: {}", + javac.display(), + text.trim() + ) + } })?; let mut parts = version.split(['.', '-', '+', '_']); let first: u32 = parts.next().and_then(|p| p.parse().ok()).unwrap_or(0); @@ -126,11 +134,38 @@ fn installed_jdks(parents: &[PathBuf], major: i64) -> Vec { homes } +/// The Java runtimes the official launcher downloaded into `runtime` (a game directory's +/// `runtime` folder: `///`, a macOS one in `jre.bundle`). Mojang's +/// runtimes are whole JDKs, javac included, so a player who has run Minecraft has one already. +pub fn minecraft_runtimes(runtime: &Path) -> Vec { + let children = |dir: &Path| -> Vec { + let mut paths: Vec = fs::read_dir(dir) + .map(|entries| entries.flatten().map(|e| e.path()).collect()) + .unwrap_or_default(); + paths.sort(); + paths + }; + let mut homes = Vec::new(); + for component in children(runtime) { + for platform in children(&component) { + let home = platform.join(component.file_name().unwrap_or_default()); + for home in [home.join("jre.bundle/Contents/Home"), home] { + if executable(&home.join("bin"), "javac").is_file() { + homes.push(home); + break; + } + } + } + } + homes +} + /// Finds a JDK with `javac` of at least `major`, the version research-lock.json pins: /// `JAVA_HOME` when it holds one, else `javac` and `java` on the PATH (as the Python preparer -/// ran them), else, on macOS, the JDK `/usr/libexec/java_home -v ` reports, else a JDK -/// in the folders installers put them in (`jdk_parents`). -pub fn find(major: i64) -> Result { +/// ran them), else, on macOS, the JDK `/usr/libexec/java_home -v ` reports, else the JDK +/// homes in `more` (the launcher's pick, Minecraft's own runtimes), else a JDK in the folders +/// installers put them in (`jdk_parents`). +pub fn find(major: i64, more: &[PathBuf]) -> Result { let need = format!( "Java {major} is needed (a JDK with javac, e.g. Eclipse Temurin {major}). \ Install it, or set JAVA_HOME to it, and try again." @@ -164,6 +199,14 @@ pub fn find(major: i64) -> Result { } } } + for home in more { + let bin = home.join("bin"); + candidates.push(( + executable(&bin, "javac"), + executable(&bin, "java"), + "Minecraft's Java", + )); + } for home in installed_jdks(&jdk_parents(), major) { let bin = home.join("bin"); candidates.push(( @@ -205,6 +248,15 @@ pub fn classpath<'a>(paths: impl IntoIterator) -> String { } impl Jdk { + /// The JDK's home, the folder above `bin` (what `JAVA_HOME` names). + pub fn home(&self) -> PathBuf { + self.javac + .parent() + .and_then(Path::parent) + .map(Path::to_path_buf) + .unwrap_or_default() + } + /// `javac --release -proc:none` with Python's `subprocess.run(..., check=True, /// stdout=log, stderr=STDOUT, timeout=3600)`. pub fn javac(&self, major: i64, args: &[String], log: &fs::File) -> Result<(), String> { @@ -301,4 +353,32 @@ mod tests { ); fs::remove_dir_all(&dir).unwrap(); } + + #[test] + fn minecraft_runtimes_are_found_in_the_launchers_layout() { + let dir = + std::env::temp_dir().join(format!("horizon-prepare-runtimes-{}", std::process::id())); + let _ = fs::remove_dir_all(&dir); + let make = |home: PathBuf, javac: bool| { + fs::create_dir_all(home.join("bin")).unwrap(); + if javac { + fs::write(executable(&home.join("bin"), "javac"), b"").unwrap(); + } + home + }; + let gamma = make( + dir.join("java-runtime-gamma/linux/java-runtime-gamma"), + true, + ); + let epsilon = make( + dir.join( + "java-runtime-epsilon/mac-os-arm64/java-runtime-epsilon/jre.bundle/Contents/Home", + ), + true, + ); + make(dir.join("jre-legacy/linux/jre-legacy"), false); + assert_eq!(minecraft_runtimes(&dir), [epsilon, gamma]); + assert!(minecraft_runtimes(&dir.join("missing")).is_empty()); + fs::remove_dir_all(&dir).unwrap(); + } } diff --git a/crates/horizon-prepare/src/lib.rs b/crates/horizon-prepare/src/lib.rs index 66ff671f9..861db254d 100644 --- a/crates/horizon-prepare/src/lib.rs +++ b/crates/horizon-prepare/src/lib.rs @@ -74,6 +74,9 @@ pub struct Options { pub minecraft_dir: Option, /// The pinned server jar the player downloaded (`--server-jar`, else HORIZON_SERVER_JAR). pub server_jar: Option, + /// The JDK to try after JAVA_HOME and the PATH (the launcher's pick, e.g. Minecraft's + /// own Java it downloaded from Mojang). + pub java_home: Option, } pub(crate) fn hex(bytes: &[u8]) -> String { @@ -402,7 +405,11 @@ pub fn prepare(options: &Options, log: Log) -> Result { .map_err(|e| format!("{}: {e}", options.root.display()))?; let lock = artifacts::Lock::read(root)?; // Java first: nothing below can finish without it, and the player should hear it at once. - let jdk = java::find(lock.java_major)?; + let mut homes: Vec = options.java_home.iter().cloned().collect(); + homes.extend(java::minecraft_runtimes( + &artifacts::minecraft_dir(options.minecraft_dir.as_deref()).join("runtime"), + )); + let jdk = java::find(lock.java_major, &homes)?; if options.import && !artifacts::reuse_imported(root, log)? { artifacts::import( root, diff --git a/crates/horizon-prepare/src/main.rs b/crates/horizon-prepare/src/main.rs index 71b7a40cc..0d3a5685d 100644 --- a/crates/horizon-prepare/src/main.rs +++ b/crates/horizon-prepare/src/main.rs @@ -62,6 +62,7 @@ fn main() -> ExitCode { import: false, minecraft_dir: None, server_jar: None, + java_home: None, }; let mut root = None; let mut args = std::env::args_os().skip(1).peekable(); diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index ba854730f..7fce7ce07 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -993,6 +993,61 @@ fn download_for_owner( } } +/// The home of a JDK of at least `major`: one horizon-prepare finds (JAVA_HOME, the PATH, an +/// installed JDK) or the Java the official launcher downloaded into one of the `games` +/// folders, else Minecraft's own Java downloaded from Mojang into Horizon's game folder, the +/// runtime the version JSON at `manifest` names (Mojang's runtimes are whole JDKs). +fn java( + major: i64, + games: &[PathBuf], + manifest: &Path, + log: &dyn Fn(String), +) -> Result { + let runtimes = || -> Vec { + let mut homes: Vec = games + .iter() + .flat_map(|game| horizon_prepare::java::minecraft_runtimes(&game.join("runtime"))) + .collect(); + homes.dedup(); + homes + }; + let missing = match horizon_prepare::java::find(major, &runtimes()) { + Ok(jdk) => return Ok(jdk.home()), + Err(e) => e, + }; + let component = read_json(manifest) + .and_then(|json| json["javaVersion"]["component"].as_str().map(String::from)) + .ok_or_else(|| missing.clone())?; + let fetch = |url: &str| -> Result, String> { + let mut body = Vec::new(); + get(url)? + .into_reader() + .read_to_end(&mut body) + .map_err(|e| e.to_string())?; + Ok(body) + }; + let runtime = data_dir().join("minecraft").join("runtime"); + let home = mojang::java_runtime(&component, &runtime, 8, &fetch, log).map_err(|e| { + format!("{missing}\n • Horizon also tried to download Minecraft's own Java from Mojang, but: {e}") + })?; + horizon_prepare::java::find(major, &[home]).map(|jdk| jdk.home()) +} + +/// Runs `cmd` with the JDK at `home`: JAVA_HOME names it and its `bin` leads the PATH, as the +/// versions' own preparers look for Java. +fn with_java(cmd: &mut Command, home: &Path) { + let mut path = vec![home.join("bin")]; + path.extend( + std::env::var_os("PATH") + .iter() + .flat_map(std::env::split_paths), + ); + cmd.env("JAVA_HOME", home); + if let Ok(path) = std::env::join_paths(path) { + cmd.env("PATH", path); + } +} + /// Checks what the preparation needs and picks how to run it. PLAY.txt describes the same /// steps: the player's own launcher install, the server jar from that version's own json, and /// Java (and Python, for versions before horizon-prepare). Also returns the Minecraft folder @@ -1006,6 +1061,7 @@ pub fn preparer( let version = game_version(tag); let dir = version_dir(tag); let reused = horizon_prepare::artifacts::reuse_imported(&dir, &|line| log(line.to_string()))?; + let chosen = minecraft.to_path_buf(); let minecraft = if reused { minecraft.to_path_buf() } else { @@ -1042,25 +1098,27 @@ pub fn preparer( .join(&version) .join(format!("{version}.json")); let binary = preparer_binary(&dir); - let python = if binary.is_some() { - // The JDK the version pins, found as horizon-prepare finds it, so a missing one is - // reported before the server jar is downloaded. - let major = read_json(&dir.join("research-lock.json")) - .and_then(|lock| lock["minecraft"]["java_major"].as_i64()) - .ok_or("The version's research-lock.json has no java_major")?; - horizon_prepare::java::find(major)?; - None - } else { - let python = python() - .ok_or("This version prepares with Python: Python 3.10 or newer is needed. Install it, or pick a newer version.")?; - if !found("java", "-version") { - return Err( - "Java 25 is needed (a JDK, e.g. Eclipse Temurin 25). Install it and try again." - .into(), - ); - } - Some(python) + let python = match binary { + Some(_) => None, + None => Some(python().ok_or( + "This version prepares with Python: Python 3.10 or newer is needed. Install it, or pick a newer version.", + )?), }; + // The JDK the version pins, found as horizon-prepare finds it, so a missing one is + // reported (or downloaded) before the server jar is downloaded. Versions from before + // java_major ran Java 25. + let major = read_json(&dir.join("research-lock.json")) + .and_then(|lock| lock["minecraft"]["java_major"].as_i64()) + .unwrap_or(25); + let mut games = vec![chosen, minecraft.clone(), data_dir().join("minecraft")]; + games.extend( + sources::Folders::current() + .map(|f| sources::known_folders(sources::Os::current(), &f)) + .unwrap_or_default() + .into_iter() + .map(|(_, dir)| dir), + ); + let java_home = java(major, &games, &manifest, log)?; let jar = data_dir() .join("server-jars") .join(format!("{version}.jar")); @@ -1092,10 +1150,12 @@ pub fn preparer( import: !reused, minecraft_dir: Some(minecraft.clone()), server_jar: (!reused).then_some(jar), + java_home: Some(java_home), }; return Ok((Preparer::InProcess(options), minecraft)); } let mut cmd = Command::new(binary); + with_java(&mut cmd, &java_home); cmd.current_dir(&dir).arg("--root").arg(&dir); if !reused { cmd.args(["--prepare", "--server-jar"]).arg(&jar); @@ -1104,6 +1164,7 @@ pub fn preparer( return Ok((Preparer::Process(cmd), minecraft)); } let mut cmd = Command::new(python.unwrap()); + with_java(&mut cmd, &java_home); cmd.current_dir(&dir) .args(["-u", "tools/prepare_native_client.py"]); if !reused { diff --git a/launcher/src/mojang.rs b/launcher/src/mojang.rs index dbe2aa7fb..070db43aa 100644 --- a/launcher/src/mojang.rs +++ b/launcher/src/mojang.rs @@ -13,6 +13,8 @@ use std::sync::Mutex; use std::time::Duration; const OBJECTS: &str = "https://resources.download.minecraft.net"; +/// The index of Mojang's Java runtimes, the one the official launcher reads. +const JAVA_RUNTIMES: &str = "https://launchermeta.mojang.com/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json"; /// One file to download. struct File { @@ -84,6 +86,120 @@ pub fn download( Ok(()) } +/// Mojang's name for this system in its Java runtime index. +fn java_platform() -> Option<&'static str> { + Some(match (std::env::consts::OS, std::env::consts::ARCH) { + ("macos", "aarch64") => "mac-os-arm64", + ("macos", "x86_64") => "mac-os", + ("linux", "x86_64") => "linux", + ("linux", "x86") => "linux-i386", + ("windows", "x86_64") => "windows-x64", + ("windows", "aarch64") => "windows-arm64", + ("windows", "x86") => "windows-x86", + _ => return None, + }) +} + +/// Downloads Mojang's Java runtime `component` (the version JSON's `javaVersion.component`, e.g. +/// `java-runtime-epsilon`) into the game directory's `runtime` folder, as the official launcher +/// lays it out: `///`. Each file is checked against its sha1; +/// files already there and whole are kept. Mojang's runtimes are whole JDKs, javac included, +/// which is what the exporters need. +pub fn java_runtime( + component: &str, + runtime: &Path, + jobs: usize, + fetch: Fetch, + log: &dyn Fn(String), +) -> Result { + let platform = java_platform().ok_or("Mojang has no Java for this system")?; + let index: Value = serde_json::from_slice(&fetch(JAVA_RUNTIMES)?) + .map_err(|e| format!("Mojang's Java index: {e}"))?; + let entry = &index[platform][component][0]; + if entry.is_null() { + return Err(format!("Mojang has no {component} for {platform}")); + } + let manifest = &entry["manifest"]; + let manifest: Value = serde_json::from_slice(&fetch_checked( + fetch, + &text(manifest, "url")?, + &text(manifest, "sha1")?, + )?) + .map_err(|e| format!("Mojang's {component} manifest: {e}"))?; + let files = manifest["files"] + .as_object() + .ok_or_else(|| format!("Mojang's {component} manifest lists no files"))?; + let home = runtime.join(component).join(platform).join(component); + let mut downloads = Vec::new(); + let mut executables = Vec::new(); + let mut links = Vec::new(); + for (name, file) in files { + let path = home.join(relative(name)?); + match file["type"].as_str() { + Some("file") => { + let raw = &file["downloads"]["raw"]; + if file["executable"] == true { + executables.push(path.clone()); + } + downloads.push(File { + url: text(raw, "url")?, + sha1: text(raw, "sha1")?, + path, + }); + } + Some("link") => links.push((path, text(file, "target")?)), + _ => {} + } + } + let name = entry["version"]["name"].as_str().unwrap_or(component); + log(format!( + "Downloading Minecraft's Java {name} from Mojang ({} files)", + downloads.len() + )); + fetch_all(&downloads, jobs, fetch, log)?; + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + for path in &executables { + fs::set_permissions(path, fs::Permissions::from_mode(0o755)) + .map_err(|e| format!("{}: {e}", path.display()))?; + } + for (path, target) in &links { + if !link_stays_inside(name_in(&home, path), target) { + return Err(format!( + "Unsafe link {target:?} in Mojang's {component} manifest" + )); + } + let _ = fs::remove_file(path); + fs::create_dir_all(path.parent().unwrap()) + .and_then(|_| std::os::unix::fs::symlink(target, path)) + .map_err(|e| format!("{}: {e}", path.display()))?; + } + } + #[cfg(not(unix))] + let _ = (executables, links); + Ok(home) +} + +fn name_in<'a>(home: &Path, path: &'a Path) -> &'a Path { + path.strip_prefix(home).unwrap_or(path) +} + +/// Whether a link at `link` (relative to the runtime's home) pointing at `target` stays in the +/// home. +fn link_stays_inside(link: &Path, target: &str) -> bool { + let mut depth = link.components().count().saturating_sub(1); + for c in Path::new(target).components() { + match c { + Component::Normal(_) => depth += 1, + Component::CurDir => {} + Component::ParentDir if depth > 0 => depth -= 1, + _ => return false, + } + } + true +} + 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())) diff --git a/launcher/src/mojang_tests.rs b/launcher/src/mojang_tests.rs index b50a77a93..24ed80bca 100644 --- a/launcher/src/mojang_tests.rs +++ b/launcher/src/mojang_tests.rs @@ -230,3 +230,99 @@ fn version_file_paths_stay_in_the_folder() { assert!(relative(bad).is_err(), "{bad}"); } } + +#[test] +fn links_stay_inside_the_runtime() { + let at = |p: &str| PathBuf::from(p); + assert!(link_stays_inside( + &at("legal/java.compiler/LICENSE"), + "../java.base/LICENSE" + )); + assert!(link_stays_inside(&at("lib/a"), "b")); + assert!(!link_stays_inside(&at("lib/a"), "../../b")); + assert!(!link_stays_inside(&at("a"), "/etc/passwd")); +} + +#[cfg(all(target_os = "linux", target_arch = "x86_64"))] +#[test] +fn java_runtime_lays_out_mojangs_runtime_with_its_executables_and_links() { + const JAVAC: &[u8] = b"#!/bin/sh\necho javac 25.0.1\n"; + const LICENSE: &[u8] = b"a fake license"; + let manifest = serde_json::json!({"files": { + "bin": {"type": "directory"}, + "bin/javac": {"type": "file", "executable": true, "downloads": {"raw": + {"sha1": sha1_hex(JAVAC), "size": JAVAC.len(), "url": "https://piston-data.mojang.com/javac"}}}, + "legal/java.base/LICENSE": {"type": "file", "executable": false, "downloads": {"raw": + {"sha1": sha1_hex(LICENSE), "size": LICENSE.len(), "url": "https://piston-data.mojang.com/license"}}}, + "legal/java.compiler/LICENSE": {"type": "link", "target": "../java.base/LICENSE"}, + }}) + .to_string(); + let index = serde_json::json!({"linux": {"java-runtime-epsilon": [{ + "manifest": {"sha1": sha1_hex(manifest.as_bytes()), "url": "https://piston-meta.mojang.com/m.json"}, + "version": {"name": "25.0.1"}, + }]}}) + .to_string(); + let server = Server { + files: HashMap::from([ + (JAVA_RUNTIMES.to_string(), index.into_bytes()), + ( + "https://piston-meta.mojang.com/m.json".into(), + manifest.into_bytes(), + ), + ( + "https://piston-data.mojang.com/javac".into(), + JAVAC.to_vec(), + ), + ( + "https://piston-data.mojang.com/license".into(), + LICENSE.to_vec(), + ), + ]), + asked: Mutex::new(Vec::new()), + }; + let dir = scratch("java"); + let home = java_runtime( + "java-runtime-epsilon", + &dir, + 2, + &|url| server.fetch(url), + &|_| {}, + ) + .unwrap(); + assert_eq!( + home, + dir.join("java-runtime-epsilon/linux/java-runtime-epsilon") + ); + use std::os::unix::fs::PermissionsExt; + let mode = fs::metadata(home.join("bin/javac")) + .unwrap() + .permissions() + .mode(); + assert_eq!(mode & 0o111, 0o111); + assert_eq!( + fs::read(home.join("legal/java.compiler/LICENSE")).unwrap(), + LICENSE + ); + // horizon-prepare finds it where the official launcher would have put it. + assert_eq!(horizon_prepare::java::minecraft_runtimes(&dir), [home]); + // A second call keeps the files: only the index and manifest are asked again. + server.asked(); + java_runtime( + "java-runtime-epsilon", + &dir, + 2, + &|url| server.fetch(url), + &|_| {}, + ) + .unwrap(); + assert_eq!(server.asked().len(), 2); + assert!(java_runtime( + "java-runtime-zeta", + &dir, + 2, + &|url| server.fetch(url), + &|_| {} + ) + .is_err()); + fs::remove_dir_all(&dir).unwrap(); +} diff --git a/website/docs/install.md b/website/docs/install.md index b898d79de..8f0df0834 100644 --- a/website/docs/install.md +++ b/website/docs/install.md @@ -5,7 +5,7 @@ Download the launcher, let it install Horizon, then prepare the game from your o ## What you need - **Minecraft: Java Edition 26.3, played once.** Install it with the official Minecraft launcher (or Prism Launcher, MultiMC, the Modrinth App, ATLauncher or GDLauncher) and start 26.3 once, so it downloads its files. Horizon reads them from there and never copies them anywhere else. -- **Java 25, a JDK.** For example [Eclipse Temurin 25](https://adoptium.net/temurin/releases/?version=25). Only the one-time preparation uses it. The game itself needs no Java. +- **Java 25, a JDK**, for the one-time preparation only (the game itself needs no Java). Nothing to install: the launcher uses the Java the Minecraft launcher downloaded for 26.3, or downloads that same Java from Mojang. A JDK you installed yourself (for example [Eclipse Temurin 25](https://adoptium.net/temurin/releases/?version=25)) works too. - **A computer on the [supported list](/docs/#supported-systems).** On Linux and Windows that means a graphics card with Vulkan (or DirectX 12 on Windows). ## Download the launcher diff --git a/website/docs/troubleshooting.md b/website/docs/troubleshooting.md index b7dac8fe4..c62802186 100644 --- a/website/docs/troubleshooting.md +++ b/website/docs/troubleshooting.md @@ -30,7 +30,7 @@ The launcher's **Settings** page has a **Logs** row with an **Open** button. On - **The game does not start, or crashes straight away.** Update the launcher and Horizon, and your graphics drivers. On Windows, try **Graphics API: DirectX 12** (see [Settings](/docs/settings#graphics-api-on-windows)). - **"Not prepared" or "Minecraft 26.3 was not found".** Play 26.3 once in the official Minecraft launcher, or point the launcher at your Minecraft folder (**Choose…** next to Minecraft folder on the Play page), then choose **Prepare** again. -- **Preparation says Java 25 is needed.** Install a Java 25 JDK, for example Eclipse Temurin 25. +- **Preparation says Java 25 is needed.** Update the launcher: it then uses the Java the Minecraft launcher downloaded for 26.3, or downloads it from Mojang. If it still can't (no internet, say), install a Java 25 JDK, for example Eclipse Temurin 25. - **Slow or stuttering.** Lower the render distance, turn LOD off, or pick the **Performance** preset. The performance overlay (Video, Advanced, Overlay) shows what is slow. - **A resource or shader pack broke something.** Switch it off, or take it out of its folder. From 92d2e2b86daee54096cde44bc404c528e5e7af77 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 22 Oct 2026 16:20:42 +0200 Subject: [PATCH 2/2] launcher: leave Java alone when the preparer finds one itself With a JDK installed, the launcher passed the preparation the home of the JDK horizon-prepare finds (javac/../..) as JAVA_HOME and on the PATH. Found through the PATH, that is often a stub: on macOS /usr/bin/javac gives JAVA_HOME=/usr, and `JAVA_HOME=/usr /usr/bin/javac -version` never returns (the stub calls itself), so the preparer subprocess hung on a Mac with Temurin installed. When horizon-prepare finds a JDK by itself, run the preparation as before, in an unchanged environment; only Minecraft's own Java (the official launcher's, or one downloaded from Mojang) is passed on. Also skip the Mojang download on x86-64 Linux without glibc's loader (NixOS without nix-ld, musl distributions): Mojang's Java can't start there, so say so instead of downloading 115 MB first. And keep each runtime home once (dedup only dropped neighbours). Co-Authored-By: Claude Opus 5.5 --- launcher/src/backend.rs | 59 ++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/launcher/src/backend.rs b/launcher/src/backend.rs index 7fce7ce07..51ee81c5c 100644 --- a/launcher/src/backend.rs +++ b/launcher/src/backend.rs @@ -993,31 +993,45 @@ fn download_for_owner( } } -/// The home of a JDK of at least `major`: one horizon-prepare finds (JAVA_HOME, the PATH, an -/// installed JDK) or the Java the official launcher downloaded into one of the `games` -/// folders, else Minecraft's own Java downloaded from Mojang into Horizon's game folder, the -/// runtime the version JSON at `manifest` names (Mojang's runtimes are whole JDKs). +/// A JDK of at least `major` for the preparation. `None` when horizon-prepare finds one by +/// itself (JAVA_HOME, the PATH, an installed JDK): the preparation then runs as before, in an +/// unchanged environment (a JDK found on the PATH can be a stub such as macOS's +/// /usr/bin/javac, whose folder is no Java home: `JAVA_HOME=/usr` makes it call itself +/// forever). Else the home of the Java the official launcher downloaded into one of the +/// `games` folders, else of Minecraft's own Java downloaded from Mojang into Horizon's game +/// folder, the runtime the version JSON at `manifest` names (Mojang's runtimes are whole JDKs). fn java( major: i64, games: &[PathBuf], manifest: &Path, log: &dyn Fn(String), -) -> Result { - let runtimes = || -> Vec { - let mut homes: Vec = games - .iter() - .flat_map(|game| horizon_prepare::java::minecraft_runtimes(&game.join("runtime"))) - .collect(); - homes.dedup(); - homes - }; - let missing = match horizon_prepare::java::find(major, &runtimes()) { - Ok(jdk) => return Ok(jdk.home()), +) -> Result, String> { + if horizon_prepare::java::find(major, &[]).is_ok() { + return Ok(None); + } + let mut runtimes: Vec = Vec::new(); + for home in games + .iter() + .flat_map(|game| horizon_prepare::java::minecraft_runtimes(&game.join("runtime"))) + { + if !runtimes.contains(&home) { + runtimes.push(home); + } + } + let missing = match horizon_prepare::java::find(major, &runtimes) { + Ok(jdk) => return Ok(Some(jdk.home())), Err(e) => e, }; let component = read_json(manifest) .and_then(|json| json["javaVersion"]["component"].as_str().map(String::from)) .ok_or_else(|| missing.clone())?; + // Mojang builds its Linux Java for glibc: without glibc's loader (NixOS without nix-ld, + // musl distributions) it cannot start, so don't download it. + if cfg!(all(target_os = "linux", target_arch = "x86_64")) && !Path::new(GLIBC_LOADER).exists() { + return Err(format!( + "{missing}\n • Minecraft's own Java from Mojang needs glibc ({GLIBC_LOADER} is missing; on NixOS, enable programs.nix-ld), so install a JDK instead." + )); + } let fetch = |url: &str| -> Result, String> { let mut body = Vec::new(); get(url)? @@ -1030,9 +1044,12 @@ fn java( let home = mojang::java_runtime(&component, &runtime, 8, &fetch, log).map_err(|e| { format!("{missing}\n • Horizon also tried to download Minecraft's own Java from Mojang, but: {e}") })?; - horizon_prepare::java::find(major, &[home]).map(|jdk| jdk.home()) + horizon_prepare::java::find(major, &[home]).map(|jdk| Some(jdk.home())) } +/// The dynamic loader glibc programs on x86-64 Linux start through. +const GLIBC_LOADER: &str = "/lib64/ld-linux-x86-64.so.2"; + /// Runs `cmd` with the JDK at `home`: JAVA_HOME names it and its `bin` leads the PATH, as the /// versions' own preparers look for Java. fn with_java(cmd: &mut Command, home: &Path) { @@ -1150,12 +1167,14 @@ pub fn preparer( import: !reused, minecraft_dir: Some(minecraft.clone()), server_jar: (!reused).then_some(jar), - java_home: Some(java_home), + java_home: java_home.clone(), }; return Ok((Preparer::InProcess(options), minecraft)); } let mut cmd = Command::new(binary); - with_java(&mut cmd, &java_home); + if let Some(home) = &java_home { + with_java(&mut cmd, home); + } cmd.current_dir(&dir).arg("--root").arg(&dir); if !reused { cmd.args(["--prepare", "--server-jar"]).arg(&jar); @@ -1164,7 +1183,9 @@ pub fn preparer( return Ok((Preparer::Process(cmd), minecraft)); } let mut cmd = Command::new(python.unwrap()); - with_java(&mut cmd, &java_home); + if let Some(home) = &java_home { + with_java(&mut cmd, home); + } cmd.current_dir(&dir) .args(["-u", "tools/prepare_native_client.py"]); if !reused {