diff --git a/modules/neogradle/src/main/java/com/ldtteam/tableau/extensions/NeoGradleExtension.java b/modules/neogradle/src/main/java/com/ldtteam/tableau/extensions/NeoGradleExtension.java index 57507a2..044cce4 100644 --- a/modules/neogradle/src/main/java/com/ldtteam/tableau/extensions/NeoGradleExtension.java +++ b/modules/neogradle/src/main/java/com/ldtteam/tableau/extensions/NeoGradleExtension.java @@ -2,7 +2,6 @@ import com.ldtteam.tableau.common.extensions.ProjectExtension; import com.ldtteam.tableau.common.extensions.VersioningExtension; -import com.ldtteam.tableau.neogradle.NeoGradlePlugin; import com.ldtteam.tableau.scripting.extensions.TableauScriptingExtension; import org.gradle.api.Project; import org.gradle.api.file.ConfigurableFileCollection; @@ -10,9 +9,11 @@ import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.bundling.Jar; +import org.jetbrains.annotations.NotNull; import javax.inject.Inject; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Map; @@ -84,6 +85,13 @@ public NeoGradleExtension(final Project project) { //Default to no additional data gen mods. getAdditionalDataGenMods().convention(new ArrayList<>()); + + //Default to the data generation runs defined in the property, if not set default to the current modern Minecraft run configuration. + getDataGenerationRuns().convention( + project.getProviders().gradleProperty("neoforge.data.runs").map( + s -> Arrays.stream(s.split(",")).toList() + ).orElse(List.of("clientData", "serverData")) + ); } /** @@ -123,28 +131,28 @@ public void interfaceInjection(Object file) { * * @return The version of NeoForge to use. */ - public abstract Property getNeoForgeVersion(); + public abstract Property<@NotNull String> getNeoForgeVersion(); /** * The classifier to use for the primary jar. * * @return The classifier for the primary jar. */ - public abstract Property getPrimaryJarClassifier(); + public abstract Property<@NotNull String> getPrimaryJarClassifier(); /** * Whether, to use random player names, when starting the client. * * @return Indicates whether the project should use random player names. */ - public abstract Property getUseRandomPlayerNames(); + public abstract Property<@NotNull Boolean> getUseRandomPlayerNames(); /** * The additional data gen mods to use. * * @return The additional data gen mods to use. */ - public abstract ListProperty getAdditionalDataGenMods(); + public abstract ListProperty<@NotNull String> getAdditionalDataGenMods(); /** * Adds a data gen mod to the project. @@ -160,5 +168,15 @@ public void additionalDataGenMod(String mod) { * * @return Indicates whether the project is an FML library. */ - public abstract Property getIsLibrary(); + public abstract Property<@NotNull Boolean> getIsLibrary(); + + /** + * Defines the data generation runs to configure. + * Generally match up with the run types exposed by neoforge. + *

+ * This is by default read from a gradle property `neoforge.runs.data`, if that is not supplied it is currently by default to clientData and serverData. + *

+ * @return The data generation run. + */ + public abstract ListProperty<@NotNull String> getDataGenerationRuns(); } diff --git a/modules/neogradle/src/main/java/com/ldtteam/tableau/neogradle/NeoGradleProjectPlugin.java b/modules/neogradle/src/main/java/com/ldtteam/tableau/neogradle/NeoGradleProjectPlugin.java index 425c4da..0bb9f2b 100644 --- a/modules/neogradle/src/main/java/com/ldtteam/tableau/neogradle/NeoGradleProjectPlugin.java +++ b/modules/neogradle/src/main/java/com/ldtteam/tableau/neogradle/NeoGradleProjectPlugin.java @@ -12,7 +12,9 @@ import javax.inject.Inject; +import net.neoforged.gradle.common.runs.run.RunImpl; import net.neoforged.gradle.dsl.common.extensions.sourceset.RunnableSourceSet; +import net.neoforged.gradle.dsl.common.runs.run.Run; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Rule; @@ -210,43 +212,12 @@ private void configureRuns(@NotNull Project target) { //Ensure a server run is created. runManager.maybeCreate("server"); - //Ensure a data gen run is created. - runManager.maybeCreate("data"); - - //Configure the data run to have the correct arguments. - runManager.named("data", run -> { - //Add the arguments for the data gen run. - //By default, these are the arguments for the main mod, its output directory, and the default existing resources' directory. - run.getArguments().addAll( - projectExtension.getModId().map(modId -> { - List dataRunArguments = new ArrayList<>(); - dataRunArguments.add("--mod"); - dataRunArguments.add(modId); - dataRunArguments.add("--all"); - dataRunArguments.add("--output"); - dataRunArguments.add(target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath()); - dataRunArguments.add("--existing"); - dataRunArguments.add(target.file("src/main/resources/").getAbsolutePath()); - return dataRunArguments; - }) - ); - - //Add the arguments for the additional data gen mods. - run.getArguments().addAll( - extension.getAdditionalDataGenMods().map(mods -> { - if (mods.isEmpty()) { - //When no additional data gen mods are set, we don't need to add any arguments. - return new ArrayList<>(); - } - - //When additional data gen mods are set, we need to add the arguments for each mod. - //Per mod, we need to add the "--existing-mod" argument followed by the mod id. - return mods.stream() - .flatMap(modId -> Stream.of("--existing-mod", modId)) - .collect(Collectors.toList()); - }) - ); - }); + //Ensure that all configured data runs are created. + runManager.addAllLater( + extension.getDataGenerationRuns().map(names -> names.stream() + .map(name -> createDataRun(target, runManager, projectExtension, extension, name)) + .toList()) + ); //Ensure a game test server run is created. runManager.maybeCreate("gameTestServer"); @@ -291,6 +262,46 @@ private void configureRuns(@NotNull Project target) { }); } + private static Run createDataRun(final @NotNull Project target, final RunManager runManager, final ProjectExtension projectExtension, final NeoGradleExtension extension, + final String runName) + { + final Run run = target.getObjects().newInstance(RunImpl.class, target, runName); + + //Add the arguments for the data gen run. + //By default, these are the arguments for the main mod, its output directory, and the default existing resources' directory. + run.getArguments().addAll( + projectExtension.getModId().map(modId -> { + List dataRunArguments = new ArrayList<>(); + dataRunArguments.add("--mod"); + dataRunArguments.add(modId); + dataRunArguments.add("--all"); + dataRunArguments.add("--output"); + dataRunArguments.add(target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath()); + dataRunArguments.add("--existing"); + dataRunArguments.add(target.file("src/main/resources/").getAbsolutePath()); + return dataRunArguments; + }) + ); + + //Add the arguments for the additional data gen mods. + run.getArguments().addAll( + extension.getAdditionalDataGenMods().map(mods -> { + if (mods.isEmpty()) { + //When no additional data gen mods are set, we don't need to add any arguments. + return new ArrayList<>(); + } + + //When additional data gen mods are set, we need to add the arguments for each mod. + //Per mod, we need to add the "--existing-mod" argument followed by the mod id. + return mods.stream() + .flatMap(modId -> Stream.of("--existing-mod", modId)) + .collect(Collectors.toList()); + }) + ); + + return run; + } + /** * Gets the library configuration for the given source set. *

diff --git a/website/docs/03-guides/01-neoforge-configuration.mdx b/website/docs/03-guides/01-neoforge-configuration.mdx index efd9d85..4e2ac6d 100644 --- a/website/docs/03-guides/01-neoforge-configuration.mdx +++ b/website/docs/03-guides/01-neoforge-configuration.mdx @@ -247,3 +247,36 @@ tableau { ``` + +## Configuring the runs which are used for data generation +Different versions of minecraft use different way of running data generation. +To be compatible with this, you can configure the data runs Tableau configures so it sets up the correct run types. + + + +```groovy title="build.gradle" +tableau { + neogradle { + //Any value is possible + dataGenerationRuns = ['data'] // for older versions of minecraft. + dataGenerationRuns = ['clientData'] // for newer versions of minecraft, when you only want a client data run. + dataGenerationRuns = ['clientData', 'serverData'] // for newer versions of minecraft, is also the default. + } +} +``` + + +```kotlin title="build.gradle.kts" +tableau { + neogradle { + //Any value is possible + dataGenerationRuns.add("data") // for older versions of minecraft. + dataGenerationRuns.add("clientData") // for newer versions of minecraft, when you only want a client data run. + + dataGenerationRuns.add("clientData") // for newer versions of minecraft, is also the default. + dataGenerationRuns.add("serverData") // for newer versions of minecraft, is also the default. + } +} +``` + +