Skip to content
Closed
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 @@ -5,7 +5,6 @@

/**
* The source of this attribute is the list of dependencies declared by the server and client Minecraft distributions.
* <p>
*
* @see <a href="https://github.com/neoforged/GradleMinecraftDependencies/blob/999449cc54c5c01fff1a66406be6e72872b75979/buildSrc/src/main/groovy/net/neoforged/minecraftdependencies/GenerateModuleMetadata.groovy#L83">GradleMinecraftDependencies project</a>
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.neoforged.moddevgradle.dsl;

import org.gradle.api.provider.ListProperty;
import org.gradle.api.tasks.SourceSet;
import org.jetbrains.annotations.Nullable;

public abstract class ModdingVersionSettings {
@Nullable
private String neoForgeVersion;

@Nullable
private String neoFormVersion;

public @Nullable String getNeoForgeVersion() {
return neoForgeVersion;
}

public @Nullable String getNeoFormVersion() {
return neoFormVersion;
}

/**
* NeoForge version number. You have to set either this or {@link #setNeoFormVersion}.
*/
public void setNeoForgeVersion(String version) {
this.neoForgeVersion = version;
}

/**
* You can set this property to a version of <a href="https://projects.neoforged.net/neoforged/neoform">NeoForm</a>
* to either override the version used in the version of NeoForge you set, or to compile against
* Vanilla artifacts that have no NeoForge code added.
*/
public void setNeoFormVersion(String version) {
this.neoFormVersion = version;
}

/**
* Contains the list of source sets for which access to Minecraft classes should be configured.
* Defaults to the main source set, but can also be set to an empty list.
*/
public abstract ListProperty<SourceSet> getEnabledSourceSets();
}
43 changes: 17 additions & 26 deletions src/main/java/net/neoforged/moddevgradle/dsl/NeoForgeExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import net.neoforged.moddevgradle.internal.ModDevPlugin;
import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
import org.gradle.api.Action;
import org.gradle.api.GradleException;
import org.gradle.api.InvalidUserCodeException;
import org.gradle.api.NamedDomainObjectContainer;
import org.gradle.api.Project;
import org.gradle.api.Task;
Expand All @@ -15,6 +15,7 @@

import javax.inject.Inject;
import java.io.File;
import java.util.List;

/**
* This is the top-level {@code neoForge} extension, used to configure the moddev plugin.
Expand Down Expand Up @@ -44,34 +45,24 @@ public NeoForgeExtension(Project project, DataFileCollection accessTransformers,
unitTest.getLoadedMods().convention(getMods());
}

/**
* Adds the necessary dependencies to develop a Minecraft mod to the given source set.
* The plugin automatically adds these dependencies to the main source set.
*/
public void addModdingDependenciesTo(SourceSet sourceSet) {
var configurations = project.getConfigurations();
var sourceSets = ExtensionUtils.getSourceSets(project);
if (!sourceSets.contains(sourceSet)) {
throw new GradleException("Cannot add to the source set in another project.");
}

configurations.getByName(sourceSet.getRuntimeClasspathConfigurationName())
.extendsFrom(configurations.getByName(ModDevPlugin.CONFIGURATION_RUNTIME_DEPENDENCIES));
configurations.getByName(sourceSet.getCompileClasspathConfigurationName())
.extendsFrom(configurations.getByName(ModDevPlugin.CONFIGURATION_COMPILE_DEPENDENCIES));
@Deprecated(forRemoval = true)
public void setVersion(Object any) {
throw new InvalidUserCodeException("Please use enableModding { neoForgeVersion = ... } instead of the version property.");
}

/**
* NeoForge version number. You have to set either this or {@link #getNeoFormVersion()}.
*/
public abstract Property<String> getVersion();
public void enableModding(Action<ModdingVersionSettings> customizer) {
var modDevPlugin = project.getPlugins().getPlugin(ModDevPlugin.class);

/**
* You can set this property to a version of <a href="https://projects.neoforged.net/neoforged/neoform">NeoForm</a>
* to either override the version used in the version of NeoForge you set, or to compile against
* Vanilla artifacts that have no NeoForge code added.
*/
public abstract Property<String> getNeoFormVersion();
var settings = project.getObjects().newInstance(ModdingVersionSettings.class);
// By default, enable modding deps only for the main source set
settings.getEnabledSourceSets().convention(project.provider(() -> {
var sourceSets = ExtensionUtils.getSourceSets(project);
return List.of(sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME));
}));
customizer.execute(settings);

modDevPlugin.enableModding(project, settings);
}

/**
* The list of additional access transformers that should be applied to the Minecraft source code.
Expand Down
Loading