Skip to content

Commit

Permalink
Use latest fabric version
Browse files Browse the repository at this point in the history
The "stable" flag doesn't actually mean "stable," it just means recommended
  • Loading branch information
The Judge committed Oct 29, 2024
1 parent 1c97b75 commit a8771cf
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/pojlib/InstanceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static MinecraftInstances.Instance create(Activity activity, MinecraftIns
VersionInfo modLoaderVersionInfo = null;
switch (modLoader) {
case Fabric: {
FabricMeta.FabricVersion fabricVersion = FabricMeta.getLatestStableVersion();
FabricMeta.FabricVersion fabricVersion = FabricMeta.getLatestVersion();
assert fabricVersion != null;
modLoaderVersionInfo = FabricMeta.getVersionInfo(fabricVersion, minecraftVersion);
break;
Expand Down
37 changes: 34 additions & 3 deletions src/main/java/pojlib/install/FabricMeta.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.gson.annotations.SerializedName;
import pojlib.APIHandler;
import pojlib.util.Constants;
import pojlib.util.Version;

public class FabricMeta {

Expand All @@ -19,11 +20,41 @@ public static FabricVersion[] getVersions() {
return handler.get("versions/loader", FabricVersion[].class);
}

public static FabricVersion getLatestStableVersion() {
private static Version getVersionFromFabric(FabricVersion fabric) {
String[] verName = fabric.version.split("\\.");
if(verName.length < 3) {
return null;
}
int major = Integer.parseInt(verName[0]);
int minor = Integer.parseInt(verName[1]);
int patch = Integer.parseInt(verName[2]);

return new Version(major, minor, patch);
}

public static FabricVersion getLatestVersion() {
FabricVersion latest = null;
for (FabricVersion version : getVersions()) {
if (version.stable) return version;
if(latest == null) {
latest = version;
continue;
}

Version newVer = getVersionFromFabric(version);
Version latestVer = getVersionFromFabric(latest);

if(newVer == null || latestVer == null)
return null;

if(latestVer.major < newVer.major) {
latest = version;
} else if(latestVer.major == newVer.major && latestVer.minor < newVer.major) {
latest = version;
} else if(latestVer.major == newVer.major && latestVer.minor == newVer.major && latestVer.patch < newVer.patch) {
latest = version;
}
}
return null;
return latest;
}

public static VersionInfo getVersionInfo(FabricVersion fabricVersion, String minecraftVersion) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/pojlib/util/Version.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package pojlib.util;

public class Version {
public final int major, minor, patch;

public Version(int major, int minor, int patch) {
this.major = major;
this.minor = minor;
this.patch = patch;
}
}

0 comments on commit a8771cf

Please sign in to comment.