Modpacks from the mod browser: ported in the same step, mods loaded together

Importing a modpack from the Mods page (or `mods install`) now ports it right away
for the selected version, so Play works straight after. port-pack leaves a
namespace two carried mods both claim to none of them (YUNG's mods all ship
`yungsapi`, which made the game drop three of them), and the launcher applies
the game's first-wins rule before it starts a pack, listing what it left off.

Measured on Vanilla Perfected, Slimes Adventure and All the Mods 10 (docs/modpacks.md):
2, 20 and 42 mods ported, every world loads, no crash.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-22 18:28:58 +02:00
parent f53998674d
commit f926d1d2b1
9 changed files with 243 additions and 20 deletions
+7 -7
View File
@@ -1053,13 +1053,13 @@ fn mods(action: ModsCmd, as_json: bool) -> Result<(), String> {
let file =
installed::fetch_modpack(&*source, &p, &folder, &progress(p.title.clone()))?;
let log = &|line: String| eprintln!("{line}");
let pack = modpacks::import(&file, log)?;
println!(
"Imported {} ({}): horizon-launcher modpack port {}",
pack.title(),
pack.summary(),
pack.slug
);
let resources = backend::resolve_version(None)
.ok()
.filter(|t| backend::is_prepared(t))
.map(|t| backend::resources(&t));
let pack = modpacks::import_and_port(&file, resources.as_deref(), log)?;
println!("{} ({})", modpacks::outcome(&pack), pack.summary());
println!("Play it: horizon-launcher modpack play {}", pack.slug);
return Ok(());
}
let done = installed::install(&*source, &p, everything, &home, &line)?;
+58 -5
View File
@@ -45,6 +45,8 @@ pub struct Imported {
pub fetched: Fetched,
/// The carried-over mods the profile loads.
pub mods: Vec<PathBuf>,
/// Carried-over mods left off because an earlier one owns a namespace of theirs, with why.
pub left_off: Vec<String>,
/// The mods the port step gets and carries over (content, data tier).
pub portable: usize,
}
@@ -105,6 +107,7 @@ pub fn load(work: &Path) -> Result<Imported, String> {
let rows: Vec<Row> = pipeline::read_json(&work.join("coverage.json")).unwrap_or_default();
let records: Vec<horizon_port_pack::inventory::Record> =
pipeline::read_json(&work.join("inventory.json")).unwrap_or_default();
let (mods, left_off) = pipeline::loadable(&carried(work));
Ok(Imported {
slug: work
.file_name()
@@ -114,7 +117,8 @@ pub fn load(work: &Path) -> Result<Imported, String> {
pack,
rows,
fetched: Fetched::load(work),
mods: carried(work),
mods,
left_off,
portable: records.iter().filter(|r| pipeline::portable(r)).count(),
})
}
@@ -176,6 +180,47 @@ pub fn port(
load(work)
}
/// What the mod browser does with a modpack: imports it, then ports what this computer can
/// (from the pack's links and Modrinth), so it plays straight away. A port that fails leaves the
/// pack imported; the error says so.
pub fn import_and_port(
path: &Path,
resources: Option<&Path>,
log: Log,
) -> Result<Imported, String> {
let pack = import(path, log)?;
if pack.portable == 0 {
return Ok(pack);
}
port(&pack.work, resources, None, log)
.map_err(|e| format!("{} is imported, but porting it failed: {e}", pack.title()))
}
/// One line on what an import and port gave: the mods carried over and the ones that weren't.
pub fn outcome(pack: &Imported) -> String {
let not = pack.count(Status::NotYet);
format!(
"{} is imported{}: {} of its {} files play in Horizon ({} ported, {} partly), {} don't \
yet, {} aren't needed{}. Its list says why.",
pack.title(),
if pack.mods.is_empty() {
""
} else {
" and ported"
},
pack.count(Status::Ported) + pack.count(Status::Partial),
pack.rows.len(),
pack.count(Status::Ported),
pack.count(Status::Partial),
not,
pack.count(Status::NotNeeded),
match pack.left_off.len() {
0 => String::new(),
n => format!("; {n} ported mods are left off, sharing a namespace with another"),
},
)
}
/// 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()) {
@@ -192,7 +237,8 @@ pub fn profile_home(work: &Path) -> PathBuf {
/// 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);
// Only mods that load together: the game would refuse the later of two sharing a namespace.
let (mods, _) = pipeline::loadable(&carried(work));
if mods.is_empty() {
return Err("Nothing is ported yet: port the pack first.".into());
}
@@ -229,12 +275,19 @@ mod tests {
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"] {
for (id, namespaces) in [("a", ""), ("b", ""), ("d", "\"a\"")] {
let carry = work.join("mods").join(id).join("carry");
fs::create_dir_all(&carry).unwrap();
fs::write(carry.join("horizon-mod.toml"), "").unwrap();
fs::write(
carry.join("horizon-mod.toml"),
format!(
"id = \"{id}\"\nname = \"{id}\"\nversion = \"1\"\napi = \"0.2\"\n\
capabilities = [\"registries\"]\nnamespaces = [{namespaces}]\n"
),
)
.unwrap();
}
// Left out: no manifest.
// Left out: no manifest (c), and one owning a namespace of an earlier mod (d).
fs::create_dir_all(work.join("mods/c/carry")).unwrap();
apply_profile(&mut cmd, &work).unwrap();
let args: Vec<String> = cmd
+3
View File
@@ -327,6 +327,9 @@ impl Launcher {
if let Some(jars) = p.jars() {
notes.push(jars);
}
for line in &p.left_off {
notes.push(format!("Left off: {line}."));
}
if !can_play {
notes.push("Playing needs a prepared Horizon version (Play page).".into());
}
+8 -3
View File
@@ -294,6 +294,11 @@ impl Launcher {
self.mods.busy = Some((id.clone(), format!("Asking {}…", source.label()), 0.));
self.mods.updates.remove(&(source, id.clone()));
let everything = self.mods.everything || self.mods.browse.filters.other_version();
// A modpack is ported for the selected version as soon as it is imported.
let resources = self
.selected()
.filter(|tag| backend::is_prepared(tag))
.map(|tag| backend::resources(tag));
let tx = self.mods.tx.clone();
std::thread::spawn(move || {
let last = std::cell::Cell::new(-1);
@@ -318,10 +323,10 @@ impl Launcher {
progress(&p.title, f)
})?;
let log = |line: String| progress(&line, 1.);
let pack = modpacks::import(&file, &log)?;
let pack = modpacks::import_and_port(&file, resources.as_deref(), &log)?;
return Ok(format!(
"{} is imported: it is listed above, ready to port.",
pack.title()
"{} Play it from the list above.",
modpacks::outcome(&pack)
));
}
let home = backend::game_home();