From 566fb6c498d571281c94029f8dfbac5e5077600c Mon Sep 17 00:00:00 2001 From: isXander Date: Wed, 12 Jun 2024 17:15:09 +0100 Subject: Changelog and minor changes --- changelog.md | 81 +++++++++++++++++++++- .../yacl3/config/v3/JsonFileCodecConfig.java | 2 +- .../dev/isxander/yacl3/gui/AbstractWidget.java | 8 +-- .../dev/isxander/yacl3/platform/YACLPlatform.java | 16 ++--- src/main/kotlin/dev/isxander/yacl3/dsl/API.kt | 3 + .../java/dev/isxander/yacl3/test/CodecConfig.java | 7 +- stonecutter.gradle.kts | 2 +- versions/1.21-fabric/gradle.properties | 4 +- 8 files changed, 101 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index dbab4c7..ab6c6d1 100644 --- a/changelog.md +++ b/changelog.md @@ -1,13 +1,88 @@ -# YetAnotherConfigLib 3.4.4 +# YetAnotherConfigLib 3.5.0 This build supports the following versions: - Fabric 1.20.1 - Fabric 1.20.4 - Fabric 1.20.6 (also supports 1.20.5) +- Fabric 1.21 - NeoForge 1.20.6 (also supports 1.20.5) - NeoForge 1.20.4 - MinecraftForge 1.20.1 -## Bug Fixes +## *Experimental* Codec Config -- Fix Kotlin DSL not being included +This update brings a new experimental config API that utilises Mojang's Codec for (de)serialization. + +```java +public class CodecConfig extends JsonFileCodecConfig/*or*/CodecConfig { + public static final CodecConfig INSTANCE = new CodecConfig(); + + public final ConfigEntry myInt = + register("my_int", 0, Codec.INT); + + public final ReadonlyConfigEntry myInnerConfig = + register("my_inner_config", InnerCodecConfig.INSTANCE); + + public CodecConfig() { + super(path); + } + + void test() { + loadFromFile(); // load like this + saveToFile(); // save like this + + // or if you just extend CodecConfig instead of JsonFileConfig: + JsonElement element = null; + this.decode(element, JsonOps.INSTANCE); // load + DataResult encoded = this.encodeStart(JsonOps.INSTANCE); // save + } +} +``` +or in Kotlin... +```kotlin +object CodecConfig : JsonFileCodecConfig(path) { + val myInt by register(0, Codec.INT) + + val myInnerConfig by register(InnerCodecConfig) + + fun test() { + loadFromFile() + saveToFile() + + // blah blah blah + } +} +``` + +## Rewritten Kotlin DSL + +Completely rewrote the Kotlin DSL! + +```kotlin +YetAnotherConfigLib("namespace") { + val category by categories.registering { + val option by rootOptions.registering { + controller = slider(range = 5..10) + binding(::thisProp, default) + + val otherOption by categories["category"]["group"].futureRef() + otherOption.onReady { it.setAvailable(false) } + } + + // translation key is generated automagically + val label by rootOptions.registeringLabel + + val group by groups.registering { + val otherOption = options.register("otherOption") { + controller = tickBox() + } + } + } +} +``` + +## Changes + +- Fix dropdown controllers erroneously showing their dropdown - Crendgrim +- Make cancel/reset and undo buttons public for accessing +- Add compatibility for 1.21 diff --git a/src/main/java/dev/isxander/yacl3/config/v3/JsonFileCodecConfig.java b/src/main/java/dev/isxander/yacl3/config/v3/JsonFileCodecConfig.java index 49a0dac..fed8ba8 100644 --- a/src/main/java/dev/isxander/yacl3/config/v3/JsonFileCodecConfig.java +++ b/src/main/java/dev/isxander/yacl3/config/v3/JsonFileCodecConfig.java @@ -12,7 +12,7 @@ import java.nio.file.Path; import java.nio.file.StandardOpenOption; @ApiStatus.Experimental -public abstract class JsonFileCodecConfig extends CodecConfig { +public abstract class JsonFileCodecConfig> extends CodecConfig { private final Path configPath; private final Gson gson; diff --git a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java index 8def3b3..48f2cc3 100644 --- a/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java +++ b/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java @@ -95,17 +95,17 @@ public abstract class AbstractWidget implements GuiEventListener, Renderable, Na VertexConsumer vertex = graphics.bufferSource().getBuffer(RenderType.gui()); Matrix4f matrix4f = graphics.pose().last().pose(); - /*? if >1.20.6 {*//* + /*? if >1.20.6 {*/ vertex.addVertex(matrix4f, x1, y1, 0).setColor(startColor); vertex.addVertex(matrix4f, x1, y2, 0).setColor(startColor); vertex.addVertex(matrix4f, x2, y2, 0).setColor(endColor); vertex.addVertex(matrix4f, x2, y1, 0).setColor(endColor); - *//*?} else {*/ - vertex.vertex(matrix4f, x1, y1, 0).color(startColor).endVertex(); + /*?} else {*/ + /*vertex.vertex(matrix4f, x1, y1, 0).color(startColor).endVertex(); vertex.vertex(matrix4f, x1, y2, 0).color(startColor).endVertex(); vertex.vertex(matrix4f, x2, y2, 0).color(endColor).endVertex(); vertex.vertex(matrix4f, x2, y1, 0).color(endColor).endVertex(); - /*?}*/ + *//*?}*/ } diff --git a/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java b/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java index 514c964..490a5fa 100644 --- a/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java +++ b/src/main/java/dev/isxander/yacl3/platform/YACLPlatform.java @@ -15,11 +15,11 @@ import java.nio.file.Path; public final class YACLPlatform { public static ResourceLocation parseRl(String rl) { - /*? if >1.20.6 {*//* + /*? if >1.20.6 {*/ return ResourceLocation.parse(rl); - *//*?} else {*/ - return new ResourceLocation(rl); - /*?}*/ + /*?} else {*/ + /*return new ResourceLocation(rl); + *//*?}*/ } public static ResourceLocation rl(String path) { @@ -31,11 +31,11 @@ public final class YACLPlatform { } public static ResourceLocation rl(String namespace, String path) { - /*? if >1.20.6 {*//* + /*? if >1.20.6 {*/ return ResourceLocation.fromNamespaceAndPath(namespace, path); - *//*?} else {*/ - return new ResourceLocation(namespace, path); - /*?}*/ + /*?} else {*/ + /*return new ResourceLocation(namespace, path); + *//*?}*/ } public static Env getEnvironment() { diff --git a/src/main/kotlin/dev/isxander/yacl3/dsl/API.kt b/src/main/kotlin/dev/isxander/yacl3/dsl/API.kt index cd2c483..e3e3099 100644 --- a/src/main/kotlin/dev/isxander/yacl3/dsl/API.kt +++ b/src/main/kotlin/dev/isxander/yacl3/dsl/API.kt @@ -23,6 +23,9 @@ typealias FutureOption = CompletableFuture> fun CompletableFuture.futureRef(id: String): FutureOption = thenCompose { it.futureRef(id) } +fun CompletableFuture.futureRef(): RegisterableDelegateProvider> = + RegisterableDelegateProvider({ this.futureRef(it) }, null) + fun YetAnotherConfigLib(id: String, block: RootDsl.() -> Unit) = RootDslImpl(id).apply(block).build() diff --git a/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java b/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java index 08137e6..1a65eb2 100644 --- a/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java +++ b/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java @@ -6,12 +6,13 @@ import com.mojang.serialization.DataResult; import com.mojang.serialization.JsonOps; import dev.isxander.yacl3.config.v3.ConfigEntry; import dev.isxander.yacl3.config.v3.JsonFileCodecConfig; +import dev.isxander.yacl3.config.v3.ReadonlyConfigEntry; import dev.isxander.yacl3.platform.YACLPlatform; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentSerialization; import net.minecraft.resources.ResourceLocation; -public class CodecConfig extends JsonFileCodecConfig { +public class CodecConfig extends JsonFileCodecConfig { public static final CodecConfig INSTANCE = new CodecConfig(); public final ConfigEntry myInt = @@ -26,8 +27,8 @@ public class CodecConfig extends JsonFileCodecConfig { public final ConfigEntry myText = register("my_text", Component.literal("Hello"), ComponentSerialization.CODEC); - public final ConfigEntry myInnerConfig = - register("my_inner_config", InnerCodecConfig.INSTANCE, InnerCodecConfig.INSTANCE); + public final ReadonlyConfigEntry myInnerConfig = + register("my_inner_config", InnerCodecConfig.INSTANCE); public static class InnerCodecConfig extends dev.isxander.yacl3.config.v3.CodecConfig { public static final InnerCodecConfig INSTANCE = new InnerCodecConfig(); diff --git a/stonecutter.gradle.kts b/stonecutter.gradle.kts index 8aa3e0c..79cc121 100644 --- a/stonecutter.gradle.kts +++ b/stonecutter.gradle.kts @@ -7,7 +7,7 @@ plugins { id("me.modmuss50.mod-publish-plugin") version "0.5.+" apply false id("org.ajoberstar.grgit") version "5.0.+" apply false } -stonecutter active "1.20.6-fabric" /* [SC] DO NOT EDIT */ +stonecutter active "1.21-fabric" /* [SC] DO NOT EDIT */ stonecutter.configureEach { val platform = project.property("loom.platform") diff --git a/versions/1.21-fabric/gradle.properties b/versions/1.21-fabric/gradle.properties index 678600f..aac37cb 100644 --- a/versions/1.21-fabric/gradle.properties +++ b/versions/1.21-fabric/gradle.properties @@ -1,8 +1,8 @@ loom.platform=fabric -mcVersion=1.21-pre1 +mcVersion=1.21-rc1 java.version=21 deps.quiltMappings= -deps.fabricApi=0.99.2+1.21 +deps.fabricApi=0.100.1+1.21 fmj.mcDep=~1.21- -- cgit