Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getNeoFormVersion and getMcpVersion getters to make Kotlin happy. #223

Merged
merged 2 commits into from
Jan 7, 2025
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 @@ -3,8 +3,10 @@
import javax.inject.Inject;
import net.neoforged.moddevgradle.dsl.DataFileCollection;
import net.neoforged.moddevgradle.dsl.ModDevExtension;
import net.neoforged.moddevgradle.internal.ModDevArtifactsWorkflow;
import net.neoforged.moddevgradle.legacyforge.internal.LegacyForgeModDevPlugin;
import org.gradle.api.Action;
import org.gradle.api.InvalidUserCodeException;
import org.gradle.api.Project;

/**
Expand Down Expand Up @@ -49,6 +51,18 @@ public void setMcpVersion(String version) {
});
}

/**
* After enabling modding, you can retrieve the version of MCP you picked using this getter.
* This getter will throw if you have not enabled vanilla-mode yet.
*/
public String getMcpVersion() {
var dependencies = ModDevArtifactsWorkflow.get(project).dependencies();
if (dependencies.neoFormDependency() == null) {
throw new InvalidUserCodeException("You cannot retrieve the MCP version without setting it first.");
}
return dependencies.neoFormDependency().getVersion();
}

public void enable(Action<LegacyForgeModdingSettings> customizer) {
var plugin = project.getPlugins().getPlugin(LegacyForgeModDevPlugin.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void addModdingDependenciesTo(SourceSet sourceSet) {

/**
* After enabling modding, you can retrieve the version of the modding platform you picked using this getter.
* I.e. the NeoForge or Forge version. If you chose to enable vanilla-only mode, this getter returns null.
* I.e. the NeoForge or Forge version. If you chose to enable vanilla-only mode, this getter will throw.
*/
public String getVersion() {
var dependencies = ModDevArtifactsWorkflow.get(project).dependencies();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.neoforged.moddevgradle.dsl;

import javax.inject.Inject;
import net.neoforged.moddevgradle.internal.ModDevArtifactsWorkflow;
import net.neoforged.moddevgradle.internal.ModDevPlugin;
import org.gradle.api.Action;
import org.gradle.api.InvalidUserCodeException;
import org.gradle.api.Project;

/**
Expand Down Expand Up @@ -50,6 +52,19 @@ public void setNeoFormVersion(String version) {
});
}

/**
* After enabling modding, you can retrieve the version of NeoForm you picked using this getter.
* This is only meaningful if you have enabled vanilla-only mode or if you have overridden NeoForm for NeoForge.
* This getter throws if no NeoForm version was set.
*/
public String getNeoFormVersion() {
var dependencies = ModDevArtifactsWorkflow.get(project).dependencies();
if (dependencies.neoFormDependency() == null) {
throw new InvalidUserCodeException("You cannot retrieve the NeoForm version without setting it first.");
}
return dependencies.neoFormDependency().getVersion();
}

public void enable(Action<ModdingVersionSettings> customizer) {
var modDevPlugin = project.getPlugins().getPlugin(ModDevPlugin.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void testEnable() {
@Test
void testGetVersion() {
extension.setNeoFormVersion(VERSION);
assertEquals(VersionCapabilitiesInternal.ofNeoFormVersion(VERSION), extension.getVersionCapabilities());
assertEquals(VERSION, extension.getNeoFormVersion());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.neoforged.moddevgradle.legacyforge;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.Set;
Expand Down Expand Up @@ -57,6 +58,12 @@ void testEnableVanillaOnlyMode() {
"build/moddev/artifacts/vanilla-1.17.1-client-extra-aka-minecraft-resources.jar",
"de.oceanlabs.mcp:mcp_config:1.17.1[net.neoforged:neoform-dependencies]",
"build/moddev/artifacts/intermediateToNamed.zip");
assertEquals("1.17.1", extension.getMcpVersion());
}

@Test
void testGetMcpVersionThrowsBeforeEnabling() {
assertThrows(InvalidUserCodeException.class, extension::getMcpVersion);
}

@Test
Expand Down
Loading