Skip to content

Commit

Permalink
Add Vanilla runs in NeoForge development environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Technici4n committed Nov 22, 2024
1 parent 16b2d4d commit 174a5ab
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<Project> {
Expand All @@ -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)
);
}
}
1 change: 1 addition & 0 deletions projects/base/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
src
build
.gradle
run
16 changes: 16 additions & 0 deletions projects/base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,19 @@ dependencies {
endorseStrictVersions()
}
}

neoDev {
runs {
client {
client()
}
server {
server()
}
// Generated files are in run/generated
data {
data()
programArgument "--all"
}
}
}

0 comments on commit 174a5ab

Please sign in to comment.