diff --git a/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java b/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java index 0eca1f1ce..2af4c05b4 100644 --- a/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java +++ b/common/src/main/java/net/neoforged/gradle/common/extensions/MinecraftArtifactCacheExtension.java @@ -93,11 +93,11 @@ public final Map cacheGameVersion(String gameVersion, Distri final Map result = new EnumMap<>(GameArtifact.class); - GameArtifact.VERSION_MANIFEST.doWhenRequired(side, () -> result.put(GameArtifact.VERSION_MANIFEST, this.cacheVersionManifest(resolvedVersion.getVersion()))); - GameArtifact.CLIENT_JAR.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_JAR, this.cacheVersionArtifact(resolvedVersion.getVersion(), DistributionType.CLIENT))); - GameArtifact.SERVER_JAR.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_JAR, this.cacheVersionArtifact(resolvedVersion.getVersion(), DistributionType.SERVER))); - GameArtifact.CLIENT_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_MAPPINGS, this.cacheVersionMappings(resolvedVersion.getVersion(), DistributionType.CLIENT))); - GameArtifact.SERVER_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_MAPPINGS, this.cacheVersionMappings(resolvedVersion.getVersion(), DistributionType.SERVER))); + GameArtifact.VERSION_MANIFEST.doWhenRequired(side, () -> result.put(GameArtifact.VERSION_MANIFEST, this.cacheVersionManifest(resolvedVersion))); + GameArtifact.CLIENT_JAR.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_JAR, this.cacheVersionArtifact(resolvedVersion, DistributionType.CLIENT))); + GameArtifact.SERVER_JAR.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_JAR, this.cacheVersionArtifact(resolvedVersion, DistributionType.SERVER))); + GameArtifact.CLIENT_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.CLIENT_MAPPINGS, this.cacheVersionMappings(resolvedVersion, DistributionType.CLIENT))); + GameArtifact.SERVER_MAPPINGS.doWhenRequired(side, () -> result.put(GameArtifact.SERVER_MAPPINGS, this.cacheVersionMappings(resolvedVersion, DistributionType.SERVER))); return result; } @@ -133,6 +133,10 @@ public final File cacheLauncherMetadata() { public final File cacheVersionManifest(String gameVersion) { final MinecraftVersionAndUrl resolvedVersion = resolveVersion(gameVersion); + return this.cacheVersionManifest(resolvedVersion); + } + + public final File cacheVersionManifest(MinecraftVersionAndUrl resolvedVersion) { final CacheFileSelector cacheFileSelector = CacheFileSelector.forVersionJson(resolvedVersion.getVersion()); return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionManifestToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion())); } @@ -145,6 +149,11 @@ public final File cacheVersionArtifact(String gameVersion, DistributionType side return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionArtifactToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side)); } + public final File cacheVersionArtifact(MinecraftVersionAndUrl resolvedVersion, DistributionType side) { + final CacheFileSelector cacheFileSelector = CacheFileSelector.forVersionJar(resolvedVersion.getVersion(), side.getName()); + return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionArtifactToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side)); + } + @Override public final File cacheVersionMappings(@NotNull String gameVersion, DistributionType side) { final MinecraftVersionAndUrl resolvedVersion = resolveVersion(gameVersion); @@ -153,6 +162,11 @@ public final File cacheVersionMappings(@NotNull String gameVersion, Distribution return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionMappingsToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side)); } + public final File cacheVersionMappings(@NotNull MinecraftVersionAndUrl resolvedVersion, DistributionType side) { + final CacheFileSelector cacheFileSelector = CacheFileSelector.forVersionMappings(resolvedVersion.getVersion(), side.getName()); + return this.cacheFiles.computeIfAbsent(cacheFileSelector, selector -> downloadVersionMappingsToCache(project, getCacheDirectory().get().getAsFile(), resolvedVersion.getVersion(), side)); + } + @Override public final File cache(final URL url, final CacheFileSelector selector) { return this.cache(url.toString(), selector); @@ -210,7 +224,7 @@ private File downloadVersionMappingsToCache(final Project project, final File ca private File doDownloadVersionDownloadToCache(Project project, File cacheDirectory, String minecraftVersion, final String artifact, final CacheFileSelector cacheFileSelector, final String potentialError) { final MinecraftVersionAndUrl minecraftVersionAndUrl = resolveVersion(minecraftVersion); - final File versionManifestFile = this.cacheVersionManifest(minecraftVersionAndUrl.getVersion()); + final File versionManifestFile = this.cacheVersionManifest(minecraftVersionAndUrl); try { JsonObject json = SerializationUtils.fromJson(versionManifestFile, JsonObject.class); diff --git a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/util/MinecraftVersionAndUrl.groovy b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/util/MinecraftVersionAndUrl.groovy index b0ebb29b6..39546883f 100644 --- a/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/util/MinecraftVersionAndUrl.groovy +++ b/dsl/common/src/main/groovy/net/neoforged/gradle/dsl/common/util/MinecraftVersionAndUrl.groovy @@ -24,9 +24,9 @@ class MinecraftVersionAndUrl { } /** - * The url to download the minecraft version from. + * The url to download the version manifest file for the minecraft version from. * - * @return The url to download the minecraft version from. + * @return The url to download the version manifest file for the minecraft version from */ String getUrl() { return url