From b0df4d17c8b7c78e8b8b598a0fb803d61cf38c7e Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 2 Mar 2021 16:27:34 -0800 Subject: [PATCH] Fix Material#getTranslationKey for Block Materials (#5294) * Fix Material#getTranslationKey for Block Materials * Cache the result of Material#isBlock --- ...Cache-the-result-of-Material-isBlock.patch | 38 +++++++++++++++++++ ...-translation-keys-for-blocks-entitie.patch | 3 ++ 2 files changed, 41 insertions(+) create mode 100644 Spigot-API-Patches/Cache-the-result-of-Material-isBlock.patch diff --git a/Spigot-API-Patches/Cache-the-result-of-Material-isBlock.patch b/Spigot-API-Patches/Cache-the-result-of-Material-isBlock.patch new file mode 100644 index 000000000..d50646286 --- /dev/null +++ b/Spigot-API-Patches/Cache-the-result-of-Material-isBlock.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> +Date: Tue, 2 Mar 2021 15:24:58 -0800 +Subject: [PATCH] Cache the result of Material#isBlock + + +diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/Material.java ++++ b/src/main/java/org/bukkit/Material.java +@@ -0,0 +0,0 @@ public enum Material implements Keyed { + public final Class data; + private final boolean legacy; + private final NamespacedKey key; ++ private boolean isBlock; // Paper + + private Material(final int id) { + this(id, 64); +@@ -0,0 +0,0 @@ public enum Material implements Keyed { + * @return true if this material is a block + */ + public boolean isBlock() { ++ // Paper start - cache isBlock ++ return this.isBlock; ++ } ++ private boolean isBlock0() { ++ // Paper end + switch (this) { + // + case ACACIA_BUTTON: +@@ -0,0 +0,0 @@ public enum Material implements Keyed { + static { + for (Material material : values()) { + BY_NAME.put(material.name(), material); ++ material.isBlock = material.isBlock0(); // Paper + } + } + diff --git a/Spigot-Server-Patches/Add-a-way-to-get-translation-keys-for-blocks-entitie.patch b/Spigot-Server-Patches/Add-a-way-to-get-translation-keys-for-blocks-entitie.patch index 88991f589..2e083bee2 100644 --- a/Spigot-Server-Patches/Add-a-way-to-get-translation-keys-for-blocks-entitie.patch +++ b/Spigot-Server-Patches/Add-a-way-to-get-translation-keys-for-blocks-entitie.patch @@ -92,6 +92,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + @Override + public String getTranslationKey(Material mat) { ++ if (mat.isBlock()) { ++ return getBlock(mat).getDescriptionId(); ++ } + return getItem(mat).getOrCreateDescriptionId(); + } +