mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 05:47:45 +01:00
Fix Material#getTranslationKey for Block Materials (#5294)
* Fix Material#getTranslationKey for Block Materials * Cache the result of Material#isBlock
This commit is contained in:
parent
b24a51c0e3
commit
b0df4d17c8
@ -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) {
|
||||
//<editor-fold defaultstate="collapsed" desc="isBlock">
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+ @Override
|
||||
+ public String getTranslationKey(Material mat) {
|
||||
+ if (mat.isBlock()) {
|
||||
+ return getBlock(mat).getDescriptionId();
|
||||
+ }
|
||||
+ return getItem(mat).getOrCreateDescriptionId();
|
||||
+ }
|
||||
+
|
||||
|
Loading…
Reference in New Issue
Block a user