From 3ca93a63b1dddbdbdee52823210e6cbc51a3bd60 Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Thu, 24 Oct 2024 19:10:24 +0200 Subject: [PATCH] fix: Add translation keys to NeoForge config options --- .../balm/neoforge/config/NeoForgeBalmConfig.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/config/NeoForgeBalmConfig.java b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/config/NeoForgeBalmConfig.java index 8caa983c..d4729710 100644 --- a/neoforge/src/main/java/net/blay09/mods/balm/neoforge/config/NeoForgeBalmConfig.java +++ b/neoforge/src/main/java/net/blay09/mods/balm/neoforge/config/NeoForgeBalmConfig.java @@ -15,6 +15,8 @@ import net.neoforged.fml.config.ModConfig; import net.neoforged.fml.event.config.ModConfigEvent; import net.neoforged.fml.loading.FMLPaths; +import net.neoforged.neoforge.client.gui.ConfigurationScreen; +import net.neoforged.neoforge.client.gui.IConfigScreenFactory; import net.neoforged.neoforge.common.ModConfigSpec; import net.neoforged.neoforge.server.ServerLifecycleHooks; import org.apache.logging.log4j.LogManager; @@ -48,6 +50,8 @@ private IConfigSpec createConfigSpec(Class clazz) private void buildConfigSpec(String parentPath, ModConfigSpec.Builder builder, Class clazz) throws IllegalAccessException { List fields = ConfigReflection.getAllFields(clazz); Object defaults = createConfigDataInstance(clazz); + final var modContainer = ModLoadingContext.get().getActiveContainer(); + final var modId = modContainer.getModId(); for (Field field : fields) { Class type = field.getType(); Object defaultValue = field.get(defaults); @@ -58,6 +62,8 @@ private void buildConfigSpec(String parentPath, ModConfigSpec.Builder builder, C builder.comment(comment.value()); } + builder.translation("config." + modId + "." + path); + if (String.class.isAssignableFrom(type)) { final var property = builder.define(path, (String) defaultValue); configProperties.put(clazz, path, property); @@ -243,9 +249,11 @@ private void writeConfigValues(String parentPath, Class clazz, T instance @Override public T initializeBackingConfig(Class clazz) { IConfigSpec configSpec = createConfigSpec(clazz); - ModLoadingContext.get().getActiveContainer().registerConfig(ModConfig.Type.COMMON, configSpec); + final var modContainer = ModLoadingContext.get().getActiveContainer(); + modContainer.registerConfig(ModConfig.Type.COMMON, configSpec); + modContainer.registerExtensionPoint(IConfigScreenFactory.class, ConfigurationScreen::new); - ModLoadingContext.get().getActiveContainer().getEventBus().addListener((ModConfigEvent.Loading event) -> { + modContainer.getEventBus().addListener((ModConfigEvent.Loading event) -> { configs.put(clazz, event.getConfig()); T newConfigData = readConfigValues(clazz, event.getConfig()); configData.put(clazz, newConfigData); @@ -253,7 +261,7 @@ public T initializeBackingConfig(Class clazz) { setActiveConfig(clazz, newConfigData); }); - ModLoadingContext.get().getActiveContainer().getEventBus().addListener((ModConfigEvent.Reloading event) -> { + modContainer.getEventBus().addListener((ModConfigEvent.Reloading event) -> { configs.put(clazz, event.getConfig()); T newConfigData = readConfigValues(clazz, event.getConfig()); configData.put(clazz, newConfigData);