diff --git a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java index 7680fffa9f..c6e3e8ea6d 100644 --- a/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java +++ b/buildSrc/src/main/java/net/neoforged/neodev/NeoDevBasePlugin.java @@ -1,9 +1,12 @@ package net.neoforged.neodev; import net.neoforged.minecraftdependencies.MinecraftDependenciesPlugin; +import net.neoforged.moddevgradle.internal.NeoDevFacade; import net.neoforged.nfrtgradle.CreateMinecraftArtifacts; +import net.neoforged.nfrtgradle.DownloadAssets; import org.gradle.api.Plugin; import org.gradle.api.Project; +import org.gradle.api.plugins.JavaPlugin; import org.gradle.api.tasks.Sync; public class NeoDevBasePlugin implements Plugin { @@ -12,13 +15,46 @@ public void apply(Project project) { // These plugins allow us to declare dependencies on Minecraft libraries needed to compile the official sources project.getPlugins().apply(MinecraftDependenciesPlugin.class); + var dependencyFactory = project.getDependencyFactory(); + var tasks = project.getTasks(); + var neoDevBuildDir = project.getLayout().getBuildDirectory().dir("neodev"); + + var extension = project.getExtensions().create(NeoDevExtension.NAME, NeoDevExtension.class); + var createSources = NeoDevPlugin.configureMinecraftDecompilation(project); + // Task must run on sync to have MC resources available for IDEA nondelegated builds. + NeoDevFacade.runTaskOnProjectSync(project, createSources); - project.getTasks().register("setup", Sync.class, task -> { + tasks.register("setup", Sync.class, task -> { task.setGroup(NeoDevPlugin.GROUP); task.setDescription("Replaces the contents of the base project sources with the unpatched, decompiled Minecraft source code."); task.from(project.zipTree(createSources.flatMap(CreateMinecraftArtifacts::getSourcesArtifact))); task.into(project.file("src/main/java/")); }); + + var downloadAssets = tasks.register("downloadAssets", DownloadAssets.class, task -> { + task.setGroup(NeoDevPlugin.INTERNAL_GROUP); + task.getNeoFormArtifact().set(createSources.flatMap(CreateMinecraftArtifacts::getNeoFormArtifact)); + task.getAssetPropertiesFile().set(neoDevBuildDir.map(dir -> dir.file("minecraft_assets.properties"))); + }); + + // MC looks for its resources on the classpath. + var runtimeClasspath = project.getConfigurations().getByName(JavaPlugin.RUNTIME_ONLY_CONFIGURATION_NAME); + runtimeClasspath.getDependencies().add( + dependencyFactory.create( + project.files(createSources.flatMap(CreateMinecraftArtifacts::getResourcesArtifact)) + ) + ); + NeoDevFacade.setupRuns( + project, + neoDevBuildDir, + extension.getRuns(), + // Pass an empty file collection for the userdev config. + // This will cause MDG to generate a dummy config suitable for vanilla. + project.files(), + modulePath -> {}, + legacyClasspath -> {}, + downloadAssets.flatMap(DownloadAssets::getAssetPropertiesFile) + ); } } diff --git a/projects/base/.gitignore b/projects/base/.gitignore index 1b10a46d0a..cb56563da3 100644 --- a/projects/base/.gitignore +++ b/projects/base/.gitignore @@ -1,3 +1,4 @@ src build .gradle +run diff --git a/projects/base/build.gradle b/projects/base/build.gradle index 1a1f878f9a..97f71e0bb5 100644 --- a/projects/base/build.gradle +++ b/projects/base/build.gradle @@ -13,3 +13,19 @@ dependencies { endorseStrictVersions() } } + +neoDev { + runs { + client { + client() + } + server { + server() + } + // Generated files are in run/generated + data { + data() + programArgument "--all" + } + } +}