Skip to content

Commit

Permalink
Do not version the asset directory
Browse files Browse the repository at this point in the history
Currently assets are written to .gradle/caches/minecraft/assets/$MCVER.
However, the asset store is content-addressed, and so can be shared
across versions. We drop the version suffix from the path to allow this.
  • Loading branch information
SquidDev committed Aug 15, 2024
1 parent cd10dca commit 738a52b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void configureRun(RunImpl run) {
protected void buildRunInterpolationData(RunImpl run, @NotNull MapProperty<String, String> interpolationData) {
interpolationData.put("runtime_name", specification.getVersionedName());
interpolationData.put("mc_version", specification.getMinecraftVersion());
interpolationData.put("assets_root", DownloadAssets.getAssetsDirectory(specification.getProject(), this.getVersionJson())
interpolationData.put("assets_root", DownloadAssets.getAssetsDirectory(specification.getProject())
.map(Directory::getAsFile)
.map(File::getAbsolutePath));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.neoforged.gradle.common.runtime.tasks;

import com.google.common.collect.Maps;
import net.neoforged.gradle.common.runtime.tasks.action.DownloadFileAction;
import net.neoforged.gradle.common.services.caching.CachedExecutionService;
import net.neoforged.gradle.common.services.caching.jobs.ICacheableJob;
import net.neoforged.gradle.common.util.FileCacheUtils;
import net.neoforged.gradle.dsl.common.tasks.WithWorkspace;
import net.neoforged.gradle.util.TransformerUtils;
import net.neoforged.gradle.common.runtime.tasks.action.DownloadFileAction;
import net.neoforged.gradle.common.util.SerializationUtils;
import net.neoforged.gradle.common.util.VersionJson;
import net.neoforged.gradle.dsl.common.tasks.WithWorkspace;
import net.neoforged.gradle.util.TransformerUtils;
import org.gradle.api.DefaultTask;
import org.gradle.api.Project;
import org.gradle.api.file.Directory;
Expand All @@ -35,7 +35,7 @@ public abstract class DownloadAssets extends DefaultTask implements WithWorkspac
private final Provider<Directory> assetsObjects;

public DownloadAssets() {
this.assetsCache = getAssetsDirectory(getProject(), getVersionJson());
this.assetsCache = getAssetsDirectory(getProject());
this.assetsObjects = assetsCache.map(directory -> directory.dir("objects"));

getAssetIndex().convention("asset-index");
Expand All @@ -47,8 +47,13 @@ public DownloadAssets() {
getIsOffline().convention(getProject().getGradle().getStartParameter().isOffline());
}

public static @NotNull Provider<Directory> getAssetsDirectory(final Project project) {
return FileCacheUtils.getAssetsCacheDirectory(project).map(TransformerUtils.ensureExists());
}

@Deprecated
public static @NotNull Provider<Directory> getAssetsDirectory(final Project project, final Provider<VersionJson> versionJsonProvider) {
return FileCacheUtils.getAssetsCacheDirectory(project).flatMap(assetsDir -> assetsDir.dir(versionJsonProvider.map(VersionJson::getId))).map(TransformerUtils.ensureExists());
return getAssetsDirectory(project);
}

protected Provider<File> getFileInAssetsDirectory(final String fileName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ private void configureRun(final Run run, final RuntimeDevRuntimeDefinition runti
);
});

Provider<String> assetsDir = DownloadAssets.getAssetsDirectory(project, runtimeDefinition.getVersionJson()).map(Directory::getAsFile).map(File::getAbsolutePath);
Provider<String> assetsDir = DownloadAssets.getAssetsDirectory(project).map(Directory::getAsFile).map(File::getAbsolutePath);
Provider<String> assetIndex = runtimeDefinition.getAssets().flatMap(DownloadAssets::getAssetIndex);

run.getArguments().addAll(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected void buildRunInterpolationData(RunImpl run, MapProperty<String, String
final String runtimeVersion = this.getClass().getPackage().getImplementationVersion();

interpolationData.put(InterpolationConstants.VERSION_NAME, getSpecification().getMinecraftVersion());
interpolationData.put(InterpolationConstants.ASSETS_ROOT, DownloadAssets.getAssetsDirectory(run.getProject(), getVersionJson()).map(Directory::getAsFile).map(File::getAbsolutePath));
interpolationData.put(InterpolationConstants.ASSETS_ROOT, DownloadAssets.getAssetsDirectory(run.getProject()).map(Directory::getAsFile).map(File::getAbsolutePath));
interpolationData.put(InterpolationConstants.ASSETS_INDEX_NAME, getAssets().flatMap(DownloadAssets::getAssetIndexFile).map(RegularFile::getAsFile).map(File::getName).map(s -> s.substring(0, s.lastIndexOf('.'))));
interpolationData.put(InterpolationConstants.AUTH_ACCESS_TOKEN, "0");
interpolationData.put(InterpolationConstants.USER_TYPE, "legacy");
Expand Down

0 comments on commit 738a52b

Please sign in to comment.