Skip to content

Commit a1b3bfd

Browse files
shartteMatyrobbrtTechnici4n
authored
Imperative Configuration #200)
Co-authored-by: Matyrobbrt <[email protected]> Co-authored-by: Technici4n <[email protected]>
1 parent 19ebb9f commit a1b3bfd

37 files changed

+2147
-1091
lines changed

BREAKING_CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ please refer to the changelog, which can be found on the [project page](https://
66
The breaking changes in this major version should not affect most projects.
77
Nonetheless, every single breaking change is documented here, along with a suggested fix.
88

9+
- Modding now needs to be enabled before dependencies are made available, and the NeoForge/NeoForm versions will
10+
be fixed at the point in time when modding is enabled. Setting `neoForge.version` or `neoForge.neoFormVersion` will
11+
enable modding when those properties are set. For more advanced use cases, the `neoForge.enable { ... }` block can
12+
be used, i.e. to not enable modding for the `main` source set. You can only enable modding once for one version
13+
of NeoForge/NeoForm per project.
914
- Changes to access transformer and interface injection data publishing.
1015
- `accessTransformers.publish` and `interfaceInjectionData.publish` syntax was changed.
1116
- `accessTransformers.published` and `interfaceInjectionData.published` were removed.

LEGACY.md

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ plugins {
1313
id 'net.neoforged.moddev.legacyforge' version '2.0.28-beta'
1414
}
1515
16-
neoForge {
16+
legacyForge {
1717
// Develop against MinecraftForge version 47.3.0 for 1.20.1 (the versions can be found at https://files.minecraftforge.net/)
18-
version = "1.20.1-47.3.0"
18+
forgeVersion = "1.20.1-47.3.0"
1919
2020
// Validate AT files and raise errors when they have invalid targets
2121
// This option is false by default, but turning it on is recommended
@@ -91,6 +91,18 @@ obfuscation {
9191
}
9292
```
9393

94+
## Vanilla Mode
95+
96+
You can get dependencies for Vanilla Minecraft added to your project by using the `mcpVersion` property instead of
97+
setting the `forgeVersion` property.
98+
99+
```groovy
100+
legacyForge {
101+
// This adds Minecraft 1.20.1 as a dependency to the main source set.
102+
mcpVersion = "1.20.1"
103+
}
104+
```
105+
94106
## Mixins
95107

96108
You need to create so-called "refmaps" for Mixin, which convert the names you used to declare injection points and reference other parts of Minecraft code to the names used at runtime (SRG).
@@ -126,10 +138,10 @@ jar {
126138
}
127139
```
128140

129-
## Effects of applying the legacy plugin
130-
When applied, the legacy plugin will change the base NeoForm and NeoForge artifact coordinates of the `neoForge` extension to
131-
`de.oceanlabs.mcp:mcp_config` and `net.minecraftforge:forge`.
132-
It will also trigger the creation of various intermediary (SRG) to named (official) mapping files used by various parts of the toolchain, such as
133-
mod reobfuscation and runtime naming services.
141+
## Effects of enabling legacy forge modding
142+
143+
Enabling modding in the legacyForge extension triggers the creation of various intermediary (SRG) to named (official) mapping files used by various parts of the toolchain, such as
144+
mod reobfuscation and runtime naming services.
145+
134146
Reobfuscation to the intermediary mappings will automatically be configured for the `jar` task, the non-obfuscated jar will have a `-dev` classifier
135147
and will not be published in favour of the reobfuscated variant.

legacytest/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ java {
1212
}
1313
}
1414

15-
neoForge {
16-
neoFormVersion = '1.19.2'
15+
legacyForge {
16+
mcpVersion = '1.19.2'
1717
}
1818

1919
publishing {

legacytest/forge/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ dependencies {
3030
modImplementation('curse.maven:applied-energistics-2-223794:5641282')
3131
}
3232

33-
neoForge {
34-
version = '1.20.1-47.3.0'
33+
legacyForge {
34+
version = '1.20.1-47.3.12'
3535
runs {
3636
client {
3737
client()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package net.neoforged.moddevgradle.legacyforge.dsl;
2+
3+
import net.neoforged.moddevgradle.dsl.DataFileCollection;
4+
import net.neoforged.moddevgradle.dsl.ModDevExtension;
5+
import net.neoforged.moddevgradle.legacyforge.internal.LegacyForgeModDevPlugin;
6+
import org.gradle.api.Action;
7+
import org.gradle.api.Project;
8+
9+
import javax.inject.Inject;
10+
11+
/**
12+
* This is the top-level {@code legacyForge} extension, used to configure the moddev plugin.
13+
*/
14+
public abstract class LegacyForgeExtension extends ModDevExtension {
15+
private final Project project;
16+
17+
@Inject
18+
public LegacyForgeExtension(Project project,
19+
DataFileCollection accessTransformers,
20+
DataFileCollection interfaceInjectionData) {
21+
super(project, accessTransformers, interfaceInjectionData);
22+
this.project = project;
23+
}
24+
25+
/**
26+
* Enables modding for the main source-set using the given Forge version.
27+
* <p>
28+
* Shorthand for:
29+
* <code>
30+
* enable { forgeVersion = '...' }
31+
* </code>
32+
*/
33+
public void setVersion(String version) {
34+
enable(settings -> {
35+
settings.setForgeVersion(version);
36+
});
37+
}
38+
39+
/**
40+
* Enables modding for the main source-set in Vanilla-mode.
41+
* <p>
42+
* Shorthand for:
43+
* <code>
44+
* enable { mcpVersion = '...' }
45+
* </code>
46+
*/
47+
public void setMcpVersion(String version) {
48+
enable(settings -> {
49+
settings.setMcpVersion(version);
50+
});
51+
}
52+
53+
public void enable(Action<LegacyForgeModdingSettings> customizer) {
54+
var plugin = project.getPlugins().getPlugin(LegacyForgeModDevPlugin.class);
55+
56+
var settings = project.getObjects().newInstance(LegacyForgeModdingSettings.class);
57+
customizer.execute(settings);
58+
59+
plugin.enable(project, settings, this);
60+
}
61+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package net.neoforged.moddevgradle.legacyforge.dsl;
2+
3+
import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
4+
import org.gradle.api.Project;
5+
import org.gradle.api.tasks.SourceSet;
6+
import org.jetbrains.annotations.Nullable;
7+
8+
import javax.inject.Inject;
9+
import java.util.HashSet;
10+
import java.util.Set;
11+
12+
public abstract class LegacyForgeModdingSettings {
13+
@Nullable
14+
private String neoForgeVersion;
15+
16+
@Nullable
17+
private String forgeVersion;
18+
19+
@Nullable
20+
private String mcpVersion;
21+
22+
private Set<SourceSet> enabledSourceSets = new HashSet<>();
23+
24+
@Inject
25+
public LegacyForgeModdingSettings(Project project) {
26+
// By default, enable modding deps only for the main source set
27+
var sourceSets = ExtensionUtils.getSourceSets(project);
28+
var mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
29+
enabledSourceSets.add(mainSourceSet);
30+
}
31+
32+
public @Nullable String getNeoForgeVersion() {
33+
return neoForgeVersion;
34+
}
35+
36+
public @Nullable String getForgeVersion() {
37+
return forgeVersion;
38+
}
39+
40+
public @Nullable String getMcpVersion() {
41+
return mcpVersion;
42+
}
43+
44+
/**
45+
* NeoForge version number. You have to set either this, {@link #setForgeVersion} or {@link #setMcpVersion}.
46+
* Only NeoForge for Minecraft 1.20.1 is supported when using this plugin.
47+
*/
48+
public void setNeoForgeVersion(String version) {
49+
this.neoForgeVersion = version;
50+
}
51+
52+
/**
53+
* Minecraft Forge version. You have to set either this, {@link #setNeoForgeVersion} or {@link #setMcpVersion}.
54+
*/
55+
public void setForgeVersion(String version) {
56+
this.forgeVersion = version;
57+
}
58+
59+
/**
60+
* You can set this property to a version of <a href="https://maven.neoforged.net/#/releases/de/oceanlabs/mcp/mcp">MCP</a>
61+
* to either override the version used in the version of Forge you set, or to compile against
62+
* Vanilla artifacts that have no Forge code added.
63+
*/
64+
public void setMcpVersion(String version) {
65+
this.mcpVersion = version;
66+
}
67+
68+
/**
69+
* Contains the list of source sets for which access to Minecraft classes should be configured.
70+
* Defaults to the main source set, but can also be set to an empty list.
71+
*/
72+
73+
/**
74+
* Contains the list of source sets for which access to Minecraft classes should be configured.
75+
* Defaults to the main source set, but can also be set to an empty list.
76+
*/
77+
public Set<SourceSet> getEnabledSourceSets() {
78+
return enabledSourceSets;
79+
}
80+
81+
public void setEnabledSourceSets(Set<SourceSet> enabledSourceSets) {
82+
this.enabledSourceSets = enabledSourceSets;
83+
}
84+
}

src/legacy/java/net/neoforged/moddevgradle/legacyforge/dsl/Obfuscation.java renamed to src/legacy/java/net/neoforged/moddevgradle/legacyforge/dsl/ObfuscationExtension.java

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
import net.neoforged.moddevgradle.legacyforge.tasks.RemapOperation;
66
import org.apache.commons.lang3.StringUtils;
77
import org.gradle.api.Action;
8+
import org.gradle.api.InvalidUserCodeException;
89
import org.gradle.api.Project;
910
import org.gradle.api.artifacts.Configuration;
1011
import org.gradle.api.artifacts.ExternalModuleDependency;
1112
import org.gradle.api.artifacts.FileCollectionDependency;
1213
import org.gradle.api.artifacts.ProjectDependency;
1314
import org.gradle.api.component.AdhocComponentWithVariants;
1415
import org.gradle.api.file.FileCollection;
15-
import org.gradle.api.file.RegularFile;
16+
import org.gradle.api.file.RegularFileProperty;
1617
import org.gradle.api.plugins.JavaPlugin;
1718
import org.gradle.api.provider.Provider;
1819
import org.gradle.api.tasks.SourceSet;
@@ -23,41 +24,53 @@
2324
import javax.inject.Inject;
2425
import java.util.List;
2526

26-
public abstract class Obfuscation {
27+
public abstract class ObfuscationExtension {
2728
private final Project project;
28-
private final Provider<RegularFile> officialToSrg;
29-
private final Provider<RegularFile> mappingsCsv;
3029
private final Configuration autoRenamingToolRuntime;
3130
private final Configuration installerToolsRuntime;
3231
private final FileCollection extraMixinMappings;
3332

3433
@Inject
35-
public Obfuscation(Project project,
36-
Provider<RegularFile> officialToSrg,
37-
Provider<RegularFile> mappingsCsv,
38-
Configuration autoRenamingToolRuntime,
39-
Configuration installerToolsRuntime,
40-
FileCollection extraMixinMappings) {
34+
public ObfuscationExtension(Project project,
35+
Configuration autoRenamingToolRuntime,
36+
Configuration installerToolsRuntime,
37+
FileCollection extraMixinMappings) {
4138
this.project = project;
42-
this.officialToSrg = officialToSrg;
43-
this.mappingsCsv = mappingsCsv;
4439
this.autoRenamingToolRuntime = autoRenamingToolRuntime;
4540
this.installerToolsRuntime = installerToolsRuntime;
4641
this.extraMixinMappings = extraMixinMappings;
4742
}
4843

44+
private <T> Provider<T> assertConfigured(Provider<T> provider) {
45+
return provider.orElse(project.provider(() -> {
46+
throw new InvalidUserCodeException("Please enable modding by setting legacyForge.version or calling legacyForge.enable()");
47+
}));
48+
}
49+
50+
/**
51+
* Format is TSRG.
52+
*/
53+
@ApiStatus.Internal
54+
public abstract RegularFileProperty getNamedToSrgMappings();
55+
56+
/**
57+
* Format is a ZIP file containing CSV files with mapping data.
58+
*/
59+
@ApiStatus.Internal
60+
public abstract RegularFileProperty getSrgToNamedMappings();
61+
4962
@ApiStatus.Internal
5063
public void configureNamedToSrgOperation(RemapOperation operation) {
5164
operation.getToolType().set(RemapOperation.ToolType.ART);
5265
operation.getToolClasspath().from(autoRenamingToolRuntime);
53-
operation.getMappings().from(officialToSrg);
66+
operation.getMappings().from(assertConfigured(getNamedToSrgMappings()));
5467
}
5568

5669
@ApiStatus.Internal
5770
public void configureSrgToNamedOperation(RemapOperation operation) {
5871
operation.getToolType().set(RemapOperation.ToolType.INSTALLER_TOOLS);
5972
operation.getToolClasspath().from(installerToolsRuntime);
60-
operation.getMappings().from(mappingsCsv);
73+
operation.getMappings().from(assertConfigured(getSrgToNamedMappings()));
6174
}
6275

6376
/**
@@ -68,7 +81,8 @@ public void configureSrgToNamedOperation(RemapOperation operation) {
6881
* @return a provider of the created task
6982
*/
7083
public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar, SourceSet sourceSet) {
71-
return reobfuscate(jar, sourceSet, ignored -> {});
84+
return reobfuscate(jar, sourceSet, ignored -> {
85+
});
7286
}
7387

7488
/**
@@ -82,7 +96,6 @@ public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchive
8296
public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar,
8397
SourceSet sourceSet,
8498
Action<RemapJar> configuration) {
85-
8699
var reobf = project.getTasks().register("reobf" + StringUtils.capitalize(jar.getName()), RemapJar.class, task -> {
87100
task.getInput().set(jar.flatMap(AbstractArchiveTask::getArchiveFile));
88101
task.getDestinationDirectory().convention(task.getProject().getLayout().getBuildDirectory().dir("libs"));

0 commit comments

Comments
 (0)