From a76a1ab86211f7afd884dbb180b1b1ccb642f267 Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Wed, 20 Jul 2022 18:23:26 +0200 Subject: [PATCH] Make Biome implement Translatable (#8161) --- ...-Add-methods-to-get-translation-keys.patch | 29 +++++++++++++++++-- ...-Add-methods-to-get-translation-keys.patch | 19 ++++++++++-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/patches/api/0221-Add-methods-to-get-translation-keys.patch b/patches/api/0221-Add-methods-to-get-translation-keys.patch index 1361cdee4..6e713111c 100644 --- a/patches/api/0221-Add-methods-to-get-translation-keys.patch +++ b/patches/api/0221-Add-methods-to-get-translation-keys.patch @@ -241,6 +241,31 @@ index 13eac9ad2c1672051635d1c35cc49239252e7a61..107e36ef02a9481954bd770ce9a55a0b + public @NotNull String translationKey() { + return "attribute.name." + this.key.getKey(); + } ++ // Paper end + } +diff --git a/src/main/java/org/bukkit/block/Biome.java b/src/main/java/org/bukkit/block/Biome.java +index 02c5fcbc76b2db6bf4eb7580456b5658c08272b4..d56e1b50dd7da18f40278cec4bfdc9414aae0be1 100644 +--- a/src/main/java/org/bukkit/block/Biome.java ++++ b/src/main/java/org/bukkit/block/Biome.java +@@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; + /** + * Holds all accepted Biomes in the default server + */ +-public enum Biome implements Keyed { ++public enum Biome implements Keyed, net.kyori.adventure.translation.Translatable { // Paper + OCEAN, + PLAINS, + DESERT, +@@ -88,4 +88,11 @@ public enum Biome implements Keyed { + public NamespacedKey getKey() { + return key; + } ++ ++ // Paper start ++ @Override ++ public @NotNull String translationKey() { ++ return "biome.minecraft." + this.key.getKey(); ++ } + // Paper end } diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java @@ -369,7 +394,7 @@ index c799ac46dbe257d470d3b236cf55b41240f5fda8..d61855b83da0776fe910dee8cde184c7 // Paper start - Add villager reputation API diff --git a/src/main/java/org/bukkit/inventory/CreativeCategory.java b/src/main/java/org/bukkit/inventory/CreativeCategory.java -index 5bd252c0ae3b09fe141d131360c67bb9bfbf5422..0ac1f47d1bea37630d1bb011e52eff90d7a31b41 100644 +index 5bd252c0ae3b09fe141d131360c67bb9bfbf5422..78587d9fabe6371a23a7963917b054dbe7603694 100644 --- a/src/main/java/org/bukkit/inventory/CreativeCategory.java +++ b/src/main/java/org/bukkit/inventory/CreativeCategory.java @@ -3,51 +3,64 @@ package org.bukkit.inventory; @@ -444,7 +469,7 @@ index 5bd252c0ae3b09fe141d131360c67bb9bfbf5422..0ac1f47d1bea37630d1bb011e52eff90 + public @org.jetbrains.annotations.NotNull String translationKey() { + return this.translationKey; + } -+ // Paper start ++ // Paper end + } diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java diff --git a/patches/server/0491-Add-methods-to-get-translation-keys.patch b/patches/server/0491-Add-methods-to-get-translation-keys.patch index f42ae5eb4..c099427ca 100644 --- a/patches/server/0491-Add-methods-to-get-translation-keys.patch +++ b/patches/server/0491-Add-methods-to-get-translation-keys.patch @@ -77,17 +77,21 @@ index 7d9a91b2afb6890a160c2cd1e1cf3f0fb6a10d92..c5d570131cd3c9b43ab7889454923c29 /** diff --git a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java -index fab3063fffa959ac7f0eb5937f2fae94d11b6591..94dacabea836bc27eb678bd4465d8b9a01d98d91 100644 +index fab3063fffa959ac7f0eb5937f2fae94d11b6591..9292a0119499d14c9ed170999ac3b8dfdd1f839a 100644 --- a/src/test/java/io/papermc/paper/world/TranslationKeyTest.java +++ b/src/test/java/io/papermc/paper/world/TranslationKeyTest.java -@@ -1,12 +1,24 @@ +@@ -1,12 +1,29 @@ package io.papermc.paper.world; import com.destroystokyo.paper.ClientOption; ++import net.minecraft.core.Registry; ++import net.minecraft.core.RegistryAccess; +import net.minecraft.network.chat.contents.TranslatableContents; ++import net.minecraft.resources.ResourceKey; import net.minecraft.world.entity.player.ChatVisiblity; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.level.GameType; ++import net.minecraft.world.level.biome.Biome; import org.bukkit.Difficulty; +import org.bukkit.FireworkEffect; +import org.bukkit.GameMode; @@ -100,13 +104,14 @@ index fab3063fffa959ac7f0eb5937f2fae94d11b6591..94dacabea836bc27eb678bd4465d8b9a import org.junit.Test; -public class TranslationKeyTest { ++import java.util.Map; +import java.util.Objects; + +public class TranslationKeyTest extends AbstractTestingBase { @Test public void testChatVisibilityKeys() { -@@ -15,4 +27,52 @@ public class TranslationKeyTest { +@@ -15,4 +32,60 @@ public class TranslationKeyTest { Assert.assertEquals(chatVisibility + "'s translation key doesn't match", ChatVisiblity.valueOf(chatVisibility.name()).getKey(), chatVisibility.translationKey()); } } @@ -157,5 +162,13 @@ index fab3063fffa959ac7f0eb5937f2fae94d11b6591..94dacabea836bc27eb678bd4465d8b9a + Assert.assertNotNull(bukkit); + Assert.assertEquals("translation key mismatch for " + bukkit, ((TranslatableContents) nms.getLongDisplayName().getContents()).getKey(), bukkit.translationKey()); + } ++ } ++ ++ @Test ++ public void testBiome() { ++ for (Map.Entry, Biome> nms : RegistryAccess.builtinCopy().registry(Registry.BIOME_REGISTRY).get().entrySet()) { ++ org.bukkit.block.Biome bukkit = org.bukkit.block.Biome.valueOf(nms.getKey().location().getPath().toUpperCase()); ++ Assert.assertEquals("translation key mismatch for " + bukkit, nms.getKey().location().toLanguageKey("biome"), bukkit.translationKey()); ++ } + } }