Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Modrinth update checking for Minecraft 1.0.0 and below #18

Open
wants to merge 1 commit into
base: 1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -11,7 +11,6 @@
import com.terraformersmc.modmenu.config.ModMenuConfig;
import com.terraformersmc.modmenu.util.mod.Mod;
import com.terraformersmc.modmenu.util.mod.ModrinthUpdateInfo;
import net.fabricmc.loader.api.FabricLoader;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.RequestBuilder;
Expand Down Expand Up @@ -211,8 +210,7 @@ private static UpdateChannel getUpdateChannel(String versionType) {
}

private static @Nullable Map<String, VersionUpdate> getUpdatedVersions(Collection<String> modHashes) {
String mcVer = FabricLoader.getInstance().getModContainer("minecraft").get()
.getMetadata().getVersion().getFriendlyString();
String mcVer = VersionUtil.getModrinthCompatibleMcVersion();
List<String> loaders = ModMenu.runningQuilt ? Arrays.asList("fabric", "quilt") : Arrays.asList("fabric");

List<UpdateChannel> updateChannels;
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/terraformersmc/modmenu/util/VersionUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.terraformersmc.modmenu.util;

import net.fabricmc.loader.api.FabricLoader;

import java.util.Arrays;
import java.util.List;

Expand Down Expand Up @@ -27,4 +29,24 @@ public static String getPrefixedVersion(String version) {
public static String removeBuildMetadata(String version) {
return version.split("\\+")[0];
}

/**
* @return a Modrinth API-compatible Minecraft version string.
*/
public static String getModrinthCompatibleMcVersion() {
String version = FabricLoader.getInstance().getModContainer("minecraft").get()
.getMetadata().getVersion().getFriendlyString();

if (version.startsWith("1.0.0-alpha.")) {
// Turn 1.0.0-alpha.2.3 into a1.2.3
return "a1." + version.substring(12);
} else if (version.startsWith("1.0.0-beta.")) {
// Turn 1.0.0-beta.7.3 into b1.7.3
return "b1." + version.substring(11);
} else if (version.equals("1.0.0")) {
return "1.0"; // 1.0.0 is the only release with an extra following zero for some reason ...
}

return version;
}
}
Loading