aboutsummaryrefslogtreecommitdiff
path: root/src/testmod/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/testmod/java')
-rw-r--r--src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java6
-rw-r--r--src/testmod/java/dev/isxander/yacl3/test/GuiTest.java64
2 files changed, 66 insertions, 4 deletions
diff --git a/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java b/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java
index 1a65eb2..1b185ac 100644
--- a/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java
+++ b/src/testmod/java/dev/isxander/yacl3/test/CodecConfig.java
@@ -9,7 +9,6 @@ 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<CodecConfig> {
@@ -24,8 +23,11 @@ public class CodecConfig extends JsonFileCodecConfig<CodecConfig> {
public final ConfigEntry<ResourceLocation> myIdentifier =
register("my_identifier", YACLPlatform.rl("test"), ResourceLocation.CODEC);
+ //? if >=1.21.2 {
public final ConfigEntry<Component> myText =
- register("my_text", Component.literal("Hello"), ComponentSerialization.CODEC);
+ register("my_text", Component.literal("Hello"),
+ net.minecraft.network.chat.ComponentSerialization.CODEC);
+ //?}
public final ReadonlyConfigEntry<InnerCodecConfig> myInnerConfig =
register("my_inner_config", InnerCodecConfig.INSTANCE);
diff --git a/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java
index a515fe0..1552a0a 100644
--- a/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java
+++ b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java
@@ -14,6 +14,7 @@ import dev.isxander.yacl3.gui.controllers.string.number.DoubleFieldController;
import dev.isxander.yacl3.gui.controllers.string.number.FloatFieldController;
import dev.isxander.yacl3.gui.controllers.string.number.IntegerFieldController;
import dev.isxander.yacl3.gui.controllers.string.number.LongFieldController;
+import dev.isxander.yacl3.impl.SelfContainedBinding;
import dev.isxander.yacl3.platform.YACLPlatform;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
@@ -116,7 +117,7 @@ public class GuiTest {
.controller(opt -> BooleanControllerBuilder.create(opt)
.formatValue(state -> state ? Component.literal("Amazing") : Component.literal("Not Amazing"))
.coloured(true))
- .listener((opt, val) -> booleanOption.get().setAvailable(val))
+ .addListener((opt, event) -> booleanOption.get().setAvailable(opt.pendingValue()))
.build())
.option(Option.<Boolean>createBuilder()
.name(Component.literal("Tick Box"))
@@ -137,6 +138,7 @@ public class GuiTest {
.option(Option.<Integer>createBuilder()
.name(Component.literal("Int Slider"))
.description(OptionDescription.createBuilder()
+ // noinspection deprecated
.gifImage(imageSample("sample4.gif"))
.build())
.binding(
@@ -462,6 +464,7 @@ public class GuiTest {
.description(OptionDescription.of(Component.literal("Yay!!!!!!")))
.build())
.build())
+ .category(sharedStateCategory())
.category(ConfigCategory.createBuilder()
.name(Component.literal("Category Test"))
.option(LabelOption.create(Component.literal("This is a test category!")))
@@ -496,12 +499,69 @@ public class GuiTest {
.build())
.save(() -> {
Minecraft.getInstance().options.save();
- ConfigTest.GSON.serializer().save();
+ ConfigTest.GSON.save();
})
)
.generateScreen(parent);
}
+ private static ConfigCategory sharedStateCategory() {
+ ConfigCategory.Builder builder = ConfigCategory.createBuilder()
+ .name(Component.literal("Shared State Test"));
+
+ StateManager<Boolean> sharedBoolean = StateManager.createSimple(new SelfContainedBinding<>(true));
+ builder.option(Option.<Boolean>createBuilder()
+ .name(Component.literal("Shared Boolean"))
+ .stateManager(sharedBoolean)
+ .controller(TickBoxControllerBuilder::create)
+ .build());
+ builder.option(Option.<Boolean>createBuilder()
+ .name(Component.literal("Shared Boolean"))
+ .stateManager(sharedBoolean)
+ .controller(BooleanControllerBuilder::create)
+ .build());
+
+ StateManager<String> sharedString = StateManager.createSimple(new SelfContainedBinding<>(""));
+ builder.option(Option.<String>createBuilder()
+ .name(Component.literal("Shared String"))
+ .stateManager(sharedString)
+ .controller(StringControllerBuilder::create)
+ .build());
+ builder.option(Option.<String>createBuilder()
+ .name(Component.literal("Shared String"))
+ .stateManager(sharedString)
+ .controller(StringControllerBuilder::create)
+ .build());
+
+ StateManager<Integer> sharedInt = StateManager.createSimple(new SelfContainedBinding<>(0));
+ builder.option(Option.<Integer>createBuilder()
+ .name(Component.literal("Shared Int"))
+ .stateManager(sharedInt)
+ .controller(opt -> IntegerSliderControllerBuilder.create(opt)
+ .range(0, 10).step(1))
+ .build());
+ builder.option(Option.<Integer>createBuilder()
+ .name(Component.literal("Shared Int"))
+ .stateManager(sharedInt)
+ .controller(IntegerFieldControllerBuilder::create)
+ .build());
+
+ StateManager<Color> sharedColor = StateManager.createSimple(new SelfContainedBinding<>(Color.RED));
+ builder.option(Option.<Color>createBuilder()
+ .name(Component.literal("Shared Color"))
+ .stateManager(sharedColor)
+ .controller(ColorControllerBuilder::create)
+ .build());
+ builder.option(Option.<Color>createBuilder()
+ .name(Component.literal("Shared Color"))
+ .stateManager(sharedColor)
+ .controller(opt -> ColorControllerBuilder.create(opt)
+ .allowAlpha(true))
+ .build());
+
+ return builder.build();
+ }
+
private static ResourceLocation imageSample(String name) {
return YACLPlatform.rl("yacl_test", "textures/images/" + name);
}