From 35305605819cece46b2c53bdc94cc9de5151bd80 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 22 Oct 2026 17:28:12 +0200 Subject: [PATCH] Launcher: Java mods in the mod browser, checked before install; Modpacks moves into Mods The Mods page gets a Mods tab: Fabric, NeoForge, Forge and Quilt mods for 26.3 (1.21 and later with Show everything). Each result's jar is downloaded (allowed CDNs, checksum), checked with horizon-port-pack (Works, Partly, Doesn't run, with what ports and what doesn't) and the answer cached per file. Install copies the carry into horizon-mods// and turns it on in horizon-mods.txt, with required mods that port; libraries with nothing to port are listed as not ported; id or namespace clashes are refused. Remove deletes it and turns it off. The Modpacks page becomes the Mods page's Modpacks tab: imported packs first, then the search. CLI: mods search --kind mod, mods check . Co-Authored-By: Claude Opus 5.5 --- docs/mod-browser.md | 59 +++- launcher/src/browser.rs | 70 ++++- launcher/src/browser/curseforge.rs | 3 +- launcher/src/browser/installed.rs | 43 ++- launcher/src/browser/installed/tests.rs | 2 +- launcher/src/browser/java.rs | 340 ++++++++++++++++++++++++ launcher/src/browser/modrinth.rs | 10 + launcher/src/browser/tests.rs | 55 +++- launcher/src/cli.rs | 70 ++++- launcher/src/main.rs | 5 +- launcher/src/modpacks_page.rs | 33 +-- launcher/src/mods_page.rs | 139 +++++++++- website/docs/modpacks.md | 2 +- website/docs/mods.md | 12 +- 14 files changed, 760 insertions(+), 83 deletions(-) create mode 100644 launcher/src/browser/java.rs diff --git a/docs/mod-browser.md b/docs/mod-browser.md index 115877075..bc7a80b16 100644 --- a/docs/mod-browser.md +++ b/docs/mod-browser.md @@ -1,25 +1,56 @@ # The launcher's mod browser -Search Modrinth (and CurseForge, once the launcher has a key) for packs Horizon loads, see how well each one runs, -and install it with its checksum checked. This is item 16 of the roadmap and issue #577. The code is in +Search Modrinth (and CurseForge, once the launcher has a key) for Java mods, modpacks, resource packs and shader +packs, see how well each one runs before installing it, and install it with its checksum checked. This is item 16 of the roadmap and issue #577. The code is in `launcher/src/browser.rs` and `launcher/src/browser/`. ## What it offers -Only what Horizon actually loads is offered. Java mod jars (Fabric, NeoForge, Forge) don't run in Horizon -([mods.md](mods.md), [research/java-mod-compat.md](research/java-mod-compat.md)), so they are never searched. -Horizon `.hmod` mods aren't on Modrinth or CurseForge yet (Modrinth has no `horizon` loader). +Horizon doesn't run Java code ([research/java-mod-compat.md](research/java-mod-compat.md)). It ports what a Java mod +carries as data (blocks, items, recipes, loot tables, tags, worldgen, textures, names) with `horizon-port-pack`, and +says before install which of the mod's features that leaves out. Horizon `.hmod` mods aren't on Modrinth or CurseForge +yet (Modrinth has no `horizon` loader). | Kind | Goes to | How well it runs | |---|---|---| +| Java mods (Fabric, NeoForge, Forge, Quilt) | ported into `horizon-mods//` and turned on | Checked from its jar before install: **Works**, **Partly** or **Doesn't run** ([below](#java-mods)) | | Resource packs | `resourcepacks/` beside `options.txt` | **Works** when made for 26.3 ([resource-packs.md](resource-packs.md) lists what Horizon reads). Older packs are **Partly**: they load with vanilla's compatibility warning | | Shader packs (Iris, OptiFine) | `shaderpacks/` | **Partly**: translated to WGSL, the full-screen passes draw and the world and shadow passes don't yet ([shader-packs.md](shader-packs.md)). Packs for other loaders (Canvas, core-shader packs) **don't run** and can't be installed | | Modpacks (`.mrpack`, CurseForge zip) | the Modpacks page's import | **Partly**: Horizon runs the mods it can port, from the player's own downloads ([modpacks.md](modpacks.md)) | -By default a search shows only what runs: resource packs made for 26.3, shader packs for Iris or OptiFine, and every -modpack. **Show everything** lists the rest of the kind too, each marked with how well it runs; what doesn't run is +By default a search shows only what runs: Java mods made for 26.3, resource packs made for 26.3, shader packs for Iris +or OptiFine, and every modpack. **Show everything** lists the rest of the kind too, each marked with how well it runs; what doesn't run is never offered for install. +## Java mods + +Before a mod is offered for install, the launcher reads its jar. For each result it picks the version it would +install (the newest for 26.3; with **Show everything**, else the newest for 1.21 or later, the versions port-pack +upgrades from), downloads that file with the checks below, and runs `horizon-port-pack check` on it +([modpacks.md](modpacks.md#the-pipeline-horizon-port-pack)): the jar is carried over into a folder content mod and its +class files are read, not run, for what the carry can't take. Two checks run at once; the row says **Checking** until +its answer comes. + +- **Works**: content only. Its blocks, items, recipes, loot, tags and worldgen port, and its code only registers + them. Blocks take the closest vanilla block's shape, hardness and sounds (a block's numbers live in Java code; the + NeoForge oracle that reads them for modpacks is a developer tool). +- **Partly**: the content ports; the row lists what doesn't: blocks with no vanilla block to copy, recipes of the + mod's own types, block entities (machines, containers), menus, mobs and entities, blocks and items with behaviour + of their own, worldgen written in Java, Mixins, the game events it reacts to. +- **Doesn't run**: nothing to port (performance mods, libraries, everything in code), a jar made for 1.20 or older, + or a mod id with characters Horizon mods can't use (`fabric-api`). Never offered for install. + +The answer is kept in `mod-browser/checks-1//` under the game folder, with the carry when something +ports; the jar itself isn't kept. A file is checked once. On ten 26.3 jars a check took 0.2 to 3 s (24 s for an +18 MB jar with 9,360 recipes). + +**Install** copies the carry into `horizon-mods//`, turns it on in `horizon-mods.txt` (the game's Options > +Mods lists it) and records it in `mod-browser.json` with its verdict and what didn't port, which the Installed list +shows. Its required mods that port are installed with it; one with nothing to port (a library such as Cloth Config +or GeckoLib) is listed as not ported. A mod that shares its id or a namespace with an installed one is refused. The +game reads mod content when it starts: start it again after installing. **Remove** deletes the folder and turns it +off. + ## Checks on every download - The file must come from Modrinth's or CurseForge's file servers (`cdn.modrinth.com`, `edge.forgecdn.net`, @@ -32,10 +63,11 @@ never offered for install. ## The Mods page -The launcher's **Mods** page has the three kinds as tabs, a search field (Enter searches), **Show everything** and, +The launcher's **Mods** page has the four kinds as tabs (Mods, Modpacks, Resource packs, Shader packs), a search field (Enter searches), **Show everything** and, once CurseForge is set up, a Modrinth / CurseForge switch. Each result is an index row: its summary, author, downloads, source and licence, how well it runs (and why), **Page** (the project's page on its source) and -**Install** (**Import** for a modpack). Installed packs are listed above the results with their version, source, +**Install** (**Import** for a modpack). The Modpacks tab lists the imported packs first, with their coverage +report, **Port** and **Play** ([modpacks.md](modpacks.md)). Installed packs are listed above the results with their version, source, file and the checksum they were checked against, with **Update to …** when a newer version runs and **Remove** (asked twice). @@ -51,14 +83,15 @@ same name the player put there is never overwritten. Packs, as in vanilla and Iris. - **Update** installs the newer version and removes the old file. - **Remove** deletes the file and its entry. Packs installed as dependencies stay. -- **A modpack** is downloaded (checked the same way) into `ports/downloads/` and imported on the Modpacks page, - which says what of it Horizon runs and ports it. +- **A modpack** is downloaded (checked the same way) into `ports/downloads/` and imported; the Modpacks tab says + what of it Horizon runs and ports it. From a terminal (or an agent): ```sh -horizon-launcher mods search faithful # --kind resource|shader|modpack, --everything, --source -horizon-launcher mods install faithful-32x # id or slug; a modpack is imported +horizon-launcher mods search faithful # --kind mod|modpack|resource|shader, --everything, --source +horizon-launcher mods check macaws-fences-and-walls # a Java mod's verdict, what ports and what doesn't (--json) +horizon-launcher mods install faithful-32x # id or slug; a Java mod is ported, a modpack imported horizon-launcher mods list # --json horizon-launcher mods update [faithful-32x] [--check] horizon-launcher mods remove faithful-32x diff --git a/launcher/src/browser.rs b/launcher/src/browser.rs index 49ec1e696..b8248fd7c 100644 --- a/launcher/src/browser.rs +++ b/launcher/src/browser.rs @@ -2,12 +2,14 @@ //! Horizon loads, say how well each result runs, and download a file only after its checksum //! matches (docs/mod-browser.md). //! -//! Only what Horizon actually loads is offered: resource packs (`resourcepacks/`), Java shader -//! packs (`shaderpacks/`, Iris and OptiFine) and modpacks (imported and ported on the Modpacks -//! page). Java mod jars don't run in Horizon (docs/mods.md), so they are never searched. +//! Offered: Java mods (Fabric, NeoForge, Forge), whose content Horizon ports and whose jar is +//! checked before install ([`java`]), modpacks (imported and ported), resource packs +//! (`resourcepacks/`) and Java shader packs (`shaderpacks/`, Iris and OptiFine). Java code itself +//! doesn't run in Horizon (docs/mods.md). pub mod curseforge; pub mod download; pub mod installed; +pub mod java; pub mod modrinth; use serde::{Deserialize, Serialize}; @@ -23,25 +25,34 @@ pub enum Kind { ResourcePack, ShaderPack, Modpack, + /// A Java mod: its content is ported ([`java`]). + Mod, } impl Kind { - pub const ALL: [Kind; 3] = [Kind::ResourcePack, Kind::ShaderPack, Kind::Modpack]; + pub const ALL: [Kind; 4] = [ + Kind::Mod, + Kind::Modpack, + Kind::ResourcePack, + Kind::ShaderPack, + ]; pub fn label(self) -> &'static str { match self { + Kind::Mod => "Mods", Kind::ResourcePack => "Resource packs", Kind::ShaderPack => "Shader packs", Kind::Modpack => "Modpacks", } } - /// The folder beside `options.txt` the file goes in; a modpack is imported instead. + /// The folder beside `options.txt` the file goes in; a modpack is imported and a mod + /// ported instead. pub fn folder(self) -> Option<&'static str> { match self { Kind::ResourcePack => Some("resourcepacks"), Kind::ShaderPack => Some("shaderpacks"), - Kind::Modpack => None, + Kind::Modpack | Kind::Mod => None, } } } @@ -256,11 +267,34 @@ pub fn support(kind: Kind, game_versions: &[String], loaders: &[String]) -> Supp )) } } - Kind::Modpack => Support::Partial( - "Imported on the Modpacks page: Horizon runs the mods it can port, from your own \ - downloads." - .into(), - ), + Kind::Modpack => { + Support::Partial("Horizon runs the mods it can port, from your own downloads.".into()) + } + Kind::Mod => { + if !loaders.iter().any(|l| java::LOADERS.contains(&l.as_str())) { + Support::No("Not a Fabric, NeoForge or Forge mod.".into()) + } else if !game_versions.iter().any(|v| portable_version(v)) { + let newest = newest_release(game_versions).unwrap_or("an unknown version"); + Support::No(format!( + "Made for {newest}: Horizon ports mods made for 1.21 and later." + )) + } else { + Support::Partial( + "Not checked yet: the launcher reads its jar to say what of it ports.".into(), + ) + } + } + } +} + +/// A Minecraft version whose mods port-pack carries over: 1.21 and later (the data folders +/// took their current names in 1.21). +pub fn portable_version(v: &str) -> bool { + let parts: Vec = v.split('.').map_while(|p| p.parse().ok()).collect(); + match parts.as_slice() { + [1, minor, ..] => *minor >= 21 && v.split('.').count() == parts.len(), + [year, ..] => *year >= 26 && v.split('.').count() == parts.len(), + [] => false, } } @@ -286,6 +320,20 @@ pub fn pick(kind: Kind, versions: &[Version], everything: bool) -> Option<&Versi let mut usable = versions .iter() .filter(|v| v.blocked.is_none() && v.file().is_some()); + if kind == Kind::Mod { + let java = |v: &&Version| { + v.loaders + .iter() + .any(|l| java::LOADERS.contains(&l.as_str())) + }; + let made_for = |v: &&Version| v.game_versions.iter().any(|g| g == GAME); + let ported = |v: &&Version| v.game_versions.iter().any(|g| portable_version(g)); + return usable + .clone() + .filter(java) + .find(made_for) + .or_else(|| usable.filter(java).find(|v| everything && ported(v))); + } let runs = |v: &&Version| match support(kind, &v.game_versions, &v.loaders) { Support::Works => true, // A modpack's version is for its own Minecraft; any shader pack Horizon translates. diff --git a/launcher/src/browser/curseforge.rs b/launcher/src/browser/curseforge.rs index 347cf0d40..04e722bba 100644 --- a/launcher/src/browser/curseforge.rs +++ b/launcher/src/browser/curseforge.rs @@ -24,6 +24,7 @@ fn class(kind: Kind) -> u64 { Kind::ResourcePack => 12, Kind::ShaderPack => 6552, Kind::Modpack => 4471, + Kind::Mod => 6, } } @@ -73,7 +74,7 @@ pub(super) fn search_url(query: &Query) -> String { query.offset, query.limit.clamp(1, 50), ); - if !query.everything && query.kind == Kind::ResourcePack { + if !query.everything && matches!(query.kind, Kind::ResourcePack | Kind::Mod) { url.push_str(&format!("&gameVersion={GAME}")); } if !query.text.is_empty() { diff --git a/launcher/src/browser/installed.rs b/launcher/src/browser/installed.rs index d1aac1af5..1ed9b3cf8 100644 --- a/launcher/src/browser/installed.rs +++ b/launcher/src/browser/installed.rs @@ -1,7 +1,8 @@ //! What the browser installed into the game folder, and installing, updating and removing it. //! //! `mod-browser.json` beside `options.txt` lists each file the browser put in `resourcepacks/` -//! or `shaderpacks/`: where it came from, its version and its checksum. Files the player put +//! or `shaderpacks/`, and each Java mod it ported into `horizon-mods/`: where it came from, its +//! version and its checksum. Files the player put //! there themselves are never touched: the browser only replaces or removes what it lists. use super::{pick, safe_name, Kind, Project, Source, SourceId, Support, Version}; use serde::{Deserialize, Serialize}; @@ -29,6 +30,15 @@ pub struct Entry { /// Installed because another pack needs it. #[serde(default)] pub dependency: bool, + /// A Java mod's verdict when it was installed: `Works` or `Partly`. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub verdict: Option, + /// What of a Java mod didn't port. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub skipped: Vec, + /// A Java mod's namespaces: two installed mods never share one. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub namespaces: Vec, } #[derive(Debug, Default, Serialize, Deserialize)] @@ -78,9 +88,15 @@ pub struct Step { /// What installing `project` takes, dependencies first, checked before any byte is downloaded: /// every file runs in Horizon and has a version to install. pub fn plan(source: &dyn Source, project: &Project, everything: bool) -> Result, String> { + if project.kind == Kind::Modpack { + return Err(format!( + "{} is a modpack: it is imported, not installed.", + project.title + )); + } if project.kind.folder().is_none() { return Err(format!( - "{} is a modpack: it is imported on the Modpacks page.", + "{} is ported, not installed as a file.", project.title )); } @@ -122,10 +138,7 @@ fn add( ) })?; if needed.kind.folder().is_none() { - return Err(format!( - "{} needs the modpack {}.", - project.title, needed.title - )); + return Err(format!("{} needs {}.", project.title, needed.title)); } add(source, needed, everything, true, depth + 1, steps)?; } @@ -146,6 +159,9 @@ pub fn install( home: &Path, progress: &dyn Fn(&str, f32), ) -> Result, String> { + if project.kind == Kind::Mod { + return super::java::install(source, project, everything, home, progress); + } let steps = plan(source, project, everything)?; let mut installed = Installed::load(home); let mut done = Vec::new(); @@ -199,6 +215,9 @@ pub fn install( page: p.page.clone(), // Asked for by the player once: it stays theirs. dependency: step.dependency && old.as_ref().is_none_or(|o| o.dependency), + verdict: None, + skipped: Vec::new(), + namespaces: Vec::new(), }; debug_assert!(path.ends_with(name)); installed @@ -218,10 +237,14 @@ pub fn remove(home: &Path, name: &str) -> Result { .lookup(name) .cloned() .ok_or_else(|| format!("{name} wasn't installed by the browser."))?; - match fs::remove_file(home.join(&entry.file)) { - Ok(()) => {} - Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} - Err(e) => return Err(format!("{}: {e}", entry.file)), + if entry.kind == Kind::Mod { + super::java::remove(home, &entry)?; + } else { + match fs::remove_file(home.join(&entry.file)) { + Ok(()) => {} + Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} + Err(e) => return Err(format!("{}: {e}", entry.file)), + } } installed .entries diff --git a/launcher/src/browser/installed/tests.rs b/launcher/src/browser/installed/tests.rs index 33dc525ab..af55ec78d 100644 --- a/launcher/src/browser/installed/tests.rs +++ b/launcher/src/browser/installed/tests.rs @@ -227,7 +227,7 @@ fn nothing_is_installed_when_a_check_fails() { let pack = project("pack", Kind::Modpack); assert!(plan(&fake, &pack, false) .unwrap_err() - .contains("Modpacks page")); + .contains("imported, not installed")); fs::remove_dir_all(&home).unwrap(); } diff --git a/launcher/src/browser/java.rs b/launcher/src/browser/java.rs new file mode 100644 index 000000000..76ce43c95 --- /dev/null +++ b/launcher/src/browser/java.rs @@ -0,0 +1,340 @@ +//! Java mods (Fabric, NeoForge, Forge) from the browser (docs/mod-browser.md). Horizon doesn't +//! run their code; it ports what they carry (blocks, items, recipes, loot, tags, worldgen) with +//! `horizon-port-pack`. Before a mod is offered for install its jar is downloaded (checked as +//! every download is), carried over and its classes read (`horizon_port_pack::check`): the +//! verdict (Works, Partly, Doesn't run) and the lists of what ports and what doesn't come from +//! that, and are kept per file so a jar is checked once. +//! +//! Installing copies the carried-over folder mod into `horizon-mods//` beside +//! `options.txt` and turns it on in `horizon-mods.txt`, where the game's Options > Mods reads it. +use super::{installed::Entry, pick, FileRef, Kind, Project, Source, Support, Version}; +use horizon_port_pack::check::{self, Check, Verdict}; +use std::fs; +use std::path::{Path, PathBuf}; + +/// Where the checks are kept, under the game folder. Its name changes when the check finds +/// more, so older answers are checked again. +const CHECKS: &str = "mod-browser/checks-1"; +/// The game's mod folder and on-list, beside `options.txt` (`horizon_client::mod_list`). +pub const MODS_DIR: &str = "horizon-mods"; +const MODS_LIST: &str = "horizon-mods.txt"; +/// How deep required mods are followed. +const MAX_DEPTH: usize = 3; + +/// The loaders whose jars port-pack reads. +pub const LOADERS: [&str; 4] = ["neoforge", "fabric", "forge", "quilt"]; + +/// How well a checked mod runs. +pub fn support_of(check: &Check) -> Support { + match check.verdict { + Verdict::Works => Support::Works, + Verdict::Partly => Support::Partial(check.summary.clone()), + Verdict::No => Support::No(check.summary.clone()), + } +} + +fn checks(home: &Path) -> PathBuf { + home.join(CHECKS) +} + +/// The folder a file's check is kept in, by its checksum. +fn checked_dir(home: &Path, file: &FileRef) -> Option { + let (_, hash) = file.checksum()?; + let hash: String = hash + .chars() + .filter(char::is_ascii_hexdigit) + .take(40) + .collect(); + (hash.len() >= 32).then(|| checks(home).join(hash)) +} + +fn read_check(dir: &Path) -> Option { + serde_json::from_str(&fs::read_to_string(dir.join("check.json")).ok()?).ok() +} + +/// The check of `file` if it was made before. +pub fn cached(home: &Path, file: &FileRef) -> Option { + read_check(&checked_dir(home, file)?) +} + +/// Checks `file`: the cached answer, else its jar downloaded, carried over and read. The jar +/// itself isn't kept; the carry is, when something of it ports, for the install to copy. +pub fn check_file( + home: &Path, + source: &dyn Source, + file: &FileRef, + progress: &dyn Fn(f32), +) -> Result { + let dir = checked_dir(home, file).ok_or("Its source gives no checksum.")?; + if let Some(c) = read_check(&dir) { + return Ok(c); + } + let jar = source.fetch(file, &checks(home).join(".downloads"), progress)?; + let part = dir.with_extension("part"); + let _ = fs::remove_dir_all(&part); + let result = check::check(&jar, &part); + let _ = fs::remove_file(&jar); + let c = result.inspect_err(|_| { + let _ = fs::remove_dir_all(&part); + })?; + if c.verdict == Verdict::No { + for d in ["carry", "outside"] { + let _ = fs::remove_dir_all(part.join(d)); + } + } + let _ = fs::remove_dir_all(&dir); + fs::rename(&part, &dir).map_err(|e| format!("{}: {e}", dir.display()))?; + Ok(c) +} + +/// The version of `project` to install and its check. +pub fn check_project( + home: &Path, + source: &dyn Source, + project: &Project, + everything: bool, + progress: &dyn Fn(f32), +) -> Result<(Version, Check), String> { + let versions = source.versions(project)?; + let version = pick(Kind::Mod, &versions, everything) + .cloned() + .ok_or_else(|| match versions.iter().find_map(|v| v.blocked.clone()) { + Some(why) => format!("{} can't be downloaded from here: {why}", project.title), + None => format!( + "{} has no Fabric, NeoForge or Forge version Horizon can port.", + project.title + ), + })?; + let file = version.file().expect("pick keeps versions with a file"); + let check = check_file(home, source, file, progress)?; + Ok((version, check)) +} + +/// Turns mod `id` on (or off) in `horizon-mods.txt`, keeping the other lines. +pub fn set_enabled(home: &Path, id: &str, on: bool) -> Result<(), String> { + let path = home.join(MODS_LIST); + let text = fs::read_to_string(&path).unwrap_or_default(); + let key = format!("mod.{id}"); + let mut lines: Vec = text + .lines() + .filter(|l| l.split_once(':').is_none_or(|(k, _)| k.trim() != key)) + .map(str::to_owned) + .collect(); + if on { + lines.push(format!("{key}:true")); + } + let mut out = lines.join("\n"); + if !out.is_empty() { + out.push('\n'); + } + fs::write(&path, out).map_err(|e| format!("{}: {e}", path.display())) +} + +fn copy_dir(from: &Path, to: &Path) -> Result<(), String> { + fs::create_dir_all(to).map_err(|e| format!("{}: {e}", to.display()))?; + for entry in fs::read_dir(from).map_err(|e| format!("{}: {e}", from.display()))? { + let entry = entry.map_err(|e| e.to_string())?; + let (src, dst) = (entry.path(), to.join(entry.file_name())); + if entry.file_type().map_err(|e| e.to_string())?.is_dir() { + copy_dir(&src, &dst)?; + } else { + fs::copy(&src, &dst).map_err(|e| format!("{}: {e}", dst.display()))?; + } + } + Ok(()) +} + +/// Installs the Java mod `project`: checked, carried over into `horizon-mods//` and turned +/// on, with the mods it requires that port too. A required mod with nothing to port (a library) +/// is listed in what was skipped. Returns the entries installed, the asked-for one last. +pub fn install( + source: &dyn Source, + project: &Project, + everything: bool, + home: &Path, + progress: &dyn Fn(&str, f32), +) -> Result, String> { + let job = Job { + source, + everything, + home, + progress, + }; + let mut done = Vec::new(); + job.add(project, false, 0, &mut done)?; + Ok(done) +} + +/// One install: where from, where to, and how it reports. +struct Job<'a> { + source: &'a dyn Source, + everything: bool, + home: &'a Path, + progress: &'a dyn Fn(&str, f32), +} + +impl Job<'_> { + fn add( + &self, + project: &Project, + dependency: bool, + depth: usize, + done: &mut Vec, + ) -> Result<(), String> { + let Job { + source, + everything, + home, + progress, + } = *self; + if done.iter().any(|e| e.project == project.id) { + return Ok(()); + } + let (version, check) = check_project(home, source, project, everything, &|f| { + progress(&format!("Checking {}", project.title), f) + })?; + if check.verdict == Verdict::No { + return Err(format!( + "{} doesn't run in Horizon: {}", + project.title, check.summary + )); + } + let mut skipped = check.skipped.clone(); + for id in &version.required { + let Ok(needed) = source.project(id) else { + continue; + }; + if needed.kind != Kind::Mod || depth >= MAX_DEPTH { + continue; + } + match self.add(&needed, true, depth + 1, done) { + Ok(()) => {} + Err(_) if dependency => {} + Err(why) => skipped.push(format!("needs {}: {why}", needed.title)), + } + } + let file = version.file().expect("pick keeps versions with a file"); + let carry = checked_dir(home, file) + .expect("checked above") + .join("carry"); + let relative = format!("{MODS_DIR}/{}", check.mod_id); + let mut installed = super::installed::Installed::load(home); + let ours = |e: &Entry| e.source == project.source && e.project == project.id; + if let Some(other) = installed.entries.iter().find(|e| { + e.kind == Kind::Mod + && !ours(e) + && (e.file == relative || e.namespaces.iter().any(|n| check.namespaces.contains(n))) + }) { + return Err(format!( + "{} shares its id or namespace with {}, installed already: remove one first.", + project.title, other.title + )); + } + let target = home.join(&relative); + let old = installed.entries.iter().find(|e| ours(e)).cloned(); + if target.exists() && old.as_ref().is_none_or(|o| o.file != relative) { + return Err(format!( + "{relative} is already there and wasn't installed by the browser: move it away first." + )); + } + progress(&format!("Installing {}", project.title), 1.); + let part = home.join(MODS_DIR).join(format!(".{}.part", check.mod_id)); + let _ = fs::remove_dir_all(&part); + copy_dir(&carry, &part).inspect_err(|_| { + let _ = fs::remove_dir_all(&part); + })?; + if let Some(old) = &old { + let _ = fs::remove_dir_all(home.join(&old.file)); + if old.file != relative { + let _ = set_enabled(home, old.file.trim_start_matches("horizon-mods/"), false); + } + } + fs::rename(&part, &target).map_err(|e| format!("{}: {e}", target.display()))?; + set_enabled(home, &check.mod_id, true)?; + let (algo, hash) = file.checksum().expect("checked files have one"); + let entry = Entry { + source: project.source, + project: project.id.clone(), + slug: project.slug.clone(), + title: project.title.clone(), + kind: Kind::Mod, + version: version.id.clone(), + number: version.number.clone(), + file: relative, + checksum: format!("{algo}:{hash}"), + page: project.page.clone(), + dependency: dependency && old.as_ref().is_none_or(|o| o.dependency), + verdict: Some(check.verdict.label().to_owned()), + skipped, + namespaces: check.namespaces.clone(), + }; + installed.entries.retain(|e| !ours(e)); + installed.entries.push(entry.clone()); + installed.save(home)?; + done.push(entry); + Ok(()) + } +} + +/// Removes an installed mod's folder and turns it off. +pub fn remove(home: &Path, entry: &Entry) -> Result<(), String> { + let Some(id) = entry.file.strip_prefix("horizon-mods/") else { + return Err(format!("{} isn't in {MODS_DIR}/.", entry.file)); + }; + match fs::remove_dir_all(home.join(&entry.file)) { + Ok(()) => {} + Err(e) if e.kind() == std::io::ErrorKind::NotFound => {} + Err(e) => return Err(format!("{}: {e}", entry.file)), + } + set_enabled(home, id, false) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_on_list_keeps_other_lines() { + let home = std::env::temp_dir().join(format!("horizon-java-mods-{}", std::process::id())); + let _ = fs::remove_dir_all(&home); + fs::create_dir_all(&home).unwrap(); + fs::write( + home.join(MODS_LIST), + "mod.coords_hud:true\nmod.ruby:false\n", + ) + .unwrap(); + set_enabled(&home, "ruby", true).unwrap(); + set_enabled(&home, "gem", true).unwrap(); + assert_eq!( + fs::read_to_string(home.join(MODS_LIST)).unwrap(), + "mod.coords_hud:true\nmod.ruby:true\nmod.gem:true\n" + ); + set_enabled(&home, "ruby", false).unwrap(); + set_enabled(&home, "gem", false).unwrap(); + assert_eq!( + fs::read_to_string(home.join(MODS_LIST)).unwrap(), + "mod.coords_hud:true\n" + ); + fs::remove_dir_all(&home).unwrap(); + } + + #[test] + fn checks_are_kept_by_checksum() { + let home = Path::new("/h"); + let file = |sha512: Option<&str>, sha1: Option<&str>| FileRef { + url: String::new(), + name: "a.jar".into(), + size: 1, + sha512: sha512.map(str::to_owned), + sha1: sha1.map(str::to_owned), + primary: true, + }; + let long = "ab".repeat(64); + assert_eq!( + checked_dir(home, &file(Some(&long), None)).unwrap(), + home.join(CHECKS).join("ab".repeat(20)) + ); + assert!(checked_dir(home, &file(None, Some("../../etc"))).is_none()); + assert!(checked_dir(home, &file(None, None)).is_none()); + } +} diff --git a/launcher/src/browser/modrinth.rs b/launcher/src/browser/modrinth.rs index e7e39628a..77b5475bb 100644 --- a/launcher/src/browser/modrinth.rs +++ b/launcher/src/browser/modrinth.rs @@ -13,6 +13,7 @@ fn project_type(kind: Kind) -> &'static str { Kind::ResourcePack => "resourcepack", Kind::ShaderPack => "shader", Kind::Modpack => "modpack", + Kind::Mod => "mod", } } @@ -32,8 +33,17 @@ pub(super) fn facets(query: &Query) -> String { all.push(vec!["categories:iris".into(), "categories:optifine".into()]) } Kind::Modpack => {} + Kind::Mod => all.push(vec![format!("versions:{GAME}")]), } } + if query.kind == Kind::Mod { + all.push( + super::java::LOADERS + .iter() + .map(|l| format!("categories:{l}")) + .collect(), + ); + } serde_json::to_string(&all).unwrap_or_default() } diff --git a/launcher/src/browser/tests.rs b/launcher/src/browser/tests.rs index ced342d13..9e75c55a1 100644 --- a/launcher/src/browser/tests.rs +++ b/launcher/src/browser/tests.rs @@ -140,6 +140,42 @@ fn modrinth_search_asks_for_what_runs() { modrinth::facets(&Query::new("", Kind::Modpack)), r#"[["project_type:modpack"]]"# ); + assert_eq!( + modrinth::facets(&Query::new("", Kind::Mod)), + r#"[["project_type:mod"],["versions:26.3"],["categories:neoforge","categories:fabric","categories:forge","categories:quilt"]]"# + ); +} + +#[test] +fn java_mods_are_checked_for_1_21_and_later() { + assert_eq!( + support(Kind::Mod, &v(&["1.20.1"]), &v(&["forge"])), + Support::No("Made for 1.20.1: Horizon ports mods made for 1.21 and later.".into()) + ); + assert!(!support(Kind::Mod, &v(&[GAME]), &v(&["rift"])).installable()); + assert!(matches!( + support(Kind::Mod, &v(&["1.21.1"]), &v(&["neoforge"])), + Support::Partial(_) + )); + for (version, ok) in [ + ("1.21", true), + ("1.21.11", true), + ("26.3", true), + ("1.20.6", false), + ("26.1-snapshot-2", false), + ("", false), + ] { + assert_eq!(portable_version(version), ok, "{version}"); + } + let versions = [ + version("snapshot", &["26.4-snapshot-1"], &["fabric"]), + version("shaders", &[GAME], &["iris"]), + version("now", &[GAME], &["neoforge"]), + version("older", &["1.21.1"], &["neoforge"]), + ]; + assert_eq!(pick(Kind::Mod, &versions, false).unwrap().id, "now"); + assert_eq!(pick(Kind::Mod, &versions[3..], false), None); + assert_eq!(pick(Kind::Mod, &versions[3..], true).unwrap().id, "older"); } #[test] @@ -157,9 +193,16 @@ fn modrinth_answers() { assert_eq!(p.page, "https://modrinth.com/resourcepack/fresh-animations"); assert_eq!(p.support(), Support::Works); assert_eq!(p.downloads, 51404735); - // A Java mod is never a result. - let jar = json!({"project_id": "AANobbMI", "project_type": "mod", "slug": "sodium"}); - assert!(modrinth::parse_hit(&jar).is_none()); + // A Java mod is a result, checked before it is offered. + let jar = json!({"project_id": "AANobbMI", "project_type": "mod", "slug": "sodium", + "versions": ["26.3"], "categories": ["fabric", "optimization"]}); + let sodium = modrinth::parse_hit(&jar).unwrap(); + assert_eq!(sodium.kind, Kind::Mod); + assert_eq!(sodium.page, "https://modrinth.com/mod/sodium"); + assert!(matches!(sodium.support(), Support::Partial(_))); + // Data packs and plugins are not. + let plugin = json!({"project_id": "x", "project_type": "plugin", "slug": "p"}); + assert!(modrinth::parse_hit(&plugin).is_none()); let project = json!({ "id": "HVnmMxH1", "project_type": "shader", "slug": "complementary-reimagined", @@ -243,7 +286,11 @@ fn curseforge_answers() { assert_eq!(p.loaders, ["iris", "optifine"]); assert_eq!(p.author, "CaptTatsu"); assert!(p.support().installable()); - assert!(curseforge::parse_mod(&json!({"id": 1, "classId": 6})).is_none()); + assert_eq!( + curseforge::parse_mod(&json!({"id": 1, "classId": 6})).map(|p| p.kind), + Some(Kind::Mod) + ); + assert!(curseforge::parse_mod(&json!({"id": 1, "classId": 17})).is_none()); let file = json!({ "id": 5000, "displayName": "BSL v10", "fileName": "BSL_v10.zip", "fileLength": 300, diff --git a/launcher/src/cli.rs b/launcher/src/cli.rs index e498fed2b..530d220dd 100644 --- a/launcher/src/cli.rs +++ b/launcher/src/cli.rs @@ -170,8 +170,18 @@ enum ModsCmd { #[arg(long, value_enum, default_value_t = SourceArg::Modrinth)] source: SourceArg, }, - /// Install a pack and what it needs, by its id or slug (checksums checked); a modpack is - /// imported on the Modpacks page + /// Say how well a Java mod runs in Horizon: its jar is downloaded (checksum checked), + /// carried over and read; the answer is kept + Check { + project: String, + /// Allow a version made for another Minecraft version (1.21 and later) + #[arg(long)] + everything: bool, + #[arg(long, value_enum, default_value_t = SourceArg::Modrinth)] + source: SourceArg, + }, + /// Install a pack and what it needs, by its id or slug (checksums checked); a Java mod is + /// ported into horizon-mods and turned on; a modpack is imported Install { project: String, /// Allow a version made for another Minecraft version @@ -193,6 +203,7 @@ enum ModsCmd { #[derive(Clone, Copy, clap::ValueEnum)] enum KindArg { + Mod, Resource, Shader, Modpack, @@ -950,6 +961,7 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { KindArg::Resource => Kind::ResourcePack, KindArg::Shader => Kind::ShaderPack, KindArg::Modpack => Kind::Modpack, + KindArg::Mod => Kind::Mod, }; let query = Query { everything, @@ -968,20 +980,67 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { } else { for p in &found { let support = p.support(); + let unchecked = p.kind == Kind::Mod && support.installable(); println!( "{} ({}) {} · {} downloads\n {}", p.title, p.slug, - support.label(), + if unchecked { + "Not checked" + } else { + support.label() + }, p.downloads, p.summary ); - if let Some(why) = support.reason() { + if unchecked { + println!(" horizon-launcher mods check {}", p.slug); + } else if let Some(why) = support.reason() { println!(" {why}"); } } } } + ModsCmd::Check { + project, + everything, + source, + } => { + let source = source.get()?; + let p = source.project(&project)?; + if p.kind != Kind::Mod { + return Err(format!("{} isn't a Java mod.", p.title)); + } + let (version, c) = horizon_launcher::browser::java::check_project( + &home, + &*source, + &p, + everything, + &progress(p.title.clone()), + )?; + if as_json { + let mut v = serde_json::to_value(&c).unwrap_or_default(); + v["version"] = version.number.clone().into(); + v["label"] = c.verdict.label().into(); + println!("{v}"); + return Ok(()); + } + println!( + "{} {} ({} {}): {}. {}", + p.title, + version.number, + c.loader, + c.mod_id, + c.verdict.label(), + c.summary + ); + for line in &c.ports { + println!(" ports: {line}"); + } + for line in &c.skipped { + println!(" doesn't: {line}"); + } + } ModsCmd::Install { project, everything, @@ -1009,6 +1068,9 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> { } for e in done.iter().filter(|_| !as_json) { println!("{} {}: {} ({})", e.title, e.number, e.file, e.checksum); + for s in &e.skipped { + println!(" not ported: {s}"); + } } } ModsCmd::Update { project, check } => { diff --git a/launcher/src/main.rs b/launcher/src/main.rs index c1184fe10..bb1e8dceb 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -37,18 +37,16 @@ enum Page { Play, Versions, Mods, - Modpacks, Servers, Notes, Settings, } impl Page { - const ALL: [(Page, &'static str); 7] = [ + const ALL: [(Page, &'static str); 6] = [ (Page::Play, "Play"), (Page::Versions, "Versions"), (Page::Mods, "Mods"), - (Page::Modpacks, "Modpacks"), (Page::Servers, "Servers"), (Page::Notes, "Patch notes"), (Page::Settings, "Settings"), @@ -2788,7 +2786,6 @@ impl Render for Launcher { Page::Play => self.play_page(cx), Page::Versions => self.versions_page(cx), Page::Mods => self.mods_page(cx), - Page::Modpacks => self.modpacks_page(cx), Page::Servers => self.servers_page(cx), Page::Notes => self.notes_page(cx), Page::Settings => self.settings_page(cx), diff --git a/launcher/src/modpacks_page.rs b/launcher/src/modpacks_page.rs index 2398421c6..b776321b3 100644 --- a/launcher/src/modpacks_page.rs +++ b/launcher/src/modpacks_page.rs @@ -1,5 +1,5 @@ -//! 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`). +//! Imported modpacks, on the Mods page's Modpacks tab: 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; @@ -124,7 +124,8 @@ impl Launcher { self.start_client(tag); } - pub(super) fn modpacks_page(&mut self, cx: &mut Context) -> Div { + /// The imported packs, above the Modpacks tab's search. + pub(super) fn imported_packs(&mut self, cx: &mut Context) -> Div { let t = self.theme; if self.packs_loaded.is_none() { self.packs = modpacks::list(); @@ -133,12 +134,6 @@ impl Launcher { } 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); @@ -159,14 +154,11 @@ impl Launcher { .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", + ".mrpack (Modrinth), .zip (CurseForge), or a Prism, MultiMC or CurseForge instance. \ + Horizon ports what it can on this computer, from your own downloads, and plays \ + the pack as its own profile. Nothing is uploaded or shared.", )); - let mut page = div() - .flex() - .flex_col() - .gap(px(32.)) - .child(header) - .child(actions); + let mut page = div().flex().flex_col().gap(px(32.)).child(actions); if busy || !self.pack_log.is_empty() { page = page.child(self.pack_log_plate(&t)); } @@ -174,10 +166,11 @@ impl Launcher { 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, - )); + return page.child( + text(theme::CAPTION) + .text_color(t.muted) + .child("No modpack imported yet: import one, or find one below."), + ); } if self.packs.len() > 1 { let mut list = div().flex().flex_col().border_t_1().border_color(t.rule); diff --git a/launcher/src/mods_page.rs b/launcher/src/mods_page.rs index 25a825c93..136ca7953 100644 --- a/launcher/src/mods_page.rs +++ b/launcher/src/mods_page.rs @@ -1,19 +1,25 @@ -//! The Mods page: search Modrinth (and CurseForge with a key) for resource packs, shader packs -//! and modpacks Horizon loads, see where each comes from and how well it runs, install it with -//! its checksum checked, and update or remove what was installed (`horizon_launcher::browser`). +//! The Mods page: search Modrinth (and CurseForge with a key) for Java mods, modpacks, resource +//! packs and shader packs, see where each comes from and how well it runs (a Java mod's jar is +//! checked first), install it with its checksum checked, and update or remove what was installed +//! (`horizon_launcher::browser`). Imported modpacks are listed on its Modpacks tab. use super::servers_page::{type_key, Key}; use super::*; use horizon_launcher::browser::{ - self, curseforge::CurseForge, installed, Kind as PackKind, Project, Query, SourceId, Support, + self, curseforge::CurseForge, installed, java, Kind as PackKind, Project, Query, SourceId, + Support, }; use horizon_launcher::modpacks; +use horizon_port_pack::check::Check; use std::collections::HashMap; -const KINDS: [(PackKind, &str); 3] = [ +const KINDS: [(PackKind, &str); 4] = [ + (PackKind::Mod, "Mods"), + (PackKind::Modpack, "Modpacks"), (PackKind::ResourcePack, "Resource packs"), (PackKind::ShaderPack, "Shader packs"), - (PackKind::Modpack, "Modpacks"), ]; +/// Java mods checked at once. +const CHECKING: usize = 2; const SOURCES: [(SourceId, &str); 2] = [ (SourceId::Modrinth, "Modrinth"), (SourceId::CurseForge, "CurseForge"), @@ -26,6 +32,15 @@ pub(super) enum Event { Progress(String, f32), Done(Result, bool), Updates(HashMap<(SourceId, String), String>), + /// A Java mod's check: its jar read, or why it couldn't be. + Checked((SourceId, String), Result, String>), +} + +/// Where a Java mod's check is. +pub(super) enum Checking { + Running, + Done(Box), + Failed(String), } pub(super) struct Mods { @@ -50,6 +65,8 @@ pub(super) struct Mods { message: Option>, updates: HashMap<(SourceId, String), String>, confirm_remove: Option, + /// Java mods' checks, by source and project. + checks: HashMap<(SourceId, String), Checking>, tx: Sender, rx: Receiver, } @@ -58,7 +75,7 @@ impl Mods { pub(super) fn new(cx: &mut App) -> Self { let (tx, rx) = channel(); Self { - kind: PackKind::ResourcePack, + kind: PackKind::Mod, source: SourceId::Modrinth, curseforge: CurseForge::from_env().is_some(), text: String::new(), @@ -77,6 +94,7 @@ impl Mods { message: None, updates: HashMap::new(), confirm_remove: None, + checks: HashMap::new(), tx, rx, } @@ -91,6 +109,19 @@ impl Mods { .iter() .find(|e| e.source == p.source && e.project == p.id) } + + /// How well a result runs: a Java mod's from its check once it has one. + fn support(&self, p: &Project) -> Support { + let metadata = p.support(); + if p.kind != PackKind::Mod || !metadata.installable() { + return metadata; + } + match self.checks.get(&(p.source, p.id.clone())) { + Some(Checking::Done(c)) => java::support_of(c), + Some(Checking::Failed(e)) => Support::Partial(format!("Not checked: {e}")), + _ => Support::Partial("Checking its jar…".into()), + } + } } /// `51404735` → `51.4M`. @@ -115,6 +146,7 @@ impl Launcher { /// Called with the launcher's other work: what the background sent. pub(super) fn mods_tick(&mut self) -> bool { let mut changed = false; + let mut to_check = Vec::new(); while let Ok(event) = self.mods.rx.try_recv() { changed = true; let m = &mut self.mods; @@ -126,8 +158,9 @@ impl Launcher { Ok(found) => { m.more = found.len() == PAGE; m.results.truncate(offset); - m.results.extend(found); + m.results.extend(found.iter().cloned()); m.error = None; + to_check.extend(found); } Err(e) => m.error = Some(e), } @@ -149,8 +182,16 @@ impl Launcher { } } Event::Updates(found) => m.updates = found, + Event::Checked(key, result) => { + let state = match result { + Ok(c) => Checking::Done(c), + Err(e) => Checking::Failed(e), + }; + m.checks.insert(key, state); + } } } + self.mods_check(to_check); changed } @@ -177,6 +218,43 @@ impl Launcher { }); } + /// Checks the Java mods among `found` that aren't checked yet, a few at a time, on threads: + /// a cached check answers at once, else the jar is downloaded and read. + fn mods_check(&mut self, found: Vec) { + let m = &mut self.mods; + let todo: Vec = found + .into_iter() + .filter(|p| p.kind == PackKind::Mod && p.support().installable()) + .filter(|p| !m.checks.contains_key(&(p.source, p.id.clone()))) + .collect(); + if todo.is_empty() { + return; + } + for p in &todo { + m.checks.insert((p.source, p.id.clone()), Checking::Running); + } + let (tx, everything) = (m.tx.clone(), m.everything); + let queue = std::sync::Mutex::new(todo.into_iter()); + std::thread::spawn(move || { + let home = backend::game_home(); + std::thread::scope(|s| { + for _ in 0..CHECKING { + s.spawn(|| { + while let Some(p) = queue.lock().ok().and_then(|mut q| q.next()) { + let result = browser::source(p.source) + .ok_or_else(|| format!("{} isn't set up.", p.source.label())) + .and_then(|source| { + java::check_project(&home, &*source, &p, everything, &|_| {}) + }) + .map(|(_, c)| Box::new(c)); + let _ = tx.send(Event::Checked((p.source, p.id), result)); + } + }); + } + }); + }); + } + /// Looks for newer versions of what the browser installed. fn mods_check_updates(&mut self) { let entries = self.mods.installed.clone(); @@ -233,7 +311,7 @@ impl Launcher { let log = |line: String| progress(&line, 1.); let pack = modpacks::import(&file, &log)?; return Ok(format!( - "{} is imported: open it on the Modpacks page to port it.", + "{} is imported: it is listed above, ready to port.", pack.title() )); } @@ -243,6 +321,19 @@ impl Launcher { .iter() .map(|e| format!("{} {}", e.title, e.number)) .collect(); + if p.kind == PackKind::Mod { + let skipped = done.last().map_or(0, |e| e.skipped.len()); + return Ok(format!( + "Ported {} into horizon-mods and turned on (Options > Mods in the \ + game).{}", + names.join(", "), + if skipped > 0 { + " What didn't port is listed under Installed." + } else { + "" + } + )); + } let turn_on = match p.kind { PackKind::ShaderPack => "Video Settings > Shader Packs", _ => "Options > Resource Packs", @@ -330,8 +421,10 @@ impl Launcher { } let header = page_header( "Mods", - "Resource packs, shader packs and modpacks that Horizon loads. Each file is checked \ - against its source's checksum before it reaches your game folder.", + "Java mods, modpacks, resource packs and shader packs. Horizon ports what a Java mod \ + carries (blocks, items, recipes, worldgen) and says before you install what runs. \ + Each file is checked against its source's checksum before it reaches your game \ + folder.", &t, ); let this = cx.entity().downgrade(); @@ -436,6 +529,9 @@ impl Launcher { Some(Err(e)) => page = page.child(notice(e.clone(), &t)), None => {} } + if self.mods.kind == PackKind::Modpack { + page = page.child(self.imported_packs(cx)); + } if let Some(list) = self.mods_installed_list(cx) { page = page.child(list); } @@ -512,7 +608,11 @@ impl Launcher { .flex() .flex_col() .child(format!( - "{} · from {}{} · {}", + "{}{} · from {}{} · {}", + e.verdict + .as_ref() + .map(|v| format!("{v} · ")) + .unwrap_or_default(), e.number, e.source.label(), if e.dependency { @@ -522,6 +622,11 @@ impl Launcher { }, e.file )) + .children(e.skipped.iter().map(|s| { + div() + .text_color(t.ink_soft) + .child(format!("Not ported: {s}")) + })) .child( div() .font_family(theme::MONO) @@ -564,7 +669,13 @@ impl Launcher { let busy = m.busy.as_ref().map(|b| b.0.as_str()); let mut list = div().flex().flex_col().border_t_1().border_color(t.rule); for (i, p) in m.results.iter().enumerate() { - let support = p.support(); + let support = m.support(p); + let checking = p.kind == PackKind::Mod + && matches!( + m.checks.get(&(p.source, p.id.clone())), + None | Some(Checking::Running) + ) + && p.support().installable(); let color = match support { Support::Works => t.success, Support::Partial(_) => t.accent, @@ -591,6 +702,8 @@ impl Launcher { right = right.child(caps("Installing").text_color(t.accent)); } else if m.entry(p).is_some() { right = right.child(caps("Installed").text_color(t.muted)); + } else if checking { + right = right.child(caps("Checking").text_color(t.muted)); } else if support.installable() { let label = if p.kind == PackKind::Modpack { "Import" diff --git a/website/docs/modpacks.md b/website/docs/modpacks.md index a4396392b..b78c59851 100644 --- a/website/docs/modpacks.md +++ b/website/docs/modpacks.md @@ -6,7 +6,7 @@ Java mod jars do not run in Horizon. Instead, the launcher reads a modpack, tell ## What the Modpacks page does -Open **Modpacks** in the launcher. +Open **Modpacks** in the launcher. (From the next launcher release, it is the **Modpacks** tab of the **Mods** page.) 1. **Import a pack.** Choose **Import a pack file…** for a Modrinth `.mrpack` or a CurseForge zip, or **Import an instance folder…** for a Prism, MultiMC or CurseForge instance. The **Mods** page can also find a Modrinth modpack and import it for you (see [Mods and data packs](/docs/mods#finding-resource-packs-shader-packs-and-modpacks)). 2. **Read the coverage report.** For every mod in the pack it says **Ported**, **Partial**, **Not yet** or **Not needed**, with the reason. You can filter the list by status. diff --git a/website/docs/mods.md b/website/docs/mods.md index 05dcaee2d..d3305fa69 100644 --- a/website/docs/mods.md +++ b/website/docs/mods.md @@ -36,7 +36,17 @@ cargo horizon-mod run The launcher's **Mods** page (launcher 0.17 and newer) searches [Modrinth](https://modrinth.com) for what Horizon can load: resource packs, Java shader packs and modpacks. Each result says how well it runs in Horizon (**Works**, **Partly**, or **Doesn't run**), and by default the page shows only what runs. **Install** downloads the file, checks it against the checksum Modrinth lists and refuses anything that does not match, then puts it in the right folder, with the packs it needs. **Update** and **Remove** are there too. A resource pack still has to be turned on in the game's Resource Packs screen, and a shader pack in Video, Shader Packs. A modpack is imported on the [Modpacks page](/docs/modpacks). -The page cannot search CurseForge yet. Java mod jars are never offered, because they do not run. The same things work from a terminal: `horizon-launcher mods search`, `install`, `update` and `remove`. +The page cannot search CurseForge yet. The same things work from a terminal: `horizon-launcher mods search`, `install`, `update` and `remove`. + +## Java mods from the Mods page (next launcher release) + +Java code does not run in Horizon, but much of what a mod adds is data: blocks, items, recipes, loot tables, tags, worldgen, textures. From the next launcher release, the Mods page also lists Fabric, NeoForge and Forge mods made for 26.3 and, before offering one, downloads its jar, checks it against Modrinth's checksum and reads it (without running it) to say what of it Horizon runs: + +- **Works**: the mod is only content, and all of it carries over. +- **Partly**: its content carries over; the row lists what does not, such as machines and containers, mobs, blocks or items with behaviour of their own, recipe types of its own, or Mixins. +- **Doesn't run**: there is nothing to carry over (performance mods, libraries, mods that are all code). It is not offered. + +**Install** brings the mod over into `horizon-mods` and turns it on; start the game again to load it. Blocks take the closest vanilla block's shape, hardness and sounds, so a carried-over block can break faster or slower than in Java. Most popular mods today are **Partly** or **Doesn't run**: the verdict is the honest answer for each one. ## Data packs