1111import net .neoforged .moddevgradle .internal .utils .VersionCapabilitiesInternal ;
1212import net .neoforged .nfrtgradle .CreateMinecraftArtifacts ;
1313import net .neoforged .nfrtgradle .DownloadAssets ;
14+ import net .neoforged .nfrtgradle .SplitMergedJar ;
1415import org .gradle .api .GradleException ;
1516import org .gradle .api .InvalidUserCodeException ;
1617import org .gradle .api .Named ;
2829import org .gradle .api .plugins .JavaPluginExtension ;
2930import org .gradle .api .provider .Provider ;
3031import org .gradle .api .tasks .SourceSet ;
32+ import org .gradle .api .tasks .SourceSetContainer ;
3133import org .gradle .api .tasks .TaskProvider ;
3234import org .gradle .jvm .toolchain .JavaLanguageVersion ;
3335import org .gradle .jvm .toolchain .JavaToolchainService ;
@@ -47,6 +49,7 @@ public record ModDevArtifactsWorkflow(
4749 TaskProvider <DownloadAssets > downloadAssets ,
4850 Configuration runtimeDependencies ,
4951 Configuration compileDependencies ,
52+ Configuration clientExtraCompileDependencies ,
5053 Provider <Directory > modDevBuildDir ,
5154 Provider <Directory > artifactsBuildDir ) {
5255
@@ -68,7 +71,8 @@ public static ModDevArtifactsWorkflow create(Project project,
6871 Configuration accessTransformers ,
6972 Configuration interfaceInjectionData ,
7073 VersionCapabilitiesInternal versionCapabilities ,
71- boolean disableRecompilation ) {
74+ boolean disableRecompilation ,
75+ boolean splitDist ) {
7276 if (project .getExtensions ().findByName (EXTENSION_NAME ) != null ) {
7377 throw new InvalidUserCodeException ("You cannot enable modding in the same project twice." );
7478 }
@@ -115,6 +119,8 @@ public static ModDevArtifactsWorkflow create(Project project,
115119 spec .getDependencies ().addLater (parchment .getParchmentArtifact ().map (dependencyFactory ::create ));
116120 });
117121
122+ Function <WorkflowArtifact , Provider <RegularFile >> artifactPathStrategy = artifact -> artifactsBuildDir .map (dir -> dir .file (artifactNamingStrategy .getFilename (artifact )));
123+
118124 // it has to contain client-extra to be loaded by FML, and it must be added to the legacy CP
119125 var createArtifacts = tasks .register ("createMinecraftArtifacts" , CreateMinecraftArtifacts .class , task -> {
120126 task .setGroup (branding .internalTaskGroup ());
@@ -151,8 +157,6 @@ public static ModDevArtifactsWorkflow create(Project project,
151157 task .getParchmentEnabled ().set (parchment .getEnabled ());
152158 task .getParchmentConflictResolutionPrefix ().set (parchment .getConflictResolutionPrefix ());
153159
154- Function <WorkflowArtifact , Provider <RegularFile >> artifactPathStrategy = artifact -> artifactsBuildDir .map (dir -> dir .file (artifactNamingStrategy .getFilename (artifact )));
155-
156160 task .getIncludeNeoForgeInGameJar ().set (versionCapabilities .needsNeoForgeInMinecraftJar ());
157161 task .getGameJarArtifact ().set (artifactPathStrategy .apply (WorkflowArtifact .COMPILED ));
158162 if (disableRecompilation ) {
@@ -185,6 +189,27 @@ public static ModDevArtifactsWorkflow create(Project project,
185189 task .getNeoFormArtifact ().set (moddingDependencies .neoFormDependencyNotation ());
186190 });
187191
192+ var splitMergedJar = tasks .register ("splitMergedJar" , SplitMergedJar .class , task -> {
193+ if (!splitDist ){
194+ throw new IllegalStateException ("Can't request split dist result when splitDist is disabled!" );
195+ }
196+ task .getClientResourcesJar ().set (createArtifacts .flatMap (CreateMinecraftArtifacts ::getResourcesArtifact ));
197+ task .getClientJar ().set (artifactPathStrategy .apply (WorkflowArtifact .CLIENT ));
198+ task .getCommonJar ().set (artifactPathStrategy .apply (WorkflowArtifact .COMMON ));
199+ if (!disableRecompilation ) {
200+ task .getMergedJar ().set (createArtifacts .flatMap (CreateMinecraftArtifacts ::getGameJarWithSourcesArtifact ));
201+ task .getClientSourcesJar ().set (artifactPathStrategy .apply (WorkflowArtifact .CLIENT_SOURCES ));
202+ task .getCommonSourcesJar ().set (artifactPathStrategy .apply (WorkflowArtifact .COMMON_SOURCES ));
203+ } else {
204+ task .getMergedJar ().set (createArtifacts .flatMap (CreateMinecraftArtifacts ::getGameJarArtifact ));
205+ }
206+
207+ });
208+
209+ if (splitDist ){
210+ ideIntegration .runTaskOnProjectSync (splitMergedJar );
211+ }
212+
188213 // For IntelliJ, we attach a combined sources+classes artifact which enables an "Attach Sources..." link for IJ users
189214 // Otherwise, attaching sources is a pain for IJ users.
190215 Provider <? extends Dependency > minecraftClassesDependency ;
@@ -218,13 +243,26 @@ public static ModDevArtifactsWorkflow create(Project project,
218243 config .setDescription ("The compile-time dependencies to develop a mod, including Minecraft and modding platform classes." );
219244 config .setCanBeResolved (false );
220245 config .setCanBeConsumed (false );
221- config .getDependencies ().addLater (minecraftClassesDependency );
246+ if (!splitDist ){
247+ config .getDependencies ().addLater (minecraftClassesDependency );
248+ } else {
249+ config .getDependencies ().addLater (splitMergedJar .map (task -> project .files (task .getCommonJar ())).map (dependencyFactory ::create ));
250+ }
222251 config .getDependencies ().add (moddingDependencies .gameLibrariesDependency ());
223252 if (!versionCapabilities .needsNeoForgeInMinecraftJar () && moddingDependencies .neoForgeDependency () != null ) {
224253 config .getDependencies ().add (moddingDependencies .neoForgeDependency ());
225254 }
226255 });
227256
257+ var clientExtraCompileDependencies = configurations .create ("modDevClientCompileDependencies" , config -> {
258+ config .setDescription ("The extra client compile-time dependencies to develop a mod, including Minecraft and modding platform classes." );
259+ config .setCanBeResolved (false );
260+ config .setCanBeConsumed (false );
261+ if (splitDist ){
262+ config .getDependencies ().addLater (splitMergedJar .map (task -> project .files (task .getClientJar ())).map (dependencyFactory ::create ));
263+ }
264+ });
265+
228266 // For IDEs that support it, link the source/binary artifacts if we use separated ones
229267 if (!disableRecompilation && !ideIntegration .shouldUseCombinedSourcesAndClassesArtifact ()) {
230268 ideIntegration .attachSources (
@@ -242,13 +280,22 @@ public static ModDevArtifactsWorkflow create(Project project,
242280 downloadAssets ,
243281 runtimeDependencies ,
244282 compileDependencies ,
283+ clientExtraCompileDependencies ,
245284 modDevBuildDir ,
246285 artifactsBuildDir );
247286
248287 project .getExtensions ().add (ModDevArtifactsWorkflow .class , EXTENSION_NAME , result );
249288
250289 for (var sourceSets : enabledSourceSets ) {
251- result .addToSourceSet (sourceSets );
290+ result .addToSourceSet (sourceSets , !splitDist );
291+ }
292+
293+ if (splitDist ){
294+ SourceSetContainer sourceSets = ExtensionUtils .getSourceSets (project );
295+ var main = sourceSets .getByName (SourceSet .MAIN_SOURCE_SET_NAME );
296+ SourceSet client = sourceSets .create ("client" );
297+ client .setCompileClasspath (client .getCompileClasspath ().plus (main .getOutput ()));
298+ result .addToSourceSet (client ,true );
252299 }
253300
254301 return result ;
@@ -351,14 +398,23 @@ private static List<Configuration> configureArtifactManifestConfigurations(
351398 * Adds the compile-time and runtime-dependencies needed to compile mod code to the source-set of the given name.
352399 */
353400 public void addToSourceSet (SourceSet sourceSet ) {
401+ addToSourceSet (sourceSet , true );
402+ }
403+
404+ public void addToSourceSet (SourceSet sourceSet , boolean includeClient ) {
354405 var configurations = project .getConfigurations ();
355406 var sourceSets = ExtensionUtils .getSourceSets (project );
356407 if (!sourceSets .contains (sourceSet )) {
357408 throw new GradleException ("Cannot add to the source set in another project: " + sourceSet );
358409 }
359410
360- configurations .getByName (sourceSet .getRuntimeClasspathConfigurationName ()).extendsFrom (runtimeDependencies );
361- configurations .getByName (sourceSet .getCompileClasspathConfigurationName ()).extendsFrom (compileDependencies );
411+ Configuration runtime = configurations .getByName (sourceSet .getRuntimeClasspathConfigurationName ());
412+ runtime .extendsFrom (runtimeDependencies );
413+ Configuration compile = configurations .getByName (sourceSet .getCompileClasspathConfigurationName ());
414+ compile .extendsFrom (compileDependencies );
415+ if (includeClient ) {
416+ compile .extendsFrom (clientExtraCompileDependencies );
417+ }
362418 }
363419
364420 public Provider <RegularFile > requestAdditionalMinecraftArtifact (String id , String filename ) {
0 commit comments