From 2fb0d7578e4ec5a5b25d7f75b4f85522b549cafe Mon Sep 17 00:00:00 2001 From: luluxiaoyu Date: Fri, 14 Jun 2024 20:24:43 +0800 Subject: [PATCH] chore: add some i18n keys --- gradle.properties | 2 +- .../java/cn/nstarmc/ash3/AshCommands.java | 22 ++-- src/main/java/cn/nstarmc/ash3/AshMod.java | 4 +- .../java/cn/nstarmc/ash3/DirectionEnum.java | 13 ++- .../cn/nstarmc/ash3/mixin/InGameHudMixin.java | 11 +- src/main/java/com/umollu/ash/AshCommands.java | 110 ------------------ .../resources/assets/ash3/lang/en_us.json | 38 +++--- .../resources/assets/ash3/lang/zh_cn.json | 38 +++--- src/main/resources/fabric.mod.json | 2 +- 9 files changed, 82 insertions(+), 158 deletions(-) delete mode 100644 src/main/java/com/umollu/ash/AshCommands.java diff --git a/gradle.properties b/gradle.properties index ba5f439..d1d32da 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ yarn_mappings=1.21+build.1 loader_version=0.15.11 # Mod Properties - mod_version = 1.5-mc1.21-SNAPSHOT + mod_version = 1.5.1-mc1.21-SNAPSHOT maven_group = cn.nstarmc archives_base_name = ash3 diff --git a/src/main/java/cn/nstarmc/ash3/AshCommands.java b/src/main/java/cn/nstarmc/ash3/AshCommands.java index 37058ca..009d3c6 100644 --- a/src/main/java/cn/nstarmc/ash3/AshCommands.java +++ b/src/main/java/cn/nstarmc/ash3/AshCommands.java @@ -9,17 +9,17 @@ public class AshCommands { - private static final String COMMAND_TOGGLE = "ash2toggle"; - private static final String COMMAND_RESET = "ash2reset"; - private static final String COMMAND_FPS = "ash2togglefps"; - private static final String COMMAND_COORDS = "ash2togglecoords"; - private static final String COMMAND_DIRECTION = "ash2toggledirection"; - private static final String COMMAND_COLOR = "ash2color"; - private static final String COMMAND_BACKGROUND_COLOR = "ash2backgroundcolor"; - private static final String COMMAND_LIGHTLEVEL = "ash2togglelightlevel"; - private static final String COMMAND_TIME = "ash2toggletime"; - private static final String COMMAND_CONCISE_COORDS = "ash2toggleconcisecoords"; - private static final String COMMAND_TOGGLE_BACKGROUND = "ash2togglebackground"; + private static final String COMMAND_TOGGLE = "ash3toggle"; + private static final String COMMAND_RESET = "ash3reset"; + private static final String COMMAND_FPS = "ash3togglefps"; + private static final String COMMAND_COORDS = "ash3togglecoords"; + private static final String COMMAND_DIRECTION = "ash3toggledirection"; + private static final String COMMAND_COLOR = "ash3color"; + private static final String COMMAND_BACKGROUND_COLOR = "ash3backgroundcolor"; + private static final String COMMAND_LIGHTLEVEL = "ash3togglelightlevel"; + private static final String COMMAND_TIME = "ash3toggletime"; + private static final String COMMAND_CONCISE_COORDS = "ash3toggleconcisecoords"; + private static final String COMMAND_TOGGLE_BACKGROUND = "ash3togglebackground"; public static AshConfig config; diff --git a/src/main/java/cn/nstarmc/ash3/AshMod.java b/src/main/java/cn/nstarmc/ash3/AshMod.java index a51eccf..0d32974 100644 --- a/src/main/java/cn/nstarmc/ash3/AshMod.java +++ b/src/main/java/cn/nstarmc/ash3/AshMod.java @@ -13,14 +13,14 @@ public class AshMod implements ClientModInitializer { - public static final String MOD_ID = "ash2"; + public static final String MOD_ID = "ash3"; public static ConfigManager configManager; @Override public void onInitializeClient() { configManager = (ConfigManager) AutoConfig.register(AshConfig.class, GsonConfigSerializer::new); - KeyBinding toggleAsh = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.ash2.toggleAsh", InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), "key.categories.misc")); + KeyBinding toggleAsh = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.ash3.toggleAsh", InputUtil.Type.KEYSYM, InputUtil.UNKNOWN_KEY.getCode(), "key.categories.misc")); ClientTickEvents.END_CLIENT_TICK.register(client -> { while (toggleAsh.wasPressed()) { diff --git a/src/main/java/cn/nstarmc/ash3/DirectionEnum.java b/src/main/java/cn/nstarmc/ash3/DirectionEnum.java index 3b056e0..14dbb0d 100644 --- a/src/main/java/cn/nstarmc/ash3/DirectionEnum.java +++ b/src/main/java/cn/nstarmc/ash3/DirectionEnum.java @@ -1,9 +1,18 @@ package cn.nstarmc.ash3; +import net.minecraft.client.resource.language.I18n; + public enum DirectionEnum { - N("North"), NE("North-east"), E("East"), SE("South-east"), S("South"), SW("South-west"), W("West"), - NW("North-west"); + N(I18n.translate("direction.north")), + NE(I18n.translate("direction.northeast")), + E(I18n.translate("direction.east")), + SE(I18n.translate("direction.southeast")), + S(I18n.translate("direction.south")), + SW(I18n.translate("direction.southwest")), + W(I18n.translate("direction.west")), + NW(I18n.translate("direction.northwest")); + public String longName; diff --git a/src/main/java/cn/nstarmc/ash3/mixin/InGameHudMixin.java b/src/main/java/cn/nstarmc/ash3/mixin/InGameHudMixin.java index 86a2b68..e6bb45e 100644 --- a/src/main/java/cn/nstarmc/ash3/mixin/InGameHudMixin.java +++ b/src/main/java/cn/nstarmc/ash3/mixin/InGameHudMixin.java @@ -3,6 +3,7 @@ import cn.nstarmc.ash3.AshCommands; import cn.nstarmc.ash3.DirectionEnum; import net.minecraft.client.render.RenderTickCounter; +import net.minecraft.client.resource.language.I18n; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -117,7 +118,7 @@ private void drawCoordsAndDirection(DrawContext drawContext, MinecraftClient cli if (!AshCommands.config.showDirection || AshCommands.config.conciseCoords) return; - String ashString = "Direction: " + directionEnum.longName; + String ashString = I18n.translate("text.ash3.ui.direction") + directionEnum.longName; drawContext.drawTextWithShadow(client.textRenderer, ashString, TEXT_POS_X, textPosY, AshCommands.config.hudColor); if (AshCommands.config.showBackground) @@ -133,7 +134,7 @@ private void drawLightLevel(DrawContext drawContext, MinecraftClient client, Ent BlockPos blockPos = cameraEntity.getBlockPos(); int lightLevel = client.world.getLightLevel(LightType.BLOCK, blockPos); - String ashString = "Light Level: " + lightLevel; + String ashString = I18n.translate("text.ash3.ui.lightlevel") + lightLevel; int color = AshCommands.config.hudColor; if (lightLevel == 0) { @@ -154,7 +155,7 @@ private void drawBiome(DrawContext drawContext, MinecraftClient client, Entity c BlockPos blockPos = cameraEntity.getBlockPos(); String biomeKey = client.world.getBiome(blockPos).getKey().get().getValue().toTranslationKey("biome"); - String ashString = "Biome: " + Text.translatable(biomeKey).getString(); + String ashString = I18n.translate("text.ash3.ui.biome") + Text.translatable(biomeKey).getString(); drawContext.drawTextWithShadow(client.textRenderer, ashString, TEXT_POS_X, textPosY, AshCommands.config.hudColor); if (AshCommands.config.showBackground) @@ -173,9 +174,9 @@ private void drawTime(DrawContext drawContext, MinecraftClient client, Entity ca int minutes = (int) ((client.world.getTimeOfDay() / 1000d * 60) % 60); String ashString; if (minutes <= 9) { - ashString = String.format("Time: %d:0%d", hour, minutes); + ashString = String.format(I18n.translate("text.ash3.ui.time") + "%d:0%d", hour, minutes); } else { - ashString = String.format("Time: %d:%d", hour, minutes); + ashString = String.format(I18n.translate("text.ash3.ui.time") + "%d:%d", hour, minutes); } drawContext.drawTextWithShadow(client.textRenderer, ashString, TEXT_POS_X, textPosY, AshCommands.config.hudColor); diff --git a/src/main/java/com/umollu/ash/AshCommands.java b/src/main/java/com/umollu/ash/AshCommands.java deleted file mode 100644 index 87e0c90..0000000 --- a/src/main/java/com/umollu/ash/AshCommands.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.umollu.ash; - -import com.mojang.brigadier.arguments.IntegerArgumentType; -import com.umollu.ash.config.AshConfig; - -import me.shedaniel.autoconfig.AutoConfig; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager; -import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; - -public class AshCommands { - - public static AshConfig config; - - public static void registerCommands() { - - if (config == null) { - config = AutoConfig.getConfigHolder(AshConfig.class).getConfig(); - } - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("toggleash").executes(context -> { - config.showHud = !config.showHud; - AshMod.configManager.save(); - return 1; - })); - }); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("togglefps").executes(context -> { - config.showFps = !config.showFps; - AshMod.configManager.save(); - return 1; - })); - }); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("togglecoords").executes(context -> { - config.showCoords = !config.showCoords; - AshMod.configManager.save(); - return 1; - })); - }); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("toggledirection").executes(context -> { - config.showDirection = !config.showDirection; - AshMod.configManager.save(); - return 1; - })); - }); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("ashcolor") - .then(ClientCommandManager.argument("r", IntegerArgumentType.integer()) - .then(ClientCommandManager.argument("g", IntegerArgumentType.integer()) - .then(ClientCommandManager.argument("b", IntegerArgumentType.integer()) - .executes(context -> { - int r = IntegerArgumentType.getInteger(context, "r"); - int g = IntegerArgumentType.getInteger(context, "g"); - int b = IntegerArgumentType.getInteger(context, "b"); - - config.hudColor = b + (g << 8) + (r << 16); - AshMod.configManager.save(); - return 1; - }))))); - }); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("resetash").executes(context -> { - config = new AshConfig(); - AshMod.configManager.save(); - return 1; - })); - }); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("alignash") - .then(ClientCommandManager.literal("left").executes(context -> { - config.align = 0; - AshMod.configManager.save(); - return 1; - })).then(ClientCommandManager.literal("center").executes(context -> { - config.align = 1; - AshMod.configManager.save(); - return 1; - })).then(ClientCommandManager.literal("right").executes(context -> { - config.align = 2; - AshMod.configManager.save(); - return 1; - }))); - }); - - ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> { - dispatcher.register(ClientCommandManager.literal("valignash") - .then(ClientCommandManager.literal("top").executes(context -> { - config.verticalAlign = 0; - AshMod.configManager.save(); - return 1; - })).then(ClientCommandManager.literal("middle").executes(context -> { - config.verticalAlign = 1; - AshMod.configManager.save(); - return 1; - })).then(ClientCommandManager.literal("bottom").executes(context -> { - config.verticalAlign = 2; - AshMod.configManager.save(); - return 1; - }))); - }); - } -} \ No newline at end of file diff --git a/src/main/resources/assets/ash3/lang/en_us.json b/src/main/resources/assets/ash3/lang/en_us.json index e4f1279..e74499b 100644 --- a/src/main/resources/assets/ash3/lang/en_us.json +++ b/src/main/resources/assets/ash3/lang/en_us.json @@ -1,15 +1,27 @@ { - "text.autoconfig.ash2.title" : "ASH Config", - "text.autoconfig.ash2.option.showHud" : "Show HUD", - "text.autoconfig.ash2.option.hudColor" : "HUD text color", - "text.autoconfig.ash2.option.hudBackgroundColor" : "HUD background value", - "text.autoconfig.ash2.option.showFps" : "Show FPS", - "text.autoconfig.ash2.option.showCoords" : "Show coordinates", - "text.autoconfig.ash2.option.showDirection" : "Show direction", - "text.autoconfig.ash2.option.showLightLevel" : "Show light level", - "text.autoconfig.ash2.option.showBiome" : "Show biome", - "text.autoconfig.ash2.option.showTime" : "Show time", - "text.autoconfig.ash2.option.conciseCoords" : "Concise coords", - "text.autoconfig.ash2.option.showBackground" : "Show HUD background", - "key.ash2.toggleAsh" : "Toggle ASH HUD" + "text.autoconfig.ash3.title" : "ASH Config", + "text.autoconfig.ash3.option.showHud" : "Show HUD", + "text.autoconfig.ash3.option.hudColor" : "HUD text color", + "text.autoconfig.ash3.option.hudBackgroundColor" : "HUD background value", + "text.autoconfig.ash3.option.showFps" : "Show FPS", + "text.autoconfig.ash3.option.showCoords" : "Show coordinates", + "text.autoconfig.ash3.option.showDirection" : "Show direction", + "text.autoconfig.ash3.option.showLightLevel" : "Show light level", + "text.autoconfig.ash3.option.showBiome" : "Show biome", + "text.autoconfig.ash3.option.showTime" : "Show time", + "text.autoconfig.ash3.option.conciseCoords" : "Concise coords", + "text.autoconfig.ash3.option.showBackground" : "Show HUD background", + "key.ash3.toggleAsh" : "Toggle ASH HUD", + "direction.north": "North", + "direction.northeast": "North-East", + "direction.east": "East", + "direction.southeast": "South-East", + "direction.south": "South", + "direction.southwest": "South-West", + "direction.west": "West", + "direction.northwest": "North-West", + "text.ash3.ui.direction": "Direction: ", + "text.ash3.ui.lightlevel": "Light Level: ", + "text.ash3.ui.biome": "Biome: ", + "text.ash3.ui.time": "Time: " } \ No newline at end of file diff --git a/src/main/resources/assets/ash3/lang/zh_cn.json b/src/main/resources/assets/ash3/lang/zh_cn.json index c9d8eec..9a7fc17 100644 --- a/src/main/resources/assets/ash3/lang/zh_cn.json +++ b/src/main/resources/assets/ash3/lang/zh_cn.json @@ -1,15 +1,27 @@ { - "text.autoconfig.ash2.title" : "ASH3配置", - "text.autoconfig.ash2.option.showHud" : "显示游戏HUD", - "text.autoconfig.ash2.option.hudColor" : "HUD文字颜色", - "text.autoconfig.ash2.option.hudBackgroundColor" : "HUD背景颜色", - "text.autoconfig.ash2.option.showFps" : "显示FPS", - "text.autoconfig.ash2.option.showCoords" : "显示坐标", - "text.autoconfig.ash2.option.showDirection" : "显示反向", - "text.autoconfig.ash2.option.showLightLevel" : "显示光照等级", - "text.autoconfig.ash2.option.showBiome" : "显示生物群系", - "text.autoconfig.ash2.option.showTime" : "显示时间", - "text.autoconfig.ash2.option.conciseCoords" : "简单坐标", - "text.autoconfig.ash2.option.showBackground" : "显示HUD背景色", - "key.ash2.toggleAsh" : "切换 ASH HUD 是否显示" + "text.autoconfig.ash3.title" : "ASH3配置", + "text.autoconfig.ash3.option.showHud" : "显示游戏HUD", + "text.autoconfig.ash3.option.hudColor" : "HUD文字颜色", + "text.autoconfig.ash3.option.hudBackgroundColor" : "HUD背景颜色", + "text.autoconfig.ash3.option.showFps" : "显示FPS", + "text.autoconfig.ash3.option.showCoords" : "显示坐标", + "text.autoconfig.ash3.option.showDirection" : "显示反向", + "text.autoconfig.ash3.option.showLightLevel" : "显示光照等级", + "text.autoconfig.ash3.option.showBiome" : "显示生物群系", + "text.autoconfig.ash3.option.showTime" : "显示时间", + "text.autoconfig.ash3.option.conciseCoords" : "简单坐标", + "text.autoconfig.ash3.option.showBackground" : "显示HUD背景色", + "key.ash3.toggleAsh" : "切换 ASH HUD 是否显示", + "direction.north": "北", + "direction.northeast": "东北", + "direction.east": "东", + "direction.southeast": "东南", + "direction.south": "南", + "direction.southwest": "西南", + "direction.west": "西", + "direction.northwest": "西北", + "text.ash3.ui.direction": "方向: ", + "text.ash3.ui.lightlevel": "光照等级: ", + "text.ash3.ui.biome": "生物群系: ", + "text.ash3.ui.time": "时间: " } \ No newline at end of file diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 8937991..f7ed538 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -27,7 +27,7 @@ "ash3.mixins.json" ], "depends": { - "fabricloader": ">=0.14.22", + "fabricloader": ">=0.15", "fabric": "*", "minecraft": ">=1.21", "java": ">=21",