Make Biome implement Translatable (#8161)

This commit is contained in:
Noah van der Aa 2022-07-20 18:23:26 +02:00
parent aa949f7a32
commit e484f0dd39
2 changed files with 39 additions and 1 deletions

View File

@ -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

View File

@ -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<ResourceKey<Biome>, 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());
+ }
+ }
}