|
3 | 3 | import net.neoforged.moddevgradle.internal.ModDevPlugin; |
4 | 4 | import net.neoforged.moddevgradle.internal.utils.ExtensionUtils; |
5 | 5 | import org.gradle.api.Action; |
6 | | -import org.gradle.api.GradleException; |
| 6 | +import org.gradle.api.InvalidUserCodeException; |
7 | 7 | import org.gradle.api.NamedDomainObjectContainer; |
8 | 8 | import org.gradle.api.Project; |
9 | 9 | import org.gradle.api.Task; |
|
15 | 15 |
|
16 | 16 | import javax.inject.Inject; |
17 | 17 | import java.io.File; |
| 18 | +import java.util.List; |
18 | 19 |
|
19 | 20 | /** |
20 | 21 | * This is the top-level {@code neoForge} extension, used to configure the moddev plugin. |
@@ -44,34 +45,31 @@ public NeoForgeExtension(Project project, DataFileCollection accessTransformers, |
44 | 45 | unitTest.getLoadedMods().convention(getMods()); |
45 | 46 | } |
46 | 47 |
|
47 | | - /** |
48 | | - * Adds the necessary dependencies to develop a Minecraft mod to the given source set. |
49 | | - * The plugin automatically adds these dependencies to the main source set. |
50 | | - */ |
51 | | - public void addModdingDependenciesTo(SourceSet sourceSet) { |
52 | | - var configurations = project.getConfigurations(); |
53 | | - var sourceSets = ExtensionUtils.getSourceSets(project); |
54 | | - if (!sourceSets.contains(sourceSet)) { |
55 | | - throw new GradleException("Cannot add to the source set in another project."); |
56 | | - } |
57 | | - |
58 | | - configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName()) |
59 | | - .extendsFrom(configurations.getByName(ModDevPlugin.CONFIGURATION_RUNTIME_DEPENDENCIES)); |
60 | | - configurations.getByName(sourceSet.getCompileClasspathConfigurationName()) |
61 | | - .extendsFrom(configurations.getByName(ModDevPlugin.CONFIGURATION_COMPILE_DEPENDENCIES)); |
| 48 | + @Deprecated(forRemoval = true) |
| 49 | + public void setVersion(Object any) { |
| 50 | + throw new InvalidUserCodeException("Please use enableModding { neoForgeVersion = ... } instead of the version property."); |
62 | 51 | } |
63 | 52 |
|
64 | | - /** |
65 | | - * NeoForge version number. You have to set either this or {@link #getNeoFormVersion()}. |
66 | | - */ |
67 | | - public abstract Property<String> getVersion(); |
| 53 | + public void enableModding(Action<ModdingVersionSettings> customizer) { |
| 54 | + var modDevPlugin = project.getPlugins().getPlugin(ModDevPlugin.class); |
68 | 55 |
|
69 | | - /** |
70 | | - * You can set this property to a version of <a href="https://projects.neoforged.net/neoforged/neoform">NeoForm</a> |
71 | | - * to either override the version used in the version of NeoForge you set, or to compile against |
72 | | - * Vanilla artifacts that have no NeoForge code added. |
73 | | - */ |
74 | | - public abstract Property<String> getNeoFormVersion(); |
| 56 | + var settings = project.getObjects().newInstance(ModdingVersionSettings.class); |
| 57 | + // By default enable modding deps only for the main source set |
| 58 | + settings.getEnabledSourceSets().convention(project.provider(() -> { |
| 59 | + var sourceSets = ExtensionUtils.getSourceSets(project); |
| 60 | + return List.of(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME)); |
| 61 | + })); |
| 62 | + customizer.execute(settings); |
| 63 | + |
| 64 | + var versions = settings.toImmutable(); |
| 65 | + |
| 66 | + modDevPlugin.enableModding( |
| 67 | + project, |
| 68 | + settings.getEnabledSourceSets().get(), |
| 69 | + versions.neoForgeVersion(), |
| 70 | + versions.neoFormVersion() |
| 71 | + ); |
| 72 | + } |
75 | 73 |
|
76 | 74 | /** |
77 | 75 | * The list of additional access transformers that should be applied to the Minecraft source code. |
|
0 commit comments