Skip to content

Commit

Permalink
Add generation of neoforge.mod.toml for API.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Nov 25, 2024
1 parent e098ad3 commit fd527cf
Show file tree
Hide file tree
Showing 9 changed files with 337 additions and 78 deletions.
25 changes: 25 additions & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import lambdynamiclights.Constants
import lambdynamiclights.data.Nmt
import lambdynamiclights.task.GenerateNmtTask

plugins {
id("lambdynamiclights")
Expand All @@ -22,6 +24,29 @@ tasks.generateFmj.configure {
}
}

val generateNmt = tasks.register("generateNmt", GenerateNmtTask::class) {
this.nmt.set(tasks.generateFmj.flatMap {
it.fmj.map { fmj ->
fmj.derive(::Nmt)
.withLoaderVersion("[2,)")
.withDepend("minecraft", "[" + libs.versions.minecraft.get() + ",)")
}
})
outputDir.set(project.file("build/generated/generated_resources/"))
}

tasks.generateFmj.configure {
dependsOn(generateNmt)
}

tasks.ideaSyncTask.configure {
dependsOn(generateNmt)
}

tasks.getByName("sourcesJar") {
dependsOn(generateNmt)
}

val mojmap by sourceSets.creating {}

java {
Expand Down
4 changes: 2 additions & 2 deletions api/moj_xplat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ apiProject.artifacts.add("mojmapRuntimeElements", tasks.remapJar) {
classifier = "mojmap"
}

val remapMojmapSourcesTask = tasks.register("remapMojmapSourcesJar", RemapSourcesJarTask::class) {
tasks.remapSourcesJar {
val remapJar = apiProject.tasks.named("remapSourcesJar", RemapSourcesJarTask::class)
dependsOn(remapJar)

Expand All @@ -55,6 +55,6 @@ val remapMojmapSourcesTask = tasks.register("remapMojmapSourcesJar", RemapSource
apiProject.configurations["mojmapSourcesElements"].artifacts.removeIf {
true
}
apiProject.artifacts.add("mojmapSourcesElements", remapMojmapSourcesTask) {
apiProject.artifacts.add("mojmapSourcesElements", tasks.remapSourcesJar) {
classifier = "mojmap-sources"
}
43 changes: 43 additions & 0 deletions build_logic/src/main/java/lambdynamiclights/data/Contact.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package lambdynamiclights.data;

import java.io.Serializable;

public final class Contact implements Serializable {
private String homepage;
private String sources;
private String issues;

public Contact withHomepage(String homepage) {
this.homepage = homepage;
return this;
}

public Contact withSources(String sources) {
this.sources = sources;
return this;
}

public Contact withIssues(String issues) {
this.issues = issues;
return this;
}

public String homepage() {
return this.homepage;
}

public String sources() {
return this.sources;
}

public String issues() {
return this.issues;
}

public Contact copy() {
return new Contact()
.withHomepage(this.homepage)
.withSources(this.sources)
.withIssues(this.issues);
}
}
54 changes: 2 additions & 52 deletions build_logic/src/main/java/lambdynamiclights/data/Fmj.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
import java.util.function.Consumer;

public final class Fmj extends ModBase<Fmj> {
private final String version;
private final List<String> authors = new ArrayList<>();
private Contact contact;
private String license;
private String environment;
private final Map<String, List<String>> entrypoints = new LinkedHashMap<>();
private String accessWidener;
Expand All @@ -25,32 +21,7 @@ public final class Fmj extends ModBase<Fmj> {
private final Map<String, Object> custom = new LinkedHashMap<>();

public Fmj(String namespace, String name, String version) {
super(namespace, name);
this.version = version;
}

public Fmj withAuthors(List<String> authors) {
this.authors.addAll(authors);
return this;
}

public Fmj withAuthors(String... authors) {
return this.withAuthors(Arrays.asList(authors));
}

private Contact useContact() {
if (this.contact == null) this.contact = new Contact();
return this.contact;
}

public Fmj withContact(Consumer<Contact> action) {
action.accept(this.useContact());
return this;
}

public Fmj withLicense(String license) {
this.license = license;
return this;
super(namespace, name, version);
}

public Fmj withEnvironment(String environment) {
Expand Down Expand Up @@ -98,27 +69,6 @@ public Fmj withModMenu(Consumer<ModMenu> action) {
return this;
}

public static final class Contact implements Serializable {
private String homepage;
private String sources;
private String issues;

public Contact withHomepage(String homepage) {
this.homepage = homepage;
return this;
}

public Contact withSources(String sources) {
this.sources = sources;
return this;
}

public Contact withIssues(String issues) {
this.issues = issues;
return this;
}
}

public static final class ModMenu implements Serializable {
private Map<String, String> links;
private List<String> badges;
Expand Down Expand Up @@ -155,7 +105,7 @@ public ModMenu withParent(String namespace, String name, Consumer<ParentMod> act
return this.withParent(mod);
}

public static final class ParentMod extends ModBase<ParentMod> {
public static final class ParentMod extends ModShell<ParentMod> {
private List<String> badges;

public ParentMod(String namespace, String name) {
Expand Down
63 changes: 40 additions & 23 deletions build_logic/src/main/java/lambdynamiclights/data/ModBase.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
package lambdynamiclights.data;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

public class ModBase<SELF extends ModBase<SELF>> implements Serializable {
@SerializedName("id")
protected String namespace;
protected String name;
protected String description;
protected String icon;

public ModBase(String namespace, String name) {
this.namespace = namespace;
this.name = name;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

public class ModBase<SELF extends ModBase<SELF>> extends ModShell<SELF> {
protected final String version;
protected final List<String> authors = new ArrayList<>();
protected Contact contact;
protected String license;

public ModBase(String namespace, String name, String version) {
super(namespace, name);
this.version = version;
}

@SuppressWarnings("unchecked")
private SELF $self() {
return (SELF) this;
}

public SELF withNamespace(String namespace) {
this.namespace = namespace;
public SELF withAuthors(List<String> authors) {
this.authors.addAll(authors);
return this.$self();
}

public SELF withName(String name) {
this.name = name;
return this.$self();
public SELF withAuthors(String... authors) {
return this.withAuthors(Arrays.asList(authors));
}

private Contact useContact() {
if (this.contact == null) this.contact = new Contact();
return this.contact;
}

public SELF withDescription(String description) {
this.description = description;
public SELF withContact(Consumer<Contact> action) {
action.accept(this.useContact());
return this.$self();
}

public SELF withIcon(String icon) {
this.icon = icon;
public SELF withLicense(String license) {
this.license = license;
return this.$self();
}

public <VARIANT extends ModBase<VARIANT>> VARIANT derive(ModBaseFactory<VARIANT> factory) {
var variant = factory.create(this.namespace, this.name, this.version);
this.copyTo(variant);
variant.authors.addAll(this.authors);
variant.contact = this.contact != null ? this.contact.copy() : null;
variant.license = this.license;
return variant;
}

public interface ModBaseFactory<SELF extends ModBase<SELF>> {
SELF create(String namespace, String name, String version);
}
}
50 changes: 50 additions & 0 deletions build_logic/src/main/java/lambdynamiclights/data/ModShell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package lambdynamiclights.data;

import com.google.gson.annotations.SerializedName;

import java.io.Serializable;

public class ModShell<SELF extends ModShell<SELF>> implements Serializable {
@SerializedName("id")
protected String namespace;
protected String name;
protected String description;
protected String icon;

public ModShell(String namespace, String name) {
this.namespace = namespace;
this.name = name;
}

@SuppressWarnings("unchecked")
private SELF $self() {
return (SELF) this;
}

public SELF withNamespace(String namespace) {
this.namespace = namespace;
return this.$self();
}

public SELF withName(String name) {
this.name = name;
return this.$self();
}

public SELF withDescription(String description) {
this.description = description;
return this.$self();
}

public SELF withIcon(String icon) {
this.icon = icon;
return this.$self();
}

public void copyTo(ModShell<?> target) {
target.namespace = this.namespace;
target.name = this.name;
target.description = this.description;
target.icon = this.icon;
}
}
Loading

0 comments on commit fd527cf

Please sign in to comment.