testserver/patches/server/0519-Add-a-way-to-get-trans...

78 lines
3.6 KiB
Diff
Raw Normal View History

2021-06-11 12:02:28 +00:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: MeFisto94 <MeFisto94@users.noreply.github.com>
Date: Tue, 11 Aug 2020 19:16:09 +0200
Subject: [PATCH] Add a way to get translation keys for blocks, entities and
materials
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
2021-06-17 19:52:26 +00:00
index f38ccdecbade43983358dfbeadca86be7d15a68c..a8d9df5a31ba5d2ff01a7a7b3e99faa47e5eb1ef 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
2021-06-17 17:11:00 +00:00
@@ -290,6 +290,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
2021-06-11 12:02:28 +00:00
return Registry.ENTITY_TYPE.getKey(type);
}
2021-06-17 19:52:26 +00:00
+ @Deprecated public static Optional<EntityType<?>> getByName(String name) { return byString(name); } // Paper - OBFHELPER
2021-06-11 12:02:28 +00:00
public static Optional<EntityType<?>> byString(String id) {
return Registry.ENTITY_TYPE.getOptional(ResourceLocation.tryParse(id));
}
diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
2021-06-14 13:45:16 +00:00
index 64c304cab8c7c4c9c29f73465f99c11f224a72bd..b31eaa1459690d7f54989ba7a01f96a3f0d8d3b9 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
2021-06-14 13:45:16 +00:00
@@ -777,5 +777,10 @@ public class CraftBlock implements Block {
2021-06-11 12:02:28 +00:00
public com.destroystokyo.paper.block.BlockSoundGroup getSoundGroup() {
return new com.destroystokyo.paper.block.CraftBlockSoundGroup(getNMSBlock().defaultBlockState().getSoundType());
}
+
+ @Override
+ public String getTranslationKey() {
+ return org.bukkit.Bukkit.getUnsafe().getTranslationKey(this);
+ }
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
2021-06-17 19:37:37 +00:00
index d18f8d7c699893740fa709ef1f0caa4390e7eb20..91e61e7f5c1b47534408c48a280587ea03ae5a17 100644
2021-06-11 12:02:28 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -43,6 +43,7 @@ import org.bukkit.Registry;
import org.bukkit.UnsafeValues;
import org.bukkit.advancement.Advancement;
import org.bukkit.block.data.BlockData;
+import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.legacy.CraftLegacy;
@@ -418,6 +419,30 @@ public final class CraftMagicNumbers implements UnsafeValues {
throw new RuntimeException();
}
}
+
+ @Override
+ public String getTranslationKey(Material mat) {
+ if (mat.isBlock()) {
2021-06-17 19:37:37 +00:00
+ return getBlock(mat).getDescriptionId();
2021-06-11 12:02:28 +00:00
+ }
+ return getItem(mat).getDescriptionId();
+ }
+
+ @Override
+ public String getTranslationKey(org.bukkit.block.Block block) {
2021-06-17 19:37:37 +00:00
+ return ((org.bukkit.craftbukkit.block.CraftBlock)block).getNMS().getBlock().getDescriptionId();
2021-06-11 12:02:28 +00:00
+ }
+
+ @Override
+ public String getTranslationKey(org.bukkit.entity.EntityType type) {
+ return net.minecraft.world.entity.EntityType.getByName(type.getName()).map(net.minecraft.world.entity.EntityType::getDescriptionId).orElse(null);
+ }
+
+ @Override
+ public String getTranslationKey(org.bukkit.inventory.ItemStack itemStack) {
+ net.minecraft.world.item.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
+ return nmsItemStack.getItem().getDescriptionId(nmsItemStack);
+ }
// Paper end
/**