Skip to content

Commit

Permalink
Fix Modrinth update checking for Minecraft 1.0.0 and below
Browse files Browse the repository at this point in the history
  • Loading branch information
LostLuma committed Jul 11, 2024
1 parent 5ea125e commit b14ebe2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
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.contains("alpha.")) {
// Turn 1.0.0-alpha.2.3 into a1.2.3
return "a1." + version.split("alpha.", 2)[1];
} else if (version.contains("beta.")) {
// Turn 1.0.0-beta.7.3 into b1.7.3
return "b1." + version.split("beta.", 2)[1];
} 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;
}
}

0 comments on commit b14ebe2

Please sign in to comment.