Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@

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;
import org.gradle.api.plugins.ExtensionAware;
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;

Expand Down Expand Up @@ -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"))
);
}

/**
Expand Down Expand Up @@ -123,28 +131,28 @@ public void interfaceInjection(Object file) {
*
* @return The version of NeoForge to use.
*/
public abstract Property<String> 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<String> 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<Boolean> 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<String> getAdditionalDataGenMods();
public abstract ListProperty<@NotNull String> getAdditionalDataGenMods();

/**
* Adds a data gen mod to the project.
Expand All @@ -160,5 +168,15 @@ public void additionalDataGenMod(String mod) {
*
* @return Indicates whether the project is an FML library.
*/
public abstract Property<Boolean> getIsLibrary();
public abstract Property<@NotNull Boolean> getIsLibrary();

/**
* Defines the data generation runs to configure.
* Generally match up with the run types exposed by neoforge.
* <p>
* 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.
* </p>
* @return The data generation run.
*/
public abstract ListProperty<@NotNull String> getDataGenerationRuns();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> 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");
Expand Down Expand Up @@ -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<String> 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.
* <p>
Expand Down
33 changes: 33 additions & 0 deletions website/docs/03-guides/01-neoforge-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,36 @@ tableau {
```
</TabItem>
</Tabs>

## 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.

<Tabs groupId="gradle-code">
<TabItem value="groovy" label="Groovy">
```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.
}
}
```
</TabItem>
<TabItem value="kotlin" label="Kotlin">
```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.
}
}
```
</TabItem>
</Tabs>
Loading