entry : overrides.getAsObject()) {
- this.applyModOverride(meta, entry.getKey(), entry.getValue());
- }
- }
- }
- }*/
-
- void applyModOverride(String modId, String name, boolean enabled) {
- Option option = this.options.get(name);
-
- if (option == null) {
- logger.warn("Mod '{}' attempted to override option '{}', which doesn't exist, ignoring", modId, name);
- return;
- }
-
- // disabling the option takes precedence over enabling
- if (!enabled && option.isEnabled()) {
- option.clearModsDefiningValue();
- }
-
- if (!enabled || option.isEnabled() || option.getDefiningMods().isEmpty()) {
- option.addModOverride(enabled, modId);
- }
- }
-
- /**
- * Returns the effective option for the specified class name. This traverses the package path of the given mixin
- * and checks each root for configuration rules. If a configuration option disables a package, all mixins located in
- * that package and its children will be disabled. The effective option is that of the highest-priority option, either
- * a enable option at the end of the chain or a disable option at the earliest point in the chain.
- *
- * @return {@code null} if no options matched the given mixin name, otherwise the effective option for this Mixin
- */
- public Option getEffectiveOptionForMixin(String mixinClassName) {
- int lastSplit = 0;
- int nextSplit;
-
- Option option = null;
-
- while ((nextSplit = mixinClassName.indexOf('.', lastSplit)) != -1) {
- String key = getMixinOptionName(mixinClassName.substring(0, nextSplit));
-
- Option candidate = this.options.get(key);
-
- if (candidate != null) {
- option = candidate;
-
- if (!option.isEnabled()) {
- return option;
- }
- }
-
- lastSplit = nextSplit + 1;
- }
-
- return option;
- }
-
- /**
- * Tests all dependencies and disables options when their dependencies are not met.
- */
- private boolean applyDependencies() {
- boolean changed = false;
- for (Option optionWithDependency : this.optionsWithDependencies) {
- changed |= optionWithDependency.disableIfDependenciesNotMet(logger);
- }
- return changed;
- }
-
- private static void writeDefaultConfig(Path file, String modName, String infoUrl) throws IOException {
- Path dir = file.getParent();
-
- if (!Files.exists(dir)) {
- Files.createDirectories(dir);
- } else if (!Files.isDirectory(dir)) {
- throw new IOException("The parent file is not a directory");
- }
-
- try (BufferedWriter writer = Files.newBufferedWriter(file)) {
- writer.write(String.format("# This is the configuration file for %s.\n", modName));
- writer.write("# This file exists for debugging purposes and should not be configured otherwise.\n");
- writer.write("#\n");
- if (infoUrl != null) {
- writer.write("# You can find information on editing this file and all the available options here:\n");
- writer.write("# " + infoUrl + "\n");
- writer.write("#\n");
- }
- writer.write("# By default, this file will be empty except for this notice.\n");
- }
- }
-
- private static String getMixinOptionName(String name) {
- return "mixin." + name;
- }
-
- public int getOptionCount() {
- return this.options.size();
- }
-
- public int getOptionOverrideCount() {
- return (int) this.options.values()
- .stream()
- .filter(Option::isOverridden)
- .count();
- }
-
- /**
- * A builder for {@link CaffeineConfig} instances.
- *
- * Allows adding mixin options and creating depencencies between them, as well as
- * configuring various properties from this config.
- *
- * @see CaffeineConfig#builder(String)
- */
- public final class Builder {
- private boolean alreadyBuilt = false;
- private String infoUrl;
- private String jsonKey;
-
- private Builder() {}
-
- /**
- * Defines a Mixin option which can be configured by users and other mods.
- *
- * @param mixin The name of the mixin package which will be controlled by this option
- * @param enabled {@code true} if the option will be enabled by default, {@code false} otherwise
- * @throws IllegalStateException If a option with that name already exists
- */
- public Builder addMixinOption(String mixin, boolean enabled) {
- CaffeineConfig.this.addMixinOption(mixin, enabled);
- return this;
- }
-
- /**
- * Defines a dependency between two registered mixin options. If a dependency is not satisfied, the mixin will
- * be disabled.
- *
- * @param option the mixin option that requires another option to be set to a given value
- * @param dependency the mixin option the given option depends on
- * @param requiredValue the required value of the dependency
- * @throws IllegalArgumentException if one of the option don't exists
- */
- public Builder addOptionDependency(String option, String dependency, boolean requiredValue) {
- CaffeineConfig.this.addOptionDependency(option, dependency, requiredValue);
- return this;
- }
-
- /**
- * Sets the logger the built {@link CaffeineConfig} will use, instead of one derived from the mod name
- * @param logger The {@link Logger} to use. Can't be {@code null}
- */
- public Builder withLogger(Logger logger) {
- CaffeineConfig.this.logger = logger;
- return this;
- }
-
- /**
- * Sets the key name to search in other mod's custom values in order to find overrides.
- * @param key The key to search for
- */
- public Builder withSettingsKey(String key) {
- this.jsonKey = key;
- return this;
- }
-
- /**
- * Sets the url to a resource with more information about the options to write in the config file header.
- *
- * If it's {@code null} or not set, the paragraph about help on editing the file will be skipped
- * @param url A {@link String} representing the url, or {@code null} to disable the paragraph
- */
- public Builder withInfoUrl(String url) {
- this.infoUrl = url;
- return this;
- }
-
- /**
- * Builds a {@link CaffeineConfig} with the specified options, and populates the overrides for them.
- *
- * This method will create a file in the given {@link Path} (and its parent directories if necessary) or
- * read from it if it already exists.
- *
- * It will also check for overrides in all loaded mods.
- *
- * This method can only be called once per builder object
- *
- * @param path The {@link Path} to the settings file
- */
- public CaffeineConfig build(Path path) {
- if (alreadyBuilt) {
- throw new IllegalStateException("Cannot build a CaffeineConfig twice from the same builder");
- }
-
- if (Files.exists(path)) {
- Properties props = new Properties();
-
- try (InputStream fin = Files.newInputStream(path)) {
- props.load(fin);
- } catch (IOException e) {
- throw new RuntimeException("Could not load config file", e);
- }
-
- readProperties(props);
- } else {
- try {
- writeDefaultConfig(path, modName, infoUrl);
- } catch (IOException e) {
- logger.warn("Could not write default configuration file", e);
- }
- }
-
- PLATFORM.applyModOverrides(CaffeineConfig.this, jsonKey);
-
- // Check dependencies several times, because one iteration may disable a option required by another option
- // This terminates because each additional iteration will disable one or more options, and there is only a finite number of rules
- while (applyDependencies());
-
- this.alreadyBuilt = true;
-
- return CaffeineConfig.this;
- }
- }
-}
diff --git a/build.gradle.kts b/build.gradle.kts
index d3a9da9b..5e48a2c5 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -14,9 +14,15 @@ val PARCHMENT_VERSION by extra { null }
// https://semver.org/
val MOD_VERSION by extra { "0.6.0-beta.1" }
+//
+val maven_group: String by project
+val archives_name: String by project
+
allprojects {
apply(plugin = "java")
apply(plugin = "maven-publish")
+ group = maven_group
+ version = createVersionString()
}
tasks.withType {
@@ -24,22 +30,26 @@ tasks.withType {
}
subprojects {
+ apply(plugin = "maven-publish")
+
repositories {
maven("https://maven.parchmentmc.org/")
maven("https://api.modrinth.com/maven")
}
- apply(plugin = "maven-publish")
+ base {
+ archivesName = "$archives_name-${project.name}"
+ }
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
tasks.processResources {
filesMatching("META-INF/neoforge.mods.toml") {
- expand(mapOf("version" to MOD_VERSION))
+ expand(mapOf("version" to createVersionString()))
}
}
- version = MOD_VERSION
+ version = createVersionString()
group = "me.flashyreese.mods"
tasks.withType {
@@ -51,3 +61,29 @@ subprojects {
enabled = false
}
}
+
+fun createVersionString(): String {
+ val builder = StringBuilder()
+
+ val isReleaseBuild = project.hasProperty("build.release")
+ val buildId = System.getenv("GITHUB_RUN_NUMBER")
+
+ if (isReleaseBuild) {
+ builder.append(MOD_VERSION)
+ } else {
+ builder.append(MOD_VERSION.split('-')[0])
+ builder.append("-snapshot")
+ }
+
+ builder.append("+mc").append(MINECRAFT_VERSION)
+
+ if (!isReleaseBuild) {
+ if (buildId != null) {
+ builder.append("-build.$buildId")
+ } else {
+ builder.append("-local")
+ }
+ }
+
+ return builder.toString()
+}
diff --git a/common/build.gradle.kts b/common/build.gradle.kts
index 9984a6fb..5e7ef82a 100644
--- a/common/build.gradle.kts
+++ b/common/build.gradle.kts
@@ -54,4 +54,32 @@ loom {
}
accessWidenerPath = file("src/main/resources/sodium-extra.accesswidener")
+}
+
+publishing {
+ publications {
+ create("mavenJava") {
+ artifactId = base.archivesName.get()
+ from(components["java"])
+ }
+ }
+
+ repositories {
+ maven {
+ name = "FlashyReeseReleases"
+ url = uri("https://maven.flashyreese.me/releases")
+ credentials {
+ username = System.getenv("MAVEN_USERNAME")
+ password = System.getenv("MAVEN_PASSWORD")
+ }
+ }
+ maven {
+ name = "FlashyReeseSnapshots"
+ url = uri("https://maven.flashyreese.me/snapshots")
+ credentials {
+ username = System.getenv("MAVEN_USERNAME")
+ password = System.getenv("MAVEN_PASSWORD")
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts
index 59bf85b9..4aab59b4 100644
--- a/fabric/build.gradle.kts
+++ b/fabric/build.gradle.kts
@@ -86,4 +86,32 @@ tasks {
jar {
from(rootDir.resolve("LICENSE.txt"))
}
+}
+
+publishing {
+ publications {
+ create("mavenJava") {
+ artifactId = base.archivesName.get()
+ from(components["java"])
+ }
+ }
+
+ repositories {
+ maven {
+ name = "FlashyReeseReleases"
+ url = uri("https://maven.flashyreese.me/releases")
+ credentials {
+ username = System.getenv("MAVEN_USERNAME")
+ password = System.getenv("MAVEN_PASSWORD")
+ }
+ }
+ maven {
+ name = "FlashyReeseSnapshots"
+ url = uri("https://maven.flashyreese.me/snapshots")
+ credentials {
+ username = System.getenv("MAVEN_USERNAME")
+ password = System.getenv("MAVEN_PASSWORD")
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
new file mode 100644
index 00000000..cde55f00
--- /dev/null
+++ b/gradle.properties
@@ -0,0 +1,3 @@
+org.gradle.parallel=true
+maven_group=me.flashyreese.mods
+archives_name=sodium-extra
\ No newline at end of file
diff --git a/neoforge/build.gradle.kts b/neoforge/build.gradle.kts
index 03d97691..5e469515 100644
--- a/neoforge/build.gradle.kts
+++ b/neoforge/build.gradle.kts
@@ -101,4 +101,32 @@ tasks.withType().matching(notNeoTask).configureEach {
from(project(":common").sourceSets.main.get().resources)
}
-java.toolchain.languageVersion = JavaLanguageVersion.of(21)
\ No newline at end of file
+java.toolchain.languageVersion = JavaLanguageVersion.of(21)
+
+publishing {
+ publications {
+ create("mavenJava") {
+ artifactId = base.archivesName.get()
+ from(components["java"])
+ }
+ }
+
+ repositories {
+ maven {
+ name = "FlashyReeseReleases"
+ url = uri("https://maven.flashyreese.me/releases")
+ credentials {
+ username = System.getenv("MAVEN_USERNAME")
+ password = System.getenv("MAVEN_PASSWORD")
+ }
+ }
+ maven {
+ name = "FlashyReeseSnapshots"
+ url = uri("https://maven.flashyreese.me/snapshots")
+ credentials {
+ username = System.getenv("MAVEN_USERNAME")
+ password = System.getenv("MAVEN_PASSWORD")
+ }
+ }
+ }
+}
\ No newline at end of file