diff options
Diffstat (limited to 'src/testmod/java/dev')
3 files changed, 55 insertions, 2 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 + } +} diff --git a/src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java b/src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java index 2c4875f..dca6070 100644 --- a/src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java +++ b/src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java @@ -1,4 +1,4 @@ -/*? if neoforge { *//* +/*? if neoforge {*//* package dev.isxander.yacl3.test; import net.neoforged.fml.common.Mod; diff --git a/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java index 07e0098..a515fe0 100644 --- a/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java +++ b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java @@ -53,7 +53,7 @@ public class GuiTest { .option(ButtonOption.createBuilder() .name(Component.literal("Kotlin DSL Test")) .action((screen, opt) -> { - Minecraft.getInstance().setScreen(DslTestKt.kotlinDslGui(screen)); + Minecraft.getInstance().setScreen(CodecConfigKt.INSTANCE.generateConfigScreen(screen)); }) .build()) .group(OptionGroup.createBuilder() |