diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteModRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteModRepository.java index 249533d28..3a5a06e8e 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteModRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/RemoteModRepository.java @@ -87,7 +87,7 @@ public interface RemoteModRepository { } String[] DEFAULT_GAME_VERSIONS = new String[]{ - "1.18.1", "1.18", + "1.18.2", "1.18.1", "1.18", "1.17.1", "1.17", "1.16.5", "1.16.4", "1.16.3", "1.16.2", "1.16.1", "1.16", "1.15.2", "1.15.1", "1.15", diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java index 7fc9c7adc..9f56a644a 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/modrinth/ModrinthRemoteModRepository.java @@ -73,12 +73,15 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository { } @Override - public Stream search(String gameVersion, Category category, int pageOffset, int pageSize, String searchFilter, SortType sort, SortOrder sortOrder) throws IOException { + public Stream search(String gameVersion, RemoteModRepository.Category category, int pageOffset, int pageSize, String searchFilter, SortType sort, SortOrder sortOrder) throws IOException { List> facets = new ArrayList<>(); facets.add(Collections.singletonList("project_type:" + projectType)); if (StringUtils.isNotBlank(gameVersion)) { facets.add(Collections.singletonList("versions:" + gameVersion)); } + if (StringUtils.isNotBlank(category.getId())) { + facets.add(Collections.singletonList("categories:" + category.getId())); + } Map query = mapOf( pair("query", searchFilter), pair("facets", JsonUtils.UGLY_GSON.toJson(facets)), @@ -131,14 +134,52 @@ public final class ModrinthRemoteModRepository implements RemoteModRepository { return versions.stream().map(ProjectVersion::toVersion).flatMap(Lang::toStream); } - public List getCategoriesImpl() throws IOException { - return HttpRequest.GET(PREFIX + "/v2/tag/category").getJson(new TypeToken>() { - }.getType()); + public List getCategoriesImpl() throws IOException { + List categories = HttpRequest.GET(PREFIX + "/v2/tag/category").getJson(new TypeToken>() {}.getType()); + return categories.stream().filter(category -> category.getProjectType().equals(projectType)).collect(Collectors.toList()); } - public Stream getCategories() throws IOException { - return getCategoriesImpl().stream() - .map(name -> new Category(null, name, Collections.emptyList())); + @Override + public Stream getCategories() throws IOException { + return getCategoriesImpl().stream().map(Category::toCategory); + } + + public static class Category { + private final String icon; + + private final String name; + + @SerializedName("project_type") + private final String projectType; + + public Category() { + this("","",""); + } + + public Category(String icon, String name, String projectType) { + this.icon = icon; + this.name = name; + this.projectType = projectType; + } + + public String getIcon() { + return icon; + } + + public String getName() { + return name; + } + + public String getProjectType() { + return projectType; + } + + public RemoteModRepository.Category toCategory() { + return new RemoteModRepository.Category( + this, + name, + Collections.emptyList()); + } } public static class Project implements RemoteMod.IMod {