aboutsummaryrefslogtreecommitdiff
path: root/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java
diff options
context:
space:
mode:
authorisXander <xander@isxander.dev>2024-06-11 23:13:49 +0100
committerisXander <xander@isxander.dev>2024-06-11 23:13:57 +0100
commit305718e163f91802a4bc1c1ed6540febb2ce204e (patch)
treed72fe8b95dab1ef89f67b13a19f8c06fdb582c28 /src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java
parent65b4f7ba8374bbaebc6a431f8347ffc3e8afdced (diff)
downloadYetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.tar.gz
YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.tar.bz2
YetAnotherConfigLib-305718e163f91802a4bc1c1ed6540febb2ce204e.zip
codec config and rewritten kotlin dsl
Diffstat (limited to 'src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java')
-rw-r--r--src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java b/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java
new file mode 100644
index 0000000..08137e6
--- /dev/null
+++ b/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java
@@ -0,0 +1,53 @@
+package dev.isxander.yacl3.test;
+
+import com.google.gson.JsonElement;
+import com.mojang.serialization.Codec;
+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.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 static final CodecConfig INSTANCE = new CodecConfig();
+
+ public final ConfigEntry<Integer> myInt =
+ register("my_int", 0, Codec.INT);
+
+ public final ConfigEntry<String> myString =
+ register("my_string", "default", Codec.STRING);
+
+ public final ConfigEntry<ResourceLocation> myIdentifier =
+ register("my_identifier", YACLPlatform.rl("test"), ResourceLocation.CODEC);
+
+ public final ConfigEntry<Component> myText =
+ register("my_text", Component.literal("Hello"), ComponentSerialization.CODEC);
+
+ public final ConfigEntry<InnerCodecConfig> myInnerConfig =
+ register("my_inner_config", InnerCodecConfig.INSTANCE, InnerCodecConfig.INSTANCE);
+
+ public static class InnerCodecConfig extends dev.isxander.yacl3.config.v3.CodecConfig<InnerCodecConfig> {
+ public static final InnerCodecConfig INSTANCE = new InnerCodecConfig();
+ }
+
+ public CodecConfig() {
+ super(YACLPlatform.getConfigDir().resolve("codec_config.json"));
+ }
+
+ void test() {
+ loadFromFile(); // load like this
+ saveToFile(); // save like this
+
+ this.myInt.get();
+ this.myInt.set(5);
+ this.myInt.defaultValue();
+
+ // or if you just extend Config instead of JsonFileConfig:
+ JsonElement element = null;
+ this.decode(element, JsonOps.INSTANCE); // load
+ DataResult<JsonElement> encoded = this.encodeStart(JsonOps.INSTANCE); // save
+ }
+}