From 0c8b646eefdc525b2a9d79d675ec305cae2bb0a2 Mon Sep 17 00:00:00 2001 From: isXander Date: Fri, 18 Aug 2023 11:46:16 +0100 Subject: More annotations to override option stuff --- .../config/v2/api/autogen/CustomDescription.java | 12 ++++ .../yacl3/config/v2/api/autogen/CustomFormat.java | 17 ++++++ .../yacl3/config/v2/api/autogen/CustomImage.java | 69 ++++++++++++++++++++++ .../yacl3/config/v2/api/autogen/CustomName.java | 18 ++++++ .../config/v2/api/autogen/FormatTranslation.java | 25 ++++++++ .../config/v2/api/autogen/OverrideFormatter.java | 17 ------ .../yacl3/config/v2/api/autogen/OverrideImage.java | 27 --------- .../yacl3/config/v2/api/autogen/OverrideName.java | 18 ------ .../config/v2/api/autogen/SimpleOptionFactory.java | 23 +++++--- .../yacl3/config/v2/impl/autogen/AutoGenUtils.java | 45 ++++++++------ .../config/v2/impl/autogen/DoubleFieldImpl.java | 3 + .../config/v2/impl/autogen/DoubleSliderImpl.java | 3 + .../v2/impl/autogen/EmptyCustomImageFactory.java | 6 +- .../config/v2/impl/autogen/FloatFieldImpl.java | 3 + .../config/v2/impl/autogen/FloatSliderImpl.java | 3 + .../yacl3/config/v2/impl/autogen/IntFieldImpl.java | 3 + .../config/v2/impl/autogen/IntSliderImpl.java | 3 + .../config/v2/impl/autogen/LongFieldImpl.java | 3 + .../config/v2/impl/autogen/LongSliderImpl.java | 3 + 19 files changed, 208 insertions(+), 93 deletions(-) create mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomDescription.java create mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomFormat.java create mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomImage.java create mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomName.java create mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/FormatTranslation.java delete mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideFormatter.java delete mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideImage.java delete mode 100644 common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideName.java (limited to 'common/src/main/java') diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomDescription.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomDescription.java new file mode 100644 index 0000000..08624b4 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomDescription.java @@ -0,0 +1,12 @@ +package dev.isxander.yacl3.config.v2.api.autogen; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface CustomDescription { + String[] value() default ""; +} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomFormat.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomFormat.java new file mode 100644 index 0000000..15f6336 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomFormat.java @@ -0,0 +1,17 @@ +package dev.isxander.yacl3.config.v2.api.autogen; + +import dev.isxander.yacl3.api.controller.ValueFormatter; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Allows you to specify a custom {@link ValueFormatter} for a field. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface CustomFormat { + Class> value(); +} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomImage.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomImage.java new file mode 100644 index 0000000..d193f42 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomImage.java @@ -0,0 +1,69 @@ +package dev.isxander.yacl3.config.v2.api.autogen; + +import dev.isxander.yacl3.config.v2.api.ConfigField; +import dev.isxander.yacl3.config.v2.impl.autogen.EmptyCustomImageFactory; +import dev.isxander.yacl3.gui.image.ImageRenderer; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; + +/** + * Defines a custom image for an option. + * Without this annotation, the option factory will look + * for the resource {@code modid:textures/yacl3/$config_id_path/$fieldName.webp}. + * WEBP was chosen as the default format because file sizes are greatly reduced, + * which is important to keep your JAR size down, if you're so bothered. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface CustomImage { + /** + * The resource path to the image, a {@link net.minecraft.resources.ResourceLocation} + * is constructed with the namespace being the modid of the config, and the path being + * this value. + *

+ * The following file formats are supported: + *

+ *

+ * If left blank, then {@link CustomImage#factory()} is used. + */ + String value() default ""; + + /** + * The width of the image, in pixels. + * This is only required when using a PNG with {@link CustomImage#value()} + */ + int width() default 0; + + /** + * The width of the image, in pixels. + * This is only required when using a PNG with {@link CustomImage#value()} + */ + int height() default 0; + + /** + * The factory to create the image with. + * For the average user, this should not be used as it breaks out of the + * API-safe environment where things could change at any time, but required + * when creating anything advanced with the {@link ImageRenderer}. + *

+ * The factory should contain a public, no-args constructor that will be + * invoked via reflection. + * + * @return the class of the factory + */ + Class> factory() default EmptyCustomImageFactory.class; + + interface CustomImageFactory { + CompletableFuture createImage(T value, ConfigField field, OptionAccess access); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomName.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomName.java new file mode 100644 index 0000000..aa235bb --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/CustomName.java @@ -0,0 +1,18 @@ +package dev.isxander.yacl3.config.v2.api.autogen; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Overrides the name of an auto-generated option. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface CustomName { + /** + * The translation key to use for the option's name. + */ + String value() default ""; +} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/FormatTranslation.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/FormatTranslation.java new file mode 100644 index 0000000..7cc4ded --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/FormatTranslation.java @@ -0,0 +1,25 @@ +package dev.isxander.yacl3.config.v2.api.autogen; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Allows you to specify a custom value formatter + * in the form of a translation key. + *

+ * Without this annotation, the value will be formatted + * according to the option factory, implementation details + * for that should be found in the javadoc for the factory. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface FormatTranslation { + /** + * The translation key for the value formatter. + * One parameter is passed to this key: the option's value, + * using {@link Object#toString()}. + */ + String value() default ""; +} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideFormatter.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideFormatter.java deleted file mode 100644 index f97395c..0000000 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideFormatter.java +++ /dev/null @@ -1,17 +0,0 @@ -package dev.isxander.yacl3.config.v2.api.autogen; - -import dev.isxander.yacl3.api.controller.ValueFormatter; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Allows you to specify a custom {@link ValueFormatter} for a field. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface OverrideFormatter { - Class> value(); -} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideImage.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideImage.java deleted file mode 100644 index 5a33884..0000000 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideImage.java +++ /dev/null @@ -1,27 +0,0 @@ -package dev.isxander.yacl3.config.v2.api.autogen; - -import dev.isxander.yacl3.config.v2.api.ConfigField; -import dev.isxander.yacl3.config.v2.impl.autogen.EmptyCustomImageFactory; -import dev.isxander.yacl3.gui.image.ImageRenderer; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; - -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface OverrideImage { - String value() default ""; - - int width() default 0; - int height() default 0; - - Class> factory() default EmptyCustomImageFactory.class; - - interface CustomImageFactory { - CompletableFuture> createImage(T value, ConfigField field, OptionAccess access); - } -} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideName.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideName.java deleted file mode 100644 index 8b73cec..0000000 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/OverrideName.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.isxander.yacl3.config.v2.api.autogen; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Overrides the name of an auto-generated option. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.FIELD) -public @interface OverrideName { - /** - * The translation key to use for the option's name. - */ - String value() default ""; -} diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java index 0ab6369..fc2957d 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/api/autogen/SimpleOptionFactory.java @@ -30,8 +30,7 @@ public abstract class SimpleOptionFactory implements Op .controller(opt -> { ControllerBuilder builder = this.createController(annotation, field, optionAccess, opt); - Optional customFormatter = field.access().getAnnotation(OverrideFormatter.class); - AutoGenUtils.addCustomFormatterToController(builder, customFormatter, field.access()); + AutoGenUtils.addCustomFormatterToController(builder, field.access()); return builder; }) @@ -47,8 +46,8 @@ public abstract class SimpleOptionFactory implements Op protected abstract ControllerBuilder createController(A annotation, ConfigField field, OptionAccess storage, Option option); protected MutableComponent name(A annotation, ConfigField field, OptionAccess storage) { - Optional customName = field.access().getAnnotation(OverrideName.class); - return Component.translatable(customName.map(OverrideName::value).orElse(this.getTranslationKey(field, null))); + Optional customName = field.access().getAnnotation(CustomName.class); + return Component.translatable(customName.map(CustomName::value).orElse(this.getTranslationKey(field, null))); } protected OptionDescription.Builder description(T value, A annotation, ConfigField field, OptionAccess storage) { @@ -65,14 +64,20 @@ public abstract class SimpleOptionFactory implements Op } } - Optional imageOverrideOpt = field.access().getAnnotation(OverrideImage.class); + field.access().getAnnotation(CustomDescription.class).ifPresent(customDescription -> { + for (String line : customDescription.value()) { + builder.text(Component.translatable(line)); + } + }); + + Optional imageOverrideOpt = field.access().getAnnotation(CustomImage.class); if (imageOverrideOpt.isPresent()) { - OverrideImage imageOverride = imageOverrideOpt.get(); + CustomImage imageOverride = imageOverrideOpt.get(); if (!imageOverride.factory().equals(EmptyCustomImageFactory.class)) { - OverrideImage.CustomImageFactory imageFactory; + CustomImage.CustomImageFactory imageFactory; try { - imageFactory = (OverrideImage.CustomImageFactory) AutoGenUtils.constructNoArgsClass( + imageFactory = (CustomImage.CustomImageFactory) AutoGenUtils.constructNoArgsClass( imageOverride.factory(), () -> "'%s': The factory class on @OverrideImage has no no-args constructor.".formatted(field.access().name()), () -> "'%s': Failed to instantiate factory class %s.".formatted(field.access().name(), imageOverride.factory().getName()) @@ -81,7 +86,7 @@ public abstract class SimpleOptionFactory implements Op throw new YACLAutoGenException("'%s': The factory class on @OverrideImage is of incorrect type. Expected %s, got %s.".formatted(field.access().name(), field.access().type().getTypeName(), imageOverride.factory().getTypeParameters()[0].getName())); } - builder.customImage(imageFactory.createImage(value, field, storage)); + builder.customImage(imageFactory.createImage(value, field, storage).thenApply(Optional::of)); } else if (!imageOverride.value().isEmpty()) { String path = imageOverride.value(); ResourceLocation imageLocation = new ResourceLocation(field.parent().id().getNamespace(), path); diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/AutoGenUtils.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/AutoGenUtils.java index 6bde931..6f614c1 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/AutoGenUtils.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/AutoGenUtils.java @@ -4,35 +4,42 @@ import dev.isxander.yacl3.api.controller.ControllerBuilder; import dev.isxander.yacl3.api.controller.ValueFormattableController; import dev.isxander.yacl3.api.controller.ValueFormatter; import dev.isxander.yacl3.config.v2.api.ReadOnlyFieldAccess; -import dev.isxander.yacl3.config.v2.api.autogen.OverrideFormatter; +import dev.isxander.yacl3.config.v2.api.autogen.CustomFormat; +import dev.isxander.yacl3.config.v2.api.autogen.FormatTranslation; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.ApiStatus; import java.util.Optional; -import java.util.function.Consumer; -import java.util.function.Function; import java.util.function.Supplier; @ApiStatus.Internal public final class AutoGenUtils { - public static void addCustomFormatterToController(ControllerBuilder controller, Optional formatter, ReadOnlyFieldAccess field) { + public static void addCustomFormatterToController(ControllerBuilder controller, ReadOnlyFieldAccess field) { + Optional formatter = field.getAnnotation(CustomFormat.class); + Optional translation = field.getAnnotation(FormatTranslation.class); + + if (formatter.isPresent() && translation.isPresent()) { + throw new YACLAutoGenException("'%s': Cannot use both @CustomFormatter and @FormatTranslation on the same field.".formatted(field.name())); + } else if (formatter.isEmpty() && translation.isEmpty()) { + return; + } + + if (!(controller instanceof ValueFormattableController)) { + throw new YACLAutoGenException("Attempted to use @CustomFormatter or @FormatTranslation on an option factory for field '%s' that uses a controller that does not support this.".formatted(field.name())); + } + + ValueFormattableController typedBuilder = (ValueFormattableController) controller; + formatter.ifPresent(formatterClass -> { - if (controller instanceof ValueFormattableController) { - ValueFormattableController typedBuilder; - try { - typedBuilder = (ValueFormattableController) controller; - } catch (ClassCastException e) { - throw new YACLAutoGenException("'%s': The formatter class on @CustomFormatter is of incorrect type. Expected %s, got %s.".formatted(field.name(), field.type().getTypeName(), formatterClass.value().getTypeParameters()[0].getName())); - } - - try { - typedBuilder.formatValue((ValueFormatter) formatterClass.value().getConstructor().newInstance()); - } catch (Exception e) { - throw new YACLAutoGenException("'%s': Failed to instantiate formatter class %s.".formatted(field.name(), formatterClass.value().getName()), e); - } - } else { - throw new YACLAutoGenException("Attempted to use @CustomFormatter on an option factory for field '%s' that uses a controller that does not support this.".formatted(field.name())); + try { + typedBuilder.formatValue((ValueFormatter) formatterClass.value().getConstructor().newInstance()); + } catch (Exception e) { + throw new YACLAutoGenException("'%s': Failed to instantiate formatter class %s.".formatted(field.name(), formatterClass.value().getName()), e); } }); + + translation.ifPresent(annotation -> + typedBuilder.formatValue(v -> Component.translatable(annotation.value(), v))); } public static T constructNoArgsClass(Class clazz, Supplier constructorNotFoundConsumer, Supplier constructorFailedConsumer) { diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleFieldImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleFieldImpl.java index d53d0f6..6445141 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleFieldImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleFieldImpl.java @@ -22,6 +22,9 @@ public class DoubleFieldImpl extends SimpleOptionFactory { key = getTranslationKey(field, "fmt.max"); if (key != null && Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.translatable(String.format(annotation.format(), v)); }) .range(annotation.min(), annotation.max()); diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleSliderImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleSliderImpl.java index 5221012..e6dd05d 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleSliderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/DoubleSliderImpl.java @@ -22,6 +22,9 @@ public class DoubleSliderImpl extends SimpleOptionFactory key = getTranslationKey(field, "fmt.max"); if (key != null && Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.translatable(String.format(annotation.format(), v)); }) .range(annotation.min(), annotation.max()) diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/EmptyCustomImageFactory.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/EmptyCustomImageFactory.java index 421de82..1500864 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/EmptyCustomImageFactory.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/EmptyCustomImageFactory.java @@ -2,16 +2,16 @@ package dev.isxander.yacl3.config.v2.impl.autogen; import dev.isxander.yacl3.config.v2.api.ConfigField; import dev.isxander.yacl3.config.v2.api.autogen.OptionAccess; -import dev.isxander.yacl3.config.v2.api.autogen.OverrideImage; +import dev.isxander.yacl3.config.v2.api.autogen.CustomImage; import dev.isxander.yacl3.gui.image.ImageRenderer; import java.util.Optional; import java.util.concurrent.CompletableFuture; -public class EmptyCustomImageFactory implements OverrideImage.CustomImageFactory { +public class EmptyCustomImageFactory implements CustomImage.CustomImageFactory { @Override - public CompletableFuture> createImage(Object value, ConfigField field, OptionAccess access) { + public CompletableFuture createImage(Object value, ConfigField field, OptionAccess access) { throw new IllegalStateException(); } } diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatFieldImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatFieldImpl.java index def5169..acdabd6 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatFieldImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatFieldImpl.java @@ -22,6 +22,9 @@ public class FloatFieldImpl extends SimpleOptionFactory { key = getTranslationKey(field, "fmt.max"); if (key != null && Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.translatable(String.format(annotation.format(), v)); }) .range(annotation.min(), annotation.max()); diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatSliderImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatSliderImpl.java index 6424bea..f22302f 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatSliderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/FloatSliderImpl.java @@ -22,6 +22,9 @@ public class FloatSliderImpl extends SimpleOptionFactory { key = getTranslationKey(field, "fmt.max"); if (key != null && Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.translatable(String.format(annotation.format(), v)); }) .range(annotation.min(), annotation.max()) diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntFieldImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntFieldImpl.java index e5f4e71..a3b759a 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntFieldImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntFieldImpl.java @@ -18,6 +18,9 @@ public class IntFieldImpl extends SimpleOptionFactory { String key = getTranslationKey(field, "fmt." + v); if (Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.literal(Integer.toString(v)); }) .range(annotation.min(), annotation.max()); diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntSliderImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntSliderImpl.java index d650837..b570b44 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntSliderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/IntSliderImpl.java @@ -18,6 +18,9 @@ public class IntSliderImpl extends SimpleOptionFactory { String key = getTranslationKey(field, "fmt." + v); if (Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.literal(Integer.toString(v)); }) .range(annotation.min(), annotation.max()) diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongFieldImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongFieldImpl.java index 41d20ca..5da7d20 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongFieldImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongFieldImpl.java @@ -18,6 +18,9 @@ public class LongFieldImpl extends SimpleOptionFactory { String key = getTranslationKey(field, "fmt." + v); if (Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.literal(Long.toString(v)); }) .range(annotation.min(), annotation.max()); diff --git a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongSliderImpl.java b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongSliderImpl.java index 3c1f778..95c5254 100644 --- a/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongSliderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/config/v2/impl/autogen/LongSliderImpl.java @@ -18,6 +18,9 @@ public class LongSliderImpl extends SimpleOptionFactory { String key = getTranslationKey(field, "fmt." + v); if (Language.getInstance().has(key)) return Component.translatable(key); + key = getTranslationKey(field, "fmt"); + if (Language.getInstance().has(key)) + return Component.translatable(key, v); return Component.literal(Long.toString(v)); }) .range(annotation.min(), annotation.max()) -- cgit