1111import net .neoforged .gradle .dsl .common .runs .run .RunManager ;
1212import net .neoforged .gradle .dsl .common .runs .type .RunTypeManager ;
1313import net .neoforged .gradle .dsl .common .runtime .tasks .Runtime ;
14- import net .neoforged .gradle .dsl .common .runtime .tasks .RuntimeArguments ;
1514import net .neoforged .gradle .dsl .common .runtime .tasks .tree .TaskTreeAdapter ;
1615import net .neoforged .gradle .dsl .common .tasks .WithOutput ;
1716import net .neoforged .gradle .dsl .common .util .CommonRuntimeUtils ;
@@ -62,7 +61,8 @@ public UserDevRuntimeExtension(Project project)
6261 "AdditionalDependenciesFor" + spec .getIdentifier ()
6362 );
6463
65- if (!useCombinedJarWithNeoForgeOnRecompile (spec )) {
64+ if (!useCombinedJarWithNeoForgeOnRecompile (spec ))
65+ {
6666 //Create the client-extra jar dependency.
6767 final Dependency clientExtraJar = spec .getProject ().getDependencies ().create (
6868 ExtraJarDependencyManager .generateClientCoordinateFor (spec .getMinecraftVersion ())
@@ -72,7 +72,9 @@ public UserDevRuntimeExtension(Project project)
7272 userDevAdditionalDependenciesConfiguration .getDependencies ().add (
7373 clientExtraJar
7474 );
75- } else {
75+ }
76+ else
77+ {
7678 userDevAdditionalDependenciesConfiguration .getDependencies ().addLater (
7779 userDevProfile .getUniversalJarArtifactCoordinate ().map (spec .getProject ().getDependencies ()::create )
7880 );
@@ -92,7 +94,7 @@ public UserDevRuntimeExtension(Project project)
9294 builder .withNeoFormDependency (userDevProfile .getNeoForm ().get ())
9395 .withDistributionType (DistributionType .JOINED )
9496 .withAdditionalDependencies (getProject ().files (userDevAdditionalDependenciesConfiguration ))
95- .withStepsMutator (this .adaptNeoFormRuntime (spec ));
97+ .withStepsMutator (this .adaptNeoFormRuntime (spec , userDevProfile , userDevJar ));
9698
9799 final FileTree accessTransformerFiles =
98100 userDevJar .matching (filter -> filter .include (userDevProfile .getAccessTransformerDirectory ().get () + "/**" ));
@@ -102,6 +104,7 @@ public UserDevRuntimeExtension(Project project)
102104 builder .withPostTaskAdapter ("patch" , createPatchAdapter (userDevJar , userDevProfile .getSourcePatchesDirectory ().get ()));
103105
104106 if (!useCombinedJarWithNeoForgeOnRecompile (spec ))
107+ {
105108 builder .withTaskCustomizer ("inject" , InjectZipContent .class , task -> {
106109 FileTree injectionDirectoryTree ;
107110 if (userDevProfile .getInjectedFilesDirectory ().isPresent ())
@@ -120,6 +123,7 @@ public UserDevRuntimeExtension(Project project)
120123 ConfigurationUtils .getArtifactProvider (getProject (), "NeoForgeRawLookupFor" + spec .getIdentifier (), userDevProfile .getUniversalJarArtifactCoordinate ())
121124 );
122125 });
126+ }
123127 });
124128
125129 spec .setMinecraftVersion (neoFormRuntimeDefinition .getSpecification ().getMinecraftVersion ());
@@ -133,7 +137,10 @@ public UserDevRuntimeExtension(Project project)
133137 );
134138 }
135139
136- private @ NotNull BiConsumer <List <NeoFormConfigConfigurationSpecV1 .Step >, Map <String , NeoFormConfigConfigurationSpecV1 .Function >> adaptNeoFormRuntime (final UserDevRuntimeSpecification spec )
140+ private @ NotNull BiConsumer <List <NeoFormConfigConfigurationSpecV1 .Step >, Map <String , NeoFormConfigConfigurationSpecV1 .Function >> adaptNeoFormRuntime (
141+ final UserDevRuntimeSpecification spec ,
142+ final UserdevProfile userDevProfile ,
143+ final FileTree userDevJar )
137144 {
138145 return (steps , functions ) -> {
139146 if (!useCombinedJarWithNeoForgeOnRecompile (spec ))
@@ -166,7 +173,11 @@ public UserDevRuntimeExtension(Project project)
166173 );
167174
168175 final Subsystems parchment = spec .getProject ().getExtensions ().getByType (Subsystems .class );
169- final SetupConfiguration configuration = buildSetupConfiguration ();
176+ final SetupConfiguration configuration = buildSetupConfiguration (
177+ spec ,
178+ userDevProfile ,
179+ userDevJar
180+ );
170181
171182 //Register the setup function:
172183 functions .put (
@@ -188,13 +199,15 @@ public UserDevRuntimeExtension(Project project)
188199 };
189200 }
190201
191- private record SetupConfiguration (List < String > arguments , Map < String , String > values ) {
192-
193- }
202+ private record SetupConfiguration (
203+ List < String > arguments ,
204+ Map < String , String > values ) { }
194205
195- private SetupConfiguration buildSetupConfiguration (UserDevRuntimeDefinition definition ) {
206+ private SetupConfiguration buildSetupConfiguration (UserDevRuntimeSpecification spec , final UserdevProfile userDevProfile , final FileTree userDevJar )
207+ {
196208 final Decompiler decompilerSubsystemConfiguration = getProject ().getExtensions ().getByType (Subsystems .class ).getDecompiler ();
197- if (decompilerSubsystemConfiguration .getIsDisabled ().get () && useCombinedJarWithNeoForgeOnRecompile (definition .getSpecification ())) {
209+ if (decompilerSubsystemConfiguration .getIsDisabled ().get () && useCombinedJarWithNeoForgeOnRecompile (spec ))
210+ {
198211 return new SetupConfiguration (
199212 List .of (
200213 "--task" , "PROCESS_MINECRAFT_JAR" ,
@@ -210,7 +223,10 @@ private SetupConfiguration buildSetupConfiguration(UserDevRuntimeDefinition defi
210223 "clientMappings" , "{downloadClientMappingsOutput}" ,
211224 "server" , "{downloadServerOutput}" ,
212225 "neoform" , "{neoform}" ,
213- "patches" , "{patches}"
226+ "patches" , userDevProfile .getBinaryPatchFile ()
227+ .map (patchFilePath -> userDevJar
228+ .matching (matcher -> matcher .include (patchFilePath ))
229+ .getSingleFile ()).get ().getAbsolutePath ()
214230 )
215231 );
216232 }
@@ -277,84 +293,17 @@ protected void afterRegistration(UserDevRuntimeDefinition runtime)
277293 );
278294 }
279295
280- private void bakeDefinition (UserDevRuntimeDefinition definition ) {
296+ private void bakeDefinition (UserDevRuntimeDefinition definition )
297+ {
281298 final Decompiler decompilerSubsystemConfiguration = this .getProject ().getExtensions ().getByType (Subsystems .class ).getDecompiler ();
282- if (decompilerSubsystemConfiguration .getIsDisabled ().get () && useCombinedJarWithNeoForgeOnRecompile (definition .getSpecification ())) {
283- final TaskProvider <? extends Runtime > binaryPatchedOutput = configureBinaryPatchMode (
284- definition ,
285- definition .getNeoFormRuntimeDefinition ().getTaskInputsByStepName (),
286- definition .getNeoFormRuntimeDefinition ().getBakedSteps ()
287- );
288-
289- binaryPatchedOutput .configure (task -> {
290- NeoFormRuntimeExtension .configureMcpRuntimeTaskWithDefaults (
291- definition .getNeoFormRuntimeDefinition (),
292- task ,
293- new NeoFormConfigConfigurationSpecV1 .Step ("binPatch" , "binPatch" , Map .of ())
294- );
295- });
296-
299+ if (decompilerSubsystemConfiguration .getIsDisabled ().get () && useCombinedJarWithNeoForgeOnRecompile (definition .getSpecification ()))
300+ {
297301 definition .getNeoFormRuntimeDefinition ().getRawJarTask ().configure (task -> {
298- task .getInput ().set (binaryPatchedOutput .flatMap (WithOutput ::getOutput ));
302+ task .getInput ().set (definition . getNeoFormRuntimeDefinition (). getTask ( "setup" ) .flatMap (WithOutput ::getOutput ));
299303 });
300304 }
301305 }
302306
303- private TaskProvider <? extends Runtime > configureBinaryPatchMode (
304- final UserDevRuntimeDefinition definition ,
305- final Map <String , Optional <TaskProvider <? extends WithOutput >>> taskInputsByStepName ,
306- final List <NeoFormConfigConfigurationSpecV1 .Step > steps ) {
307- final NeoFormConfigConfigurationSpecV1 .Step step = ListUtils .find (
308- steps , s -> s .getType ().equals ("decompile" )
309- );
310- if (step == null )
311- throw new IllegalArgumentException ("Could not find the decompile step!" );
312- final Provider <File > cleanFileProvider ;
313- Optional <TaskProvider <? extends WithOutput >> decompilerInputOptional = taskInputsByStepName .get ("decompile" );
314- TaskProvider <? extends Runtime > decompileTask = definition .getSpecification ().getProject ().getTasks ().named (
315- CommonRuntimeUtils .buildTaskName (definition .getNeoFormRuntimeDefinition (), "decompile" ),
316- Runtime .class
317- );
318- if (decompilerInputOptional != null && decompilerInputOptional .isPresent ()) {
319- cleanFileProvider = decompilerInputOptional .get ().flatMap (WithOutput ::getOutput )
320- .map (RegularFile ::getAsFile );
321- } else {
322- cleanFileProvider = decompileTask .map (Runtime ::getArguments )
323- .flatMap (arguments -> arguments .get ("input" ))
324- .map (File ::new );
325- }
326-
327- return definition .getSpecification ().getProject ().getTasks ().register (CommonRuntimeUtils .buildTaskName (definition .getSpecification (), "binaryPatch" ), DefaultExecute .class , task -> {
328- task .getExecutingJar ().fileProvider (ToolUtilities .resolveTool (
329- task .getProject (),
330- definition .getUserdevConfiguration ().getBinaryPatcher ()
331- .flatMap (UserdevProfile .ToolExecution ::getTool )
332- ));
333- task .getJvmArguments ().addAll (
334- definition .getUserdevConfiguration ().getBinaryPatcher ()
335- .flatMap (UserdevProfile .ToolExecution ::getJvmArguments )
336- );
337- task .getProgramArguments ().addAll (
338- definition .getUserdevConfiguration ().getBinaryPatcher ()
339- .flatMap (UserdevProfile .ToolExecution ::getArguments )
340- );
341-
342- task .getArguments ().putFile (
343- "clean" ,
344- cleanFileProvider
345- );
346- task .getArguments ().putFile (
347- "patch" ,
348- definition .getUserdevConfiguration ().getBinaryPatchFile ()
349- .map (patchFilePath -> definition .getUnpackedUserDevJarDirectory ()
350- .matching (matcher -> matcher .include (patchFilePath ))
351- .getSingleFile ())
352- );
353- });
354-
355- }
356-
357-
358307 @ Override
359308 protected UserDevRuntimeSpecification .Builder createBuilder ()
360309 {
0 commit comments