Skip to content

Commit

Permalink
add downloadMojangMappings task
Browse files Browse the repository at this point in the history
  • Loading branch information
supersaiyansubtlety committed Nov 27, 2024
1 parent d5b8b3e commit c38bfc4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface Extensions {
String UNPICK = Constants.UNPICK_NAME;
String GZ = "gz";
String JSON = "json";
String TXT = "txt";
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import quilt.internal.task.VersionParserConsumingTask;
import quilt.internal.task.setup.DownloadMinecraftJarsTask;
import quilt.internal.task.setup.DownloadMinecraftLibrariesTask;
import quilt.internal.task.setup.DownloadMojangMappingsTask;
import quilt.internal.task.setup.DownloadWantedVersionManifestTask;
import quilt.internal.task.setup.ExtractServerJarTask;
import quilt.internal.task.setup.MergeJarsTask;
Expand Down Expand Up @@ -98,9 +99,9 @@ protected MinecraftJarsExtension applyImpl(@NotNull Project project) {
downloadMinecraftJars.flatMap(DownloadMinecraftJarsTask::getServerBootstrapJar)
);

task.getExtractionDest().convention(
this.provideMinecraftBuildFile(quiltExt.provideSuffixedMinecraftVersion("-server." + Extensions.JAR))
);
task.getExtractionDest().convention(this.provideMinecraftBuildFile(
quiltExt.provideSuffixedMinecraftVersion("-server." + Extensions.JAR)
));
}
);

Expand All @@ -112,9 +113,9 @@ protected MinecraftJarsExtension applyImpl(@NotNull Project project) {

task.getServerJar().convention(extractServerJar.flatMap(ExtractServerJarTask::getExtractionDest));

task.getMergedFile().convention(
this.provideMinecraftBuildFile(quiltExt.provideSuffixedMinecraftVersion("-merged." + Extensions.JAR))
);
task.getMergedFile().convention(this.provideMinecraftBuildFile(
quiltExt.provideSuffixedMinecraftVersion("-merged." + Extensions.JAR)
));
}
);

Expand All @@ -126,6 +127,20 @@ protected MinecraftJarsExtension applyImpl(@NotNull Project project) {
}
);

tasks.register(
DownloadMojangMappingsTask.DOWNLOAD_MOJANG_MAPPINGS_TASK_NAME,
DownloadMojangMappingsTask.class,
task -> {
task.getClientMappings().convention(
this.getMinecraftBuildDir().map(dir -> dir.file("client." + Extensions.TXT))
);

task.getServerMappings().convention(
this.getMinecraftBuildDir().map(dir -> dir.file("server." + Extensions.TXT))
);
}
);

return project.getExtensions().create(
MinecraftJarsExtension.NAME, MinecraftJarsExtension.class,
new Tasks(mergeJars, downloadMinecraftLibraries)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package quilt.internal.task.setup;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.quiltmc.launchermeta.version.v1.Downloads;
import quilt.internal.constants.Groups;
import quilt.internal.plugin.MinecraftJarsPlugin;
import quilt.internal.task.VersionParserConsumingTask;
import quilt.internal.util.DownloadUtil;

/**
* Downloads Mojang's client and server mappings for the passed {@linkplain #getVersionParser version}.
*
* @see <a href=https://minecraft.wiki/w/Obfuscation_map>Obfuscation map</a>
* @see MinecraftJarsPlugin MinecraftJarsPlugin's configureEach
*/
public abstract class DownloadMojangMappingsTask extends DefaultTask implements VersionParserConsumingTask {
/**
* {@linkplain org.gradle.api.tasks.TaskContainer#register Registered} by
* {@link MinecraftJarsPlugin MinecraftJarsPlugin}.
*/
public static final String DOWNLOAD_MOJANG_MAPPINGS_TASK_NAME = "downloadMojangMappings";

@OutputFile
public abstract RegularFileProperty getClientMappings();

@OutputFile
public abstract RegularFileProperty getServerMappings();

public DownloadMojangMappingsTask() {
this.setGroup(Groups.SETUP);
}

@TaskAction
public void download() {
final Downloads downloads = this.getVersionParser().get().get().getDownloads();

downloads.getClientMappings().ifPresentOrElse(
clientMappings -> DownloadUtil.download(
clientMappings.getUrl(),
this.getClientMappings().get().getAsFile(),
false, this.getLogger()
),
() -> this.getLogger().warn("No client mappings available")
);

downloads.getServerMappings().ifPresentOrElse(
serverMappings -> DownloadUtil.download(
serverMappings.getUrl(),
this.getServerMappings().get().getAsFile(),
false, this.getLogger()
),
() -> this.getLogger().warn("No server mappings available")
);
}
}

0 comments on commit c38bfc4

Please sign in to comment.