Skip to content

Commit

Permalink
Make API importable into dev environments.
Browse files Browse the repository at this point in the history
  • Loading branch information
LambdAurora committed Nov 3, 2024
1 parent bfcbbc7 commit 9f11b5e
Show file tree
Hide file tree
Showing 13 changed files with 427 additions and 94 deletions.
21 changes: 18 additions & 3 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,35 @@ plugins {
id("lambdynamiclights")
}

val prettyName = "${Constants.PRETTY_NAME} (API)"

base.archivesName.set(Constants.NAME + "-api")

tasks.generateFmj.configure {
this.fmj.get()
.withNamespace(Constants.NAMESPACE + "_api")
.withName(prettyName)
.withDescription(Constants.API_DESCRIPTION)
.withModMenu {
it.withBadges("library")
.withParent(Constants.NAMESPACE, Constants.PRETTY_NAME) { parent ->
parent.withDescription(Constants.DESCRIPTION)
.withIcon("assets/${Constants.NAMESPACE}/icon.png")
}
}
}

// Configure the maven publication.
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])

groupId = "$group.lambdynamiclights"
artifactId = "lambdynamiclights-api"

pom {
name.set("${Constants.PRETTY_NAME} (API)")
description.set("API for LambDynamicLights, a mod which adds dynamic lighting to Minecraft.")
name.set(prettyName)
description.set(Constants.API_DESCRIPTION)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import dev.lambdaurora.lambdynlights.api.item.ItemLightSourceManager;

/**
* Represents the entrypoint for LambDynamicLights API.
* Represents the entrypoint for LambDynamicLights' API.
*
* @author LambdAurora
* @version 4.0.0
Expand Down
Binary file added api/src/main/resources/assets/lambdynlights/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 19 additions & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ if (!(System.getenv("CURSEFORGE_TOKEN") != null || System.getenv("MODRINTH_TOKEN
}
logger.lifecycle("Preparing version ${version}...")

tasks.generateFmj.configure {
this.fmj.get()
.withEntrypoints("client", "dev.lambdaurora.lambdynlights.LambDynLights")
.withEntrypoints("modmenu", "dev.lambdaurora.lambdynlights.LambDynLightsModMenu")
.withAccessWidener("lambdynlights.accesswidener")
.withMixins("lambdynlights.mixins.json", "lambdynlights.lightsource.mixins.json")
.withDepend("${Constants.NAMESPACE}_api", ">=${version}")
.withDepend("fabric-api", ">=${libs.versions.fabric.api.get()}")
.withDepend("spruceui", ">=${libs.versions.spruceui.get()}")
.withRecommend("modmenu", ">=${libs.versions.modmenu.get()}")
.withBreak("optifabric", "*")
}

repositories {
mavenLocal()
maven {
Expand All @@ -35,8 +48,10 @@ loom {
}

dependencies {
implementation(project(":api", configuration = "namedElements"))
api(project(":api", configuration = "namedElements"))
include(project(":api"))

modImplementation(libs.fabric.loader)
modImplementation(libs.fabric.api)

implementation(libs.nightconfig.core)
Expand All @@ -50,9 +65,6 @@ dependencies {
this.isTransitive = false
}

shadow(project(":api", configuration = "namedElements")) {
isTransitive = false
}
shadow(libs.yumi.commons.core) {
isTransitive = false
}
Expand Down Expand Up @@ -90,7 +102,7 @@ tasks.remapJar {

modrinth {
projectId = project.property("modrinth_id") as String
versionName = "LambDynamicLights ${Constants.VERSION} (${Constants.mcVersion()})"
versionName = "${Constants.PRETTY_NAME} ${Constants.VERSION} (${Constants.mcVersion()})"
uploadFile.set(tasks.remapJar.get())
loaders.set(listOf("fabric", "quilt"))
gameVersions.set(listOf(Constants.mcVersion()))
Expand Down Expand Up @@ -146,7 +158,7 @@ tasks.register<TaskPublishCurseForge>("curseforge") {
mainFile.addJavaVersion("Java 21", "Java 22")
mainFile.addEnvironment("Client")

mainFile.displayName = "LambDynamicLights ${Constants.VERSION} (${Constants.mcVersion()})"
mainFile.displayName = "${Constants.PRETTY_NAME} ${Constants.VERSION} (${Constants.mcVersion()})"
mainFile.addRequirement("fabric-api")
mainFile.addOptional("modmenu")
mainFile.addIncompatibility("optifabric")
Expand All @@ -161,12 +173,11 @@ publishing {
create<MavenPublication>("mavenJava") {
from(components["java"])

groupId = "$group.lambdynamiclights"
artifactId = "lambdynamiclights-runtime"

pom {
name.set(Constants.PRETTY_NAME)
description.set("Adds dynamic lighting to Minecraft.")
description.set(Constants.DESCRIPTION)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions build_logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ dependencies {
implementation(libs.gradle.licenser)
implementation(libs.gradle.loom)
implementation(libs.mappingio)
implementation(libs.gson)

// A bit of a hack you definitely should not worry about.
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
Expand Down
201 changes: 201 additions & 0 deletions build_logic/src/main/java/lambdynamiclights/data/Fmj.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package lambdynamiclights.data;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.*;
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;
private final List<String> mixins = new ArrayList<>();
private final Map<String, String> depends = new LinkedHashMap<>();
private final Map<String, String> recommends = new LinkedHashMap<>();
private final Map<String, String> breaks = new LinkedHashMap<>();
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;
}

public Fmj withEnvironment(String environment) {
this.environment = environment;
return this;
}

public Fmj withEntrypoints(String entrypointName, String... entrypoints) {
this.entrypoints.computeIfAbsent(entrypointName, k -> new ArrayList<>()).addAll(Arrays.asList(entrypoints));
return this;
}

public Fmj withAccessWidener(String accessWidener) {
this.accessWidener = accessWidener;
return this;
}

public Fmj withMixins(String... mixins) {
this.mixins.addAll(Arrays.asList(mixins));
return this;
}

public Fmj withDepend(String dependency, String constraint) {
this.depends.put(dependency, constraint);
return this;
}

public Fmj withRecommend(String dependency, String constraint) {
this.recommends.put(dependency, constraint);
return this;
}

public Fmj withBreak(String dependency, String constraint) {
this.breaks.put(dependency, constraint);
return this;
}

public Fmj withCustom(String key, Object value) {
this.custom.put(key, value);
return this;
}

public Fmj withModMenu(Consumer<ModMenu> action) {
action.accept((ModMenu) this.custom.computeIfAbsent("modmenu", k -> new ModMenu()));
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;
private ParentMod parent;

private Map<String, String> useLinks() {
if (this.links == null) this.links = new LinkedHashMap<>();
return this.links;
}

public ModMenu withLink(String key, String value) {
this.useLinks().put(key, value);
return this;
}

private List<String> useBadges() {
if (this.badges == null) this.badges = new ArrayList<>();
return this.badges;
}

public ModMenu withBadges(String... badges) {
this.useBadges().addAll(Arrays.asList(badges));
return this;
}

public ModMenu withParent(ParentMod parent) {
this.parent = parent;
return this;
}

public ModMenu withParent(String namespace, String name, Consumer<ParentMod> action) {
var mod = new ParentMod(namespace, name);
action.accept(mod);
return this.withParent(mod);
}

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

public ParentMod(String namespace, String name) {
super(namespace, name);
}

private List<String> useBadges() {
if (this.badges == null) this.badges = new ArrayList<>();
return this.badges;
}

public ParentMod withBadges(String... badges) {
this.useBadges().addAll(Arrays.asList(badges));
return this;
}
}
}

public static final class Serializer implements JsonSerializer<Fmj> {
@Override
public JsonElement serialize(Fmj src, Type typeOfSrc, JsonSerializationContext context) {
var json = new JsonObject();
json.addProperty("schemaVersion", 1);
json.addProperty("id", src.namespace);
json.addProperty("name", src.name);
json.addProperty("version", src.version);
if (src.description != null) json.addProperty("description", src.description);
if (!src.authors.isEmpty()) json.add("authors", context.serialize(src.authors));
if (src.contact != null) json.add("contact", context.serialize(src.contact));
if (src.license != null) json.addProperty("license", src.license);
if (src.icon != null) json.addProperty("icon", src.icon);
if (src.environment != null) json.addProperty("environment", src.environment);
if (!src.entrypoints.isEmpty()) json.add("entrypoints", context.serialize(src.entrypoints));
if (src.accessWidener != null) json.addProperty("accessWidener", src.accessWidener);
if (!src.mixins.isEmpty()) json.add("mixins", context.serialize(src.mixins));
if (!src.depends.isEmpty()) json.add("depends", context.serialize(src.depends));
if (!src.recommends.isEmpty()) json.add("recommends", context.serialize(src.recommends));
if (!src.breaks.isEmpty()) json.add("breaks", context.serialize(src.breaks));
if (!src.custom.isEmpty()) json.add("custom", context.serialize(src.custom));
return json;
}
}
}
43 changes: 43 additions & 0 deletions build_logic/src/main/java/lambdynamiclights/data/ModBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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;
}

@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();
}
}
Loading

0 comments on commit 9f11b5e

Please sign in to comment.