From 7be72ac9d9b7346edfec1d78f9560073b3fbb694 Mon Sep 17 00:00:00 2001 From: moonleay Date: Mon, 22 Apr 2024 23:30:24 +0200 Subject: [PATCH] feat: added TranslatableText support --- .gitignore | 1 + build.gradle.kts | 9 ++++-- .../client/keybindings/KeybindingRegistrar.kt | 20 ++++++------ .../mods/gimble/datagen/DataGenerator.kt | 3 +- .../datagen/En_us_GimbleLanguageProvider.kt | 32 +++++++++++++++++++ src/main/resources/fabric.mod.json | 6 ++++ 6 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 src/main/java/net/moonleay/mods/gimble/datagen/En_us_GimbleLanguageProvider.kt diff --git a/.gitignore b/.gitignore index 2501862..b0afcb5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ build/ !gradle/wrapper/gradle-wrapper.jar !**/src/main/**/build/ !**/src/test/**/build/ +generated/ ### IntelliJ IDEA ### .idea/ diff --git a/build.gradle.kts b/build.gradle.kts index ca0f1e6..7cf8da2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -53,6 +53,10 @@ repositories { } } +fabricApi { + configureDataGeneration() +} + dependencies { // To change the versions see the gradle.properties file minecraft("com.mojang:minecraft:$minecraftVersion") @@ -98,6 +102,7 @@ tasks { withType { filteringCharset = "UTF-8" + duplicatesStrategy = DuplicatesStrategy.INCLUDE inputs.properties(templateProps) filesMatching("fabric.mod.json") { expand(templateProps) @@ -117,13 +122,11 @@ tasks { if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible) { options.release.set(targetJavaVersion) } - dependsOn("generateTemplates", "processResources") } withType { kotlinOptions.jvmTarget = targetJavaVersion.toString() - dependsOn("generateTemplates", "processResources") } withType { @@ -132,7 +135,7 @@ tasks { } archiveBaseName.set(mavenArtifact) - + duplicatesStrategy = DuplicatesStrategy.INCLUDE dependsOn("generateTemplates", "processResources") } } diff --git a/src/main/java/net/moonleay/mods/gimble/client/keybindings/KeybindingRegistrar.kt b/src/main/java/net/moonleay/mods/gimble/client/keybindings/KeybindingRegistrar.kt index 86f6d32..87eb7d7 100644 --- a/src/main/java/net/moonleay/mods/gimble/client/keybindings/KeybindingRegistrar.kt +++ b/src/main/java/net/moonleay/mods/gimble/client/keybindings/KeybindingRegistrar.kt @@ -33,25 +33,25 @@ object KeybindingRegistrar { "gimble.key.editor.modifier.bulldozer", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_B, - "category.gimble.editormodifier" + "gimble.category.editormodifier" ) val toggleForcePlaceModifierShortcut = KeyBinding( "gimble.key.editor.modifier.forceplace", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F, - "category.gimble.editormodifier" + "gimble.category.editormodifier" ) val toggleNoUpdatesModifierShortcut = KeyBinding( "gimble.key.editor.modifier.noupdates", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_N, - "category.gimble.editormodifier" + "gimble.category.editormodifier" ) val toggleNoClipModifierShortcut = KeyBinding( "gimble.key.editor.modifier.noclip", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_C, - "category.gimble.editormodifier" + "gimble.category.editormodifier" ) KeybindingManager.registerShortcut(ToggleBulldozerModifierShortcut(toggleBulldozerModifierShortcut)) @@ -65,19 +65,19 @@ object KeybindingRegistrar { "gimble.key.editor.mode.insert", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_I, - "category.gimble.editormode" + "gimble.category.editormode" ) val replaceKeyBinding = KeyBinding( "gimble.key.editor.mode.replace", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_R, - "category.gimble.editormode" + "gimble.category.editormode" ) val visualKeyBinding = KeyBinding( "gimble.key.editor.mode.visual", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_V, - "category.gimble.editormode" + "gimble.category.editormode" ) KeybindingManager.registerShortcut(EnableInsertModeShortcut(insertKeyBinding)) KeybindingManager.registerShortcut(EnableReplaceModeShortcut(replaceKeyBinding)) @@ -89,19 +89,19 @@ object KeybindingRegistrar { "gimble.key.game.mode.survival", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, - "category.gimble.gamemode" + "gimble.category.gamemode" ) val creativeKeyBinding = KeyBinding( "gimble.key.game.mode.creative", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, - "category.gimble.gamemode" + "gimble.category.gamemode" ) val spectatorKeyBinding = KeyBinding( "gimble.key.game.mode.spectator", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, - "category.gimble.gamemode" + "gimble.category.gamemode" ) KeybindingManager.registerShortcut(SurvivalModeShortcut(survivalKeyBinding)) KeybindingManager.registerShortcut(CreativeModeShortcut(creativeKeyBinding)) diff --git a/src/main/java/net/moonleay/mods/gimble/datagen/DataGenerator.kt b/src/main/java/net/moonleay/mods/gimble/datagen/DataGenerator.kt index 301d524..d432acd 100644 --- a/src/main/java/net/moonleay/mods/gimble/datagen/DataGenerator.kt +++ b/src/main/java/net/moonleay/mods/gimble/datagen/DataGenerator.kt @@ -10,5 +10,6 @@ internal class DataGenerator : DataGeneratorEntrypoint { override fun onInitializeDataGenerator(fabricDataGenerator: FabricDataGenerator) { LOGGER.info("Starting Data Generation") + fabricDataGenerator.addProvider(En_us_GimbleLanguageProvider(fabricDataGenerator)) } -} \ No newline at end of file +} diff --git a/src/main/java/net/moonleay/mods/gimble/datagen/En_us_GimbleLanguageProvider.kt b/src/main/java/net/moonleay/mods/gimble/datagen/En_us_GimbleLanguageProvider.kt new file mode 100644 index 0000000..8196c14 --- /dev/null +++ b/src/main/java/net/moonleay/mods/gimble/datagen/En_us_GimbleLanguageProvider.kt @@ -0,0 +1,32 @@ +package net.moonleay.mods.gimble.datagen + +import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator +import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider + +class En_us_GimbleLanguageProvider(dataGenerator: FabricDataGenerator?) : + FabricLanguageProvider(dataGenerator, "en_us") { + + override fun generateTranslations(translationBuilder: TranslationBuilder?) { + if (translationBuilder == null) return + // Editor modes + translationBuilder.add("gimble.category.editormode", "Editor Modes") + translationBuilder.add("gimble.key.editor.mode.insert", "Enter Insert Mode") + translationBuilder.add("gimble.key.editor.mode.replace", "Enter Replace Mode") + translationBuilder.add("gimble.key.editor.mode.visual", "Enter Visual Mode") + + + // Editor mode modifiers + translationBuilder.add("gimble.category.editormodifier", "Editor Mode Modifiers") + translationBuilder.add("gimble.key.editor.modifier.bulldozer", "Toggle Bulldozer Modifier") + translationBuilder.add("gimble.key.editor.modifier.forceplace", "Toggle Force Place Modifier") + translationBuilder.add("gimble.key.editor.modifier.noupdates", "Toggle No Updates Modifier") + translationBuilder.add("gimble.key.editor.modifier.noclip", "Toggle No Clip Modifier") + + // Game mode + translationBuilder.add("gimble.category.gamemode", "Game Mode") + translationBuilder.add("gimble.key.game.mode.survival", "Enable Survival Mode") + translationBuilder.add("gimble.key.game.mode.creative", "Enable Creative Mode") + translationBuilder.add("gimble.key.game.mode.spectator", "Enable Spectator Mode") + + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a75e075..1ae3592 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,6 +22,12 @@ "adapter": "kotlin", "value": "net.moonleay.mods.gimble.Main" } + ], + "fabric-datagen": [ + { + "adapter": "kotlin", + "value": "net.moonleay.mods.gimble.datagen.DataGenerator" + } ] }, "mixins": [