Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import javafx.scene.layout.VBox;
import org.jackhuang.hmcl.ui.FXUtils;

import java.util.Collection;

public class TwoLineListItem extends VBox {
private static final String DEFAULT_STYLE_CLASS = "two-line-list-item";

Expand Down Expand Up @@ -158,6 +160,15 @@ public Label getSubtitleLabel() {
return lblSubtitle;
}

private static Label createTag(String tag, PseudoClass pseudoClass) {
var tagLabel = new Label(tag);
tagLabel.getStyleClass().add("tag");
tagLabel.setMinWidth(Label.USE_PREF_SIZE);
if (pseudoClass != null)
tagLabel.pseudoClassStateChanged(pseudoClass, true);
return tagLabel;
}

private ObservableList<Label> tags;

public ObservableList<Label> getTags() {
Expand All @@ -183,18 +194,17 @@ public ObservableList<Label> getTags() {
}

public void addTag(String tag, PseudoClass pseudoClass) {
var tagLabel = new Label(tag);
tagLabel.getStyleClass().add("tag");
tagLabel.setMinWidth(Label.USE_PREF_SIZE);
if (pseudoClass != null)
tagLabel.pseudoClassStateChanged(pseudoClass, true);
getTags().add(tagLabel);
getTags().add(createTag(tag, pseudoClass));
}

public void addTag(String tag) {
addTag(tag, null);
}

public void addTags(Collection<String> tags) {
getTags().addAll(tags.stream().map(tag -> createTag(tag, null)).toList());
}

private static final PseudoClass WARNING_PSEUDO_CLASS = PseudoClass.getPseudoClass("warning");

public void addTagWarning(String tag) {
Expand Down
46 changes: 24 additions & 22 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ protected DownloadPageSkin(DownloadPage control) {
resolve:
for (RemoteAddon.Version modVersion : modVersions) {
if (getSkinnable().type == RemoteAddonRepository.Type.MOD) {
for (ModLoaderType loader : modVersion.loaders()) {
if (targetLoaders.contains(loader)) {
for (Either<ModLoaderType, String> loader : modVersion.loaders()) {
if (loader.hasLeft() && targetLoaders.contains(loader.left())) {
list.getContent().addAll(
ComponentList.createComponentListTitle(i18n("mods.download.recommend", gameVersion)),
new AddonItem(control.addon, modVersion, control)
Expand Down Expand Up @@ -452,28 +452,30 @@ private static final class AddonItem extends StackPane {
break;
}

for (ModLoaderType modLoaderType : dataItem.loaders()) {
switch (modLoaderType) {
case FORGE:
content.addTag(i18n("install.installer.forge"));
break;
case CLEANROOM:
content.addTag(i18n("install.installer.cleanroom"));
break;
case NEO_FORGE:
content.addTag(i18n("install.installer.neoforge"));
break;
case FABRIC:
content.addTag(i18n("install.installer.fabric"));
break;
case LITE_LOADER:
content.addTag(i18n("install.installer.liteloader"));
break;
case QUILT:
content.addTag(i18n("install.installer.quilt"));
break;
Set<String> tags = new LinkedHashSet<>();
for (Either<ModLoaderType, String> loader : dataItem.loaders()) {
if (loader.hasLeft()) {
var modLoaderType = loader.left();
String tag = switch (modLoaderType) {
case FORGE -> i18n("install.installer.forge");
case CLEANROOM -> i18n("install.installer.cleanroom");
case NEO_FORGE -> i18n("install.installer.neoforge");
case FABRIC -> i18n("install.installer.fabric");
case LITE_LOADER -> i18n("install.installer.liteloader");
case QUILT -> i18n("install.installer.quilt");
case LEGACY_FABRIC -> i18n("install.installer.legacyfabric");
default -> null;
};
if (tag != null) tags.add(tag);
} else if (loader.hasRight()) {
if ("bungeecord".equalsIgnoreCase(loader.right())) {
tags.add("BungeeCord");
} else {
tags.add(StringUtils.removeDashAndCapitalizeWords(loader.right()));
}
}
}
content.addTags(tags);

descPane.getChildren().setAll(graphicPane, content);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@
import org.jackhuang.hmcl.ui.animation.ContainerAnimations;
import org.jackhuang.hmcl.ui.animation.TransitionPane;
import org.jackhuang.hmcl.ui.construct.*;
import org.jackhuang.hmcl.util.FXThread;
import org.jackhuang.hmcl.util.Lazy;
import org.jackhuang.hmcl.util.Pair;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.i18n.I18n;
import org.jackhuang.hmcl.util.io.CompressingUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
Expand Down Expand Up @@ -477,25 +474,26 @@ final class ModInfoDialog extends JFXDialogLayout {
if (versionOptional.isPresent()) {
RemoteAddon remoteAddon = repository.getModById(DownloadProviders.getDownloadProvider(), versionOptional.get().modid());
FXUtils.runInFX(() -> {
for (ModLoaderType modLoaderType : versionOptional.get().loaders()) {
String loaderName = switch (modLoaderType) {
case FORGE -> i18n("install.installer.forge");
case CLEANROOM -> i18n("install.installer.cleanroom");
case LEGACY_FABRIC -> i18n("install.installer.legacyfabric");
case NEO_FORGE -> i18n("install.installer.neoforge");
case FABRIC -> i18n("install.installer.fabric");
case LITE_LOADER -> i18n("install.installer.liteloader");
case QUILT -> i18n("install.installer.quilt");
default -> null;
};
if (loaderName == null)
continue;
if (title.getTags()
.stream()
.noneMatch(it -> it.getText().equals(loaderName))) {
title.addTag(loaderName);
}
Set<String> tags = new LinkedHashSet<>();
for (Either<ModLoaderType, String> loader : versionOptional.get().loaders()) {
String loaderName;
if (loader.hasLeft()) {
loaderName = switch (loader.left()) {
case FORGE -> i18n("install.installer.forge");
case CLEANROOM -> i18n("install.installer.cleanroom");
case LEGACY_FABRIC -> i18n("install.installer.legacyfabric");
case NEO_FORGE -> i18n("install.installer.neoforge");
case FABRIC -> i18n("install.installer.fabric");
case LITE_LOADER -> i18n("install.installer.liteloader");
case QUILT -> i18n("install.installer.quilt");
default -> null;
};
} else if (loader.hasRight()) {
loaderName = StringUtils.removeDashAndCapitalizeWords(loader.right());
} else continue;
if (loaderName != null) tags.add(loaderName);
}
title.addTags(tags);
Comment thread
ToobLac marked this conversation as resolved.
Outdated

button.setOnAction(e -> {
fireEvent(new DialogCloseEvent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jackhuang.hmcl.addon.repository.ModrinthRemoteAddonRepository;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.util.Either;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
Expand Down Expand Up @@ -204,7 +205,7 @@ public interface IVersion {

public record Version(IVersion self, String modid, String name, String version, String changelog,
Instant datePublished, VersionType versionType, File file, List<Dependency> dependencies,
List<String> gameVersions, List<ModLoaderType> loaders) {
List<String> gameVersions, List<Either<ModLoaderType, String>> loaders) {
}

public record File(Map<String, String> hashes, String url, String filename) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.jackhuang.hmcl.addon.RemoteAddon;
import org.jackhuang.hmcl.addon.RemoteAddonRepository;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.util.Either;
import org.jackhuang.hmcl.util.io.FileUtils;

import java.io.IOException;
Expand Down Expand Up @@ -202,7 +203,7 @@ public AddonUpdate checkUpdates(DownloadProvider downloadProvider, String gameVe
if (currentVersion.isEmpty()) return null;
List<RemoteAddon.Version> remoteVersions = repository.getRemoteVersionsById(downloadProvider, currentVersion.get().modid())
.filter(version -> version.gameVersions().contains(gameVersion))
.filter(version -> version.loaders().contains(getModLoaderType()))
.filter(version -> version.loaders().contains(Either.left(getModLoaderType())))
Comment thread
ToobLac marked this conversation as resolved.
.filter(version -> version.datePublished().compareTo(currentVersion.get().datePublished()) > 0)
.sorted(Comparator.comparing(RemoteAddon.Version::datePublished).reversed())
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
*/
package org.jackhuang.hmcl.addon.mod;

import org.jackhuang.hmcl.util.Either;

import java.util.Locale;

public enum ModLoaderType {
UNKNOWN,
FORGE,
Expand All @@ -25,5 +29,17 @@ public enum ModLoaderType {
FABRIC,
QUILT,
LITE_LOADER,
LEGACY_FABRIC
LEGACY_FABRIC;

public static Either<ModLoaderType, String> toEither(String loader) {
return switch (loader.toLowerCase(Locale.ROOT)) {
case "fabric" -> Either.left(ModLoaderType.FABRIC);
case "forge" -> Either.left(ModLoaderType.FORGE);
case "neoforge" -> Either.left(ModLoaderType.NEO_FORGE);
case "quilt" -> Either.left(ModLoaderType.QUILT);
case "liteloader" -> Either.left(ModLoaderType.LITE_LOADER);
case "legacy-fabric" -> Either.left(ModLoaderType.LEGACY_FABRIC);
default -> Either.right(loader);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
import org.jackhuang.hmcl.addon.RemoteAddonRepository;
import org.jackhuang.hmcl.addon.mod.ModLoaderType;
import org.jackhuang.hmcl.download.DownloadProvider;
import org.jackhuang.hmcl.util.Immutable;
import org.jackhuang.hmcl.util.MurmurHash2;
import org.jackhuang.hmcl.util.Pair;
import org.jackhuang.hmcl.util.StringUtils;
import org.jackhuang.hmcl.util.*;
import org.jackhuang.hmcl.util.io.HttpRequest;
import org.jackhuang.hmcl.util.io.JarUtils;
import org.jackhuang.hmcl.util.io.NetworkUtils;
Expand Down Expand Up @@ -482,13 +479,7 @@ public RemoteAddon.Version toVersion() {
return RemoteAddon.Dependency.ofGeneral(RELATION_TYPE.get(dependency.relationType()), MODS, Integer.toString(dependency.modId()));
}).distinct().filter(Objects::nonNull).collect(Collectors.toList()),
gameVersions.stream().filter(GameVersionNumber::isKnown).toList(),
gameVersions.stream().flatMap(version -> {
if ("fabric".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.FABRIC);
else if ("forge".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.FORGE);
else if ("quilt".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.QUILT);
else if ("neoforge".equalsIgnoreCase(version)) return Stream.of(ModLoaderType.NEO_FORGE);
else return Stream.empty();
}).collect(Collectors.toList())
gameVersions.stream().map(ModLoaderType::toEither).toList()
Comment thread
ToobLac marked this conversation as resolved.
Outdated
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,7 @@ public Optional<RemoteAddon.Version> toVersion() {
return RemoteAddon.Dependency.ofGeneral(DEPENDENCY_TYPE.get(dependency.dependencyType), MODS, dependency.projectId);
}).filter(Objects::nonNull).collect(Collectors.toList()),
gameVersions,
loaders.stream().flatMap(loader -> {
if ("fabric".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.FABRIC);
else if ("forge".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.FORGE);
else if ("neoforge".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.NEO_FORGE);
else if ("quilt".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.QUILT);
else if ("liteloader".equalsIgnoreCase(loader)) return Stream.of(ModLoaderType.LITE_LOADER);
else return Stream.empty();
}).collect(Collectors.toList())
loaders.stream().map(ModLoaderType::toEither).toList()
));
}
}
Expand Down
38 changes: 38 additions & 0 deletions HMCLCore/src/main/java/org/jackhuang/hmcl/util/Either.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Hello Minecraft! Launcher
* Copyright (C) 2026 huangyuhui <huanghongxun2008@126.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.jackhuang.hmcl.util;

public record Either<T, U>(T left, U right) {
Comment thread
ToobLac marked this conversation as resolved.
Outdated

public static <T, U> Either<T, U> left(T left) {
return new Either<>(left, null);
}

public static <T, U> Either<T, U> right(U right) {
return new Either<>(null, right);
}

public boolean hasLeft() {
return left != null;
}

public boolean hasRight() {
return right != null;
}

}
10 changes: 10 additions & 0 deletions HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ public static String capitalizeFirst(String str) {
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
}

public static String removeDashAndCapitalizeWords(String str) {
if (str == null || str.isEmpty())
return str;
String[] words = str.replace('-', ' ').split(" ");
for (int i = 0; i < words.length; i++) {
words[i] = capitalizeFirst(words[i]);
}
return String.join(" ", words);
}

public static String substringBeforeLast(String str, char delimiter) {
return substringBeforeLast(str, delimiter, str);
}
Expand Down