Skip to content
Draft
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 @@ -18,8 +18,9 @@ public abstract class LegacyForgeExtension extends ModDevExtension {
@Inject
public LegacyForgeExtension(Project project,
DataFileCollection accessTransformers,
DataFileCollection interfaceInjectionData) {
super(project, accessTransformers, interfaceInjectionData);
DataFileCollection interfaceInjectionData,
DataFileCollection enumExtensionsData) {
super(project, accessTransformers, interfaceInjectionData, enumExtensionsData);
this.project = project;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void apply(Project project) {
LegacyForgeExtension.class,
project,
dataFileCollections.accessTransformers().extension(),
dataFileCollections.interfaceInjectionData().extension());
dataFileCollections.interfaceInjectionData().extension(),
dataFileCollections.enumExtensionsData().extension());
}

public void enable(Project project, LegacyForgeModdingSettings settings, LegacyForgeExtension extension) {
Expand Down Expand Up @@ -153,6 +154,7 @@ public void enable(Project project, LegacyForgeModdingSettings settings, LegacyF
artifactNamingStrategy,
configurations.getByName(DataFileCollections.CONFIGURATION_ACCESS_TRANSFORMERS),
configurations.getByName(DataFileCollections.CONFIGURATION_INTERFACE_INJECTION_DATA),
configurations.getByName(DataFileCollections.CONFIGURATION_ENUM_EXTENSIONS_DATA),
versionCapabilities,
settings.isDisableRecompilation());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@ public abstract class ModDevExtension {
private final Project project;
private final DataFileCollection accessTransformers;
private final DataFileCollection interfaceInjectionData;
private final DataFileCollection enumExtensionsData;

@Inject
public ModDevExtension(Project project,
DataFileCollection accessTransformers,
DataFileCollection interfaceInjectionData) {
DataFileCollection interfaceInjectionData,
DataFileCollection enumExtensionsData) {
mods = project.container(ModModel.class);
runs = project.container(RunModel.class, name -> project.getObjects().newInstance(RunModel.class, name, project, mods));
parchment = project.getObjects().newInstance(Parchment.class);
this.project = project;
this.accessTransformers = accessTransformers;
this.interfaceInjectionData = interfaceInjectionData;
this.enumExtensionsData = enumExtensionsData;
getValidateAccessTransformers().convention(false);

// Make sync tasks run
Expand Down Expand Up @@ -88,6 +91,28 @@ public DataFileCollection getInterfaceInjectionData() {
public void setInterfaceInjectionData(Object... paths) {
getInterfaceInjectionData().getFiles().setFrom(paths);
}

/**
* The data-files describing additional enum extension declarations to be added to Minecraft enums.
* <p>
* <strong>This is an advanced property: Extending enums in your development environment using this property will not actually extend the enums in your published mod. You must register your enum extensions in your mod metadata for that.</strong>
*
* @see <a href="https://docs.neoforged.net/docs/advanced/extensibleenums/">Extensible Enums</a>
*/
public void enumExtensionsData(Action<DataFileCollection> action) {
action.execute(enumExtensionsData);
}

public DataFileCollection getEnumExtensionsData() {
return enumExtensionsData;
}

/**
* Replaces current enum extensions data files.
*/
public void setEnumExtensionsData(Object... paths) {
getEnumExtensionsData().getFiles().setFrom(paths);
}

/**
* Enable access transformer validation, raising fatal errors if an AT targets a member that doesn't exist.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public abstract class NeoForgeExtension extends ModDevExtension {
private final UnitTest unitTest;

@Inject
public NeoForgeExtension(Project project, DataFileCollection accessTransformers, DataFileCollection interfaceInjectionData) {
super(project, accessTransformers, interfaceInjectionData);
public NeoForgeExtension(Project project, DataFileCollection accessTransformers, DataFileCollection interfaceInjectionData, DataFileCollection enumExtensionsData) {
super(project, accessTransformers, interfaceInjectionData, enumExtensionsData);
this.project = project;
unitTest = project.getObjects().newInstance(UnitTest.class);
unitTest.getLoadedMods().convention(getMods());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
*/
@ApiStatus.Internal
public record DataFileCollections(CollectionWrapper accessTransformers,
CollectionWrapper interfaceInjectionData) {
CollectionWrapper interfaceInjectionData,
CollectionWrapper enumExtensionsData) {

public static final String CONFIGURATION_ACCESS_TRANSFORMERS = "accessTransformers";

public static final String CONFIGURATION_INTERFACE_INJECTION_DATA = "interfaceInjectionData";

public static final String CONFIGURATION_ENUM_EXTENSIONS_DATA = "enumExtensionsData";

/**
* Constructs the default data file collections for access transformers and intrface injection data
Expand Down Expand Up @@ -61,8 +64,14 @@ public static DataFileCollections create(Project project) {
CONFIGURATION_INTERFACE_INJECTION_DATA,
"Interface injection data adds extend/implements clauses for interfaces to Minecraft code at development time",
"interfaceinjection");

var enumExtensionsData = createCollection(
project,
CONFIGURATION_ENUM_EXTENSIONS_DATA,
"Enum extensions data adds new enum constants to Minecraft enums at development time",
"enumextensions");

return new DataFileCollections(accessTransformers, interfaceInjectionData);
return new DataFileCollections(accessTransformers, interfaceInjectionData, enumExtensionsData);
}
public record CollectionWrapper(DataFileCollection extension, Configuration configuration) {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static ModDevArtifactsWorkflow create(Project project,
ArtifactNamingStrategy artifactNamingStrategy,
Configuration accessTransformers,
Configuration interfaceInjectionData,
Configuration enumExtensionsData,
VersionCapabilitiesInternal versionCapabilities,
boolean disableRecompilation) {
if (project.getExtensions().findByName(EXTENSION_NAME) != null) {
Expand Down Expand Up @@ -147,6 +148,7 @@ public static ModDevArtifactsWorkflow create(Project project,
}
}));
task.getInterfaceInjectionData().from(interfaceInjectionData);
task.getEnumExtensionsData().from(enumExtensionsData);
task.getParchmentData().from(parchmentData);
task.getParchmentEnabled().set(parchment.getEnabled());
task.getParchmentConflictResolutionPrefix().set(parchment.getConflictResolutionPrefix());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public void apply(Project project) {
NeoForgeExtension.NAME,
NeoForgeExtension.class,
dataFileCollections.accessTransformers().extension(),
dataFileCollections.interfaceInjectionData().extension());
dataFileCollections.interfaceInjectionData().extension(),
dataFileCollections.enumExtensionsData().extension());
}

public void enable(
Expand Down Expand Up @@ -97,6 +98,7 @@ public void enable(
artifactNamingStrategy,
configurations.getByName(DataFileCollections.CONFIGURATION_ACCESS_TRANSFORMERS),
configurations.getByName(DataFileCollections.CONFIGURATION_INTERFACE_INJECTION_DATA),
configurations.getByName(DataFileCollections.CONFIGURATION_ENUM_EXTENSIONS_DATA),
versionCapabilities,
settings.isDisableRecompilation());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public CreateMinecraftArtifacts() {
@InputFiles
public abstract ConfigurableFileCollection getInterfaceInjectionData();

/**
* Files added to this collection will be passed to NFRT via the {@code --enum-extensions.data} command line option.
*/
@InputFiles
public abstract ConfigurableFileCollection getEnumExtensionsData();

/**
* If set to true, all files from {@link #getAccessTransformers()} are added as validated ATs and will fail the build
* if they contain errors, or they target non-existent code elements.
Expand Down Expand Up @@ -295,6 +301,11 @@ public void createArtifacts() {
args.add("--interface-injection-data");
args.add(interfaceInjectionFile.getAbsolutePath());
}

for (var enumExtensionsFile : getEnumExtensionsData().getFiles()) {
args.add("--enum-extensions-data");
args.add(enumExtensionsFile.getAbsolutePath());
}

if (getParchmentEnabled().get()) {
var parchmentData = getParchmentData().getFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,34 @@ public void testPublishInterfaceInjectionFile() throws IOException {
entry("publish-if-1.0-interfaceinjection3.json", "{}"));
}

@Test
public void testPublishEnumExtensionsFile() throws IOException {
writeProjectFile("enumextensions.json", "{}");
writeProjectFile("enumextensions/enumextensions.json", "{}");
Files.writeString(testProjectDir.toPath().resolve("enumextensions.json"), "{}");

publishDataFiles("test", "publish-if", "1.0", """
def generatedDataFile = tasks.register("generateDataFile") {
outputs.file("build/generatedDataFile.json")
doFirst {
outputs.files.singleFile.text = '{}'
}
}
neoForge {
enumExtensionsData {
publish(file('enumextensions.json'))
publish(file('subfolder/enumextensions.json'))
publish(generatedDataFile)
}
}
""");

assertThat(consumeDataFilePublication("enumExtensionsData", "test:publish-if:1.0")).containsOnly(
entry("publish-if-1.0-enumextensions1.json", "{}"),
entry("publish-if-1.0-enumextensions2.json", "{}"),
entry("publish-if-1.0-enumextensions3.json", "{}"));
}

@Test
public void testNoEmptyVariantsArePublished() throws IOException {
publishDataFiles("test", "publish-empty", "1.0", "");
Expand Down
Loading