Skip to content

Commit

Permalink
Configure imperatively
Browse files Browse the repository at this point in the history
  • Loading branch information
shartte committed Dec 15, 2024
1 parent 2f75594 commit 2ecd9d7
Show file tree
Hide file tree
Showing 36 changed files with 1,632 additions and 1,072 deletions.
6 changes: 4 additions & 2 deletions legacytest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ java {
}
}

neoForge {
neoFormVersion = '1.19.2'
legacyForge {
enableModding {
mcpVersion = '1.19.2'
}
}

publishing {
Expand Down
4 changes: 2 additions & 2 deletions legacytest/forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ dependencies {
modImplementation('curse.maven:applied-energistics-2-223794:5641282')
}

neoForge {
version = '1.20.1-47.3.0'
legacyForge {
version = '1.20.1-47.3.12'
runs {
client {
client()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

import net.neoforged.moddevgradle.dsl.DataFileCollection;
import net.neoforged.moddevgradle.internal.ModDevExtension;
import net.neoforged.moddevgradle.internal.utils.ExtensionUtils;
import net.neoforged.moddevgradle.legacyforge.internal.LegacyForgeModDevPlugin;
import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.tasks.SourceSet;

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

/**
* This is the top-level {@code legacyForge} extension, used to configure the moddev plugin.
*/
public abstract class LegacyForgeExtension extends ModDevExtension {
private final Project project;

private final Obfuscation obfuscation;

@Inject
public LegacyForgeExtension(Project project,
DataFileCollection accessTransformers,
DataFileCollection interfaceInjectionData,
Obfuscation obfuscation) {
super(project, accessTransformers, interfaceInjectionData);
this.project = project;
this.obfuscation = obfuscation;
}

public void setVersion(String version) {
enableModding(settings -> {
settings.setForgeVersion(version);
});
}

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

var settings = project.getObjects().newInstance(LegacyForgeModdingSettings.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);

plugin.enableModding(project, settings, this);
}

public Obfuscation getObfuscation() {
return obfuscation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.neoforged.moddevgradle.legacyforge.dsl;

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

public abstract class LegacyForgeModdingSettings {
@Nullable
private String neoForgeVersion;

private String forgeVersion;

@Nullable
private String mcpVersion;

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

public @Nullable String getForgeVersion() {
return forgeVersion;
}

public @Nullable String getMcpVersion() {
return mcpVersion;
}

/**
* NeoForge version number. You have to set either this, {@link #setForgeVersion} or {@link #setMcpVersion}.
* Only NeoForge for Minecraft 1.20.1 is supported when using this plugin.
*/
public void setNeoForgeVersion(String version) {
this.neoForgeVersion = version;
}

/**
* Minecraft Forge version. You have to set either this, {@link #setNeoForgeVersion} or {@link #setMcpVersion}.
*/
public void setForgeVersion(String version) {
this.forgeVersion = version;
}

/**
* You can set this property to a version of <a href="https://maven.neoforged.net/#/releases/de/oceanlabs/mcp/mcp">MCP</a>
* to either override the version used in the version of Forge you set, or to compile against
* Vanilla artifacts that have no Forge code added.
*/
public void setMcpVersion(String version) {
this.mcpVersion = 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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
import org.gradle.api.artifacts.ProjectDependency;
import org.gradle.api.component.AdhocComponentWithVariants;
import org.gradle.api.file.FileCollection;
import org.gradle.api.file.RegularFile;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
Expand All @@ -25,39 +24,45 @@

public abstract class Obfuscation {
private final Project project;
private final Provider<RegularFile> officialToSrg;
private final Provider<RegularFile> mappingsCsv;
private final Configuration autoRenamingToolRuntime;
private final Configuration installerToolsRuntime;
private final FileCollection extraMixinMappings;

@Inject
public Obfuscation(Project project,
Provider<RegularFile> officialToSrg,
Provider<RegularFile> mappingsCsv,
Configuration autoRenamingToolRuntime,
Configuration installerToolsRuntime,
FileCollection extraMixinMappings) {
this.project = project;
this.officialToSrg = officialToSrg;
this.mappingsCsv = mappingsCsv;
this.autoRenamingToolRuntime = autoRenamingToolRuntime;
this.installerToolsRuntime = installerToolsRuntime;
this.extraMixinMappings = extraMixinMappings;
}

/**
* Format is TSRG
*/
@ApiStatus.Internal
public abstract RegularFileProperty getNamedToSrgMappings();

/**
* Format is "mappings.csv"
*/
@ApiStatus.Internal
public abstract RegularFileProperty getSrgToNamedMappings();

@ApiStatus.Internal
public void configureNamedToSrgOperation(RemapOperation operation) {
operation.getToolType().set(RemapOperation.ToolType.ART);
operation.getToolClasspath().from(autoRenamingToolRuntime);
operation.getMappings().from(officialToSrg);
operation.getMappings().from(getNamedToSrgMappings().get());
}

@ApiStatus.Internal
public void configureSrgToNamedOperation(RemapOperation operation) {
operation.getToolType().set(RemapOperation.ToolType.INSTALLER_TOOLS);
operation.getToolClasspath().from(installerToolsRuntime);
operation.getMappings().from(mappingsCsv);
operation.getMappings().from(getSrgToNamedMappings().get());
}

/**
Expand All @@ -68,7 +73,8 @@ public void configureSrgToNamedOperation(RemapOperation operation) {
* @return a provider of the created task
*/
public TaskProvider<RemapJar> reobfuscate(TaskProvider<? extends AbstractArchiveTask> jar, SourceSet sourceSet) {
return reobfuscate(jar, sourceSet, ignored -> {});
return reobfuscate(jar, sourceSet, ignored -> {
});
}

/**
Expand Down
Loading

0 comments on commit 2ecd9d7

Please sign in to comment.