From e484f0dd39fb286cf4fbd31d99d0b91f7e04042c 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 | 27 ++++++++++++++++++- .../Add-methods-to-get-translation-keys.patch | 13 +++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/patches/api/Add-methods-to-get-translation-keys.patch b/patches/api/Add-methods-to-get-translation-keys.patch index 71b2e2b629..f3833b3b4c 100644 --- a/patches/api/Add-methods-to-get-translation-keys.patch +++ b/patches/api/Add-methods-to-get-translation-keys.patch @@ -241,6 +241,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/block/Biome.java ++++ b/src/main/java/org/bukkit/block/Biome.java +@@ -0,0 +0,0 @@ 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, +@@ -0,0 +0,0 @@ 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 @@ -444,7 +469,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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/Add-methods-to-get-translation-keys.patch b/patches/server/Add-methods-to-get-translation-keys.patch index 3adfd95868..aa5fcdfb34 100644 --- a/patches/server/Add-methods-to-get-translation-keys.patch +++ b/patches/server/Add-methods-to-get-translation-keys.patch @@ -84,10 +84,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 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,6 +104,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import org.junit.Test; -public class TranslationKeyTest { ++import java.util.Map; +import java.util.Objects; + +public class TranslationKeyTest extends AbstractTestingBase { @@ -157,5 +162,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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()); ++ } + } }