Skip to content

Commit 9a5b50d

Browse files
committed
API: Fixed finding latest Forge loader
Now going through all versions and taking the maximum, it will be more resilient in the future of the order in maven-metadata.xml change again.
1 parent 26646af commit 9a5b50d

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

portablemc/src/forge/mod.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ impl Repo {
547547
let [major, minor] = parse_game_version(game_version)?;
548548
let prefix = if self.neoforge {
549549
if major == 20 && minor == 1 {
550+
// We ignore the special case of 47.1.82 because it's not the latest
551+
// version anyway...
550552
format!("1.20.1-")
551553
} else {
552554
format!("{major}.{minor}.")
@@ -559,17 +561,28 @@ impl Repo {
559561
}
560562
};
561563

562-
let mut it = self.iter()
563-
.filter(|v| v.name().starts_with(&prefix))
564-
.filter(|v| !stable || v.is_stable());
565-
566-
// NeoForge has latest versions last.
567-
if self.neoforge {
568-
it.last()
569-
} else {
570-
it.next()
564+
// To search the maximum version...
565+
let mut max_loader = [0; 4];
566+
let mut max_version = None;
567+
for version in self.iter() {
568+
// Filter versions that starts with the right prefix...
569+
let Some(loader) = version.name().strip_prefix(&prefix) else { continue };
570+
// Ignore unstable versions when not requested!
571+
if stable && !version.is_stable() { continue }
572+
// Remove a potential suffix to that version, such as -1.7.10, -beta, etc...
573+
let loader = loader.split_once("-").map(|(before, _)| before).unwrap_or(loader);
574+
// Parse the loader version as 4-digit versions, because Forge used to have
575+
// such long versions, ignoring versions that could not be parsed.
576+
let Some(loader) = parse_generic_version::<4, 1>(loader) else { continue };
577+
// Then compare to find the maximum version...
578+
if loader > max_loader {
579+
max_loader = loader;
580+
max_version = Some(version);
581+
}
571582
}
572583

584+
max_version
585+
573586
}
574587

575588
}

0 commit comments

Comments
 (0)