Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Add Fabric loader version pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
comp500 committed Nov 6, 2020
1 parent 26fc4f7 commit 96e60d4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '2.0.1'
version = '2.1.0'
group = 'link.infra.jumploader' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'jumploader'

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
modGroup=link.infra.jumploader
modVersion=2.0.1
modVersion=2.1.0
modBaseName=jumploader
7 changes: 7 additions & 0 deletions src/main/java/link/infra/jumploader/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public class ConfigFile {
// Call this main class instead of the class determined by the source list
@Expose
public String overrideMainClass = null;
// TODO: Rewrite everything according to https://medium.com/@sdboyer/so-you-want-to-write-a-package-manager-4ae9c17d9527
// TODO: - all the metadata can be supplied with modpacks - as long as it's ensured that the files are downloaded from fabricmc/mojang
// Use this Fabric loader version, if possible, instead of the latest one
// This should be automatically set on first load to the version that is loaded, if it does not already exist
// Then, updating the Fabric loader version in a modpack is an explicit action - and is set by the modpack
@Expose
public String pinFabricLoaderVersion = null;

// Legacy config file detection
@Expose(serialize = false)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/link/infra/jumploader/Jumploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import java.util.Set;

public class Jumploader implements ITransformationService {
public static final String VERSION = "2.0.1";
public static final String VERSION = "2.1.0";
public static final String USER_AGENT = "Jumploader/" + VERSION;

private final Logger LOGGER = LogManager.getLogger();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,32 @@ public class FabricJarSource implements ResolvableJarSource<FabricJarSource.Fabr
public static class FabricInvalidationKey implements MetadataCacheHelper.InvalidationKey<FabricInvalidationKey> {
public final String gameVersion;
public final Side side;
public final String pinnedFabricVersion;

protected FabricInvalidationKey(String gameVersion, Side side) {
protected FabricInvalidationKey(String gameVersion, Side side, String pinnedFabricVersion) {
this.gameVersion = gameVersion;
this.side = side;
this.pinnedFabricVersion = pinnedFabricVersion;
}

@Override
public boolean isValid(FabricInvalidationKey key) {
return equals(key);
return equals(key) && key.pinnedFabricVersion != null;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FabricInvalidationKey that = (FabricInvalidationKey) o;
return gameVersion.equals(that.gameVersion) &&
side == that.side;
return Objects.equals(gameVersion, that.gameVersion) &&
side == that.side &&
Objects.equals(pinnedFabricVersion, that.pinnedFabricVersion);
}

@Override
public int hashCode() {
return Objects.hash(gameVersion, side);
return Objects.hash(gameVersion, side, pinnedFabricVersion);
}
}

Expand Down Expand Up @@ -84,13 +87,24 @@ public MetadataResolutionResult resolve(MetadataCacheHelper.MetadataCacheView ca
FabricMetadata meta;
meta = cacheView.getObject("fabric.json", FabricMetadata.class, () -> {
try {
URL loaderJsonUrl = new URI("https", "meta.fabricmc.net", "/v2/versions/loader/" + gameVersion, null).toURL();
JsonArray manifestData = RequestUtils.getJson(loaderJsonUrl).getAsJsonArray();
if (manifestData.size() == 0) {
throw new IOException("Failed to update configuration: no Fabric versions available!");
JsonObject latestLoaderData;
if (ctx.getConfigFile().pinFabricLoaderVersion != null) {
URL loaderJsonUrl = new URI("https", "meta.fabricmc.net", "/v2/versions/loader/" + gameVersion + "/" + ctx.getConfigFile().pinFabricLoaderVersion, null).toURL();
latestLoaderData = RequestUtils.getJson(loaderJsonUrl).getAsJsonObject();
} else {
URL loaderJsonUrl = new URI("https", "meta.fabricmc.net", "/v2/versions/loader/" + gameVersion, null).toURL();
JsonArray manifestData = RequestUtils.getJson(loaderJsonUrl).getAsJsonArray();
if (manifestData.size() == 0) {
throw new IOException("Failed to update configuration: no Fabric versions available!");
}
latestLoaderData = manifestData.get(0).getAsJsonObject();
}

if (ctx.getConfigFile().pinFabricLoaderVersion == null) {
ctx.getConfigFile().pinFabricLoaderVersion = latestLoaderData.getAsJsonObject("loader").get("version").getAsString();
ctx.getConfigFile().save();
}

JsonObject latestLoaderData = manifestData.get(0).getAsJsonObject();
JsonObject launcherMeta = latestLoaderData.getAsJsonObject("launcherMeta");
JsonObject mainClass = launcherMeta.getAsJsonObject("mainClass");

Expand Down Expand Up @@ -152,6 +166,6 @@ public Class<FabricInvalidationKey> getInvalidationKeyType() {

@Override
public FabricInvalidationKey getInvalidationKey(ResolutionContext ctx) {
return new FabricInvalidationKey(ctx.getLoadingVersion(), ctx.getLoadingSide());
return new FabricInvalidationKey(ctx.getLoadingVersion(), ctx.getLoadingSide(), ctx.getConfigFile().pinFabricLoaderVersion);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"id": "jumploader",
"version": "2.0.1",
"version": "2.1.0",

"name": "Jumploader",
"description": "Allows the use of Fabric mods in Twitch modpacks, by loading Fabric as if it were a Forge mod.",
Expand Down

0 comments on commit 96e60d4

Please sign in to comment.