diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java index da4b8c2029..a8244c509b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java @@ -94,22 +94,11 @@ public DownloadPage(DownloadListPage page, RemoteMod addon, Profile.ProfileVersi } private void loadModVersions() { - File versionJar = StringUtils.isNotBlank(version.getVersion()) - ? version.getProfile().getRepository().getVersionJar(version.getVersion()) - : null; - setLoading(true); setFailed(false); Task.supplyAsync(() -> { Stream versions = addon.getData().loadVersions(repository); -// if (StringUtils.isNotBlank(version.getVersion())) { -// Optional gameVersion = GameVersion.minecraftVersion(versionJar); -// if (gameVersion.isPresent()) { -// return sortVersions( -// .filter(file -> file.getGameVersions().contains(gameVersion.get()))); -// } -// } return sortVersions(versions); }).whenComplete(Schedulers.javafx(), (result, exception) -> { if (exception == null) { @@ -286,19 +275,27 @@ protected ModDownloadPageSkin(DownloadPage control) { if (control.version.getProfile() != null && control.version.getVersion() != null) { HMCLGameRepository repository = control.version.getProfile().getRepository(); Version game = repository.getResolvedPreservingPatchesVersion(control.version.getVersion()); - LibraryAnalyzer libraryAnalyzer = LibraryAnalyzer.analyze(game, repository.getGameVersion(game).orElse(null)); - libraryAnalyzer.getVersion(LibraryAnalyzer.LibraryType.MINECRAFT).ifPresent(currentGameVersion -> { - Set currentGameModLoaders = libraryAnalyzer.getModLoaders(); - if (control.versions.containsKey(currentGameVersion)) { - control.versions.get(currentGameVersion).stream() - .filter(version1 -> version1.getLoaders().isEmpty() || version1.getLoaders().stream().anyMatch(currentGameModLoaders::contains)) - .findFirst() - .ifPresent(value -> list.getContent().addAll( - ComponentList.createComponentListTitle(i18n("mods.download.recommend", currentGameVersion)), - new ModItem(value, control) - )); + String gameVersion = repository.getGameVersion(game).orElse(null); + + if (gameVersion != null) { + List modVersions = control.versions.get(gameVersion); + if (modVersions != null && !modVersions.isEmpty()) { + Set targetLoaders = LibraryAnalyzer.analyze(game, gameVersion).getModLoaders(); + + resolve: + for (RemoteMod.Version modVersion : modVersions) { + for (ModLoaderType loader : modVersion.getLoaders()) { + if (targetLoaders.contains(loader)) { + list.getContent().addAll( + ComponentList.createComponentListTitle(i18n("mods.download.recommend", gameVersion)), + new ModItem(modVersion, control) + ); + break resolve; + } + } + } } - }); + } } for (String gameVersion : control.versions.keys().stream()