3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 11:00:06 +01:00

Fix Material#getTranslationKey for Block Materials (#5294)

* Fix Material#getTranslationKey for Block Materials

* Cache the result of Material#isBlock
Dieser Commit ist enthalten in:
Jason 2021-03-02 16:27:34 -08:00 committet von GitHub
Ursprung 60e92c061b
Commit 45bc531dd3
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 46 neuen und 5 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,38 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: jmp <jasonpenilla2@me.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 2a3becabbd10fa8ffd19f35a3f6d8a6bfcb388c3..7b77c7132723a01e8c38ddaa616b363be300b653 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -3521,6 +3521,7 @@ 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);
@@ -3718,6 +3719,11 @@ 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:
@@ -4663,6 +4669,7 @@ public enum Material implements Keyed {
static {
for (Material material : values()) {
BY_NAME.put(material.name(), material);
+ material.isBlock = material.isBlock0(); // Paper
}
}

Datei anzeigen

@ -74,7 +74,7 @@ index f787238575ed7ac9108a2fd9782af55056219767..3524b677525bf2bb529b797fe1f258ef
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 324afd2a5e50a3b1fd9de926f6da8836b00e173b..865c1e4cf18b25ecf2ba8d592d9ca40f631e2215 100644
index 324afd2a5e50a3b1fd9de926f6da8836b00e173b..8f13e2685b8e68005d2c4d1613089f4d606fba94 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -45,6 +45,7 @@ import org.bukkit.Registry;
@ -85,13 +85,16 @@ index 324afd2a5e50a3b1fd9de926f6da8836b00e173b..865c1e4cf18b25ecf2ba8d592d9ca40f
import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.legacy.CraftLegacy;
@@ -393,6 +394,22 @@ public final class CraftMagicNumbers implements UnsafeValues {
@@ -393,6 +394,25 @@ public final class CraftMagicNumbers implements UnsafeValues {
throw new RuntimeException();
}
}
+
+ @Override
+ public String getTranslationKey(Material mat) {
+ if (mat.isBlock()) {
+ return getBlock(mat).getDescriptionId();
+ }
+ return getItem(mat).getOrCreateDescriptionId();
+ }
+

Datei anzeigen

@ -6,7 +6,7 @@ Subject: [PATCH] Expose the Entity Counter to allow plugins to use valid and
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index e65cb9c72e46d50b871d1c7b5789a1855622d934..9415588d7df27fb6907381cff802fd8ad983663f 100644
index a7b225249f7ffafa2c6e1fc60657067229e02960..fcb5cf78d1deff3c2593c7470f5501be8fed567b 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -3382,4 +3382,10 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
@ -21,10 +21,10 @@ index e65cb9c72e46d50b871d1c7b5789a1855622d934..9415588d7df27fb6907381cff802fd8a
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
index 865c1e4cf18b25ecf2ba8d592d9ca40f631e2215..e073db219a35c3ac02e4c5f65a9ad405cd148d1d 100644
index 8f13e2685b8e68005d2c4d1613089f4d606fba94..f37ab6dc33cda2aeb997db060b255acda3316b61 100644
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
@@ -410,6 +410,10 @@ public final class CraftMagicNumbers implements UnsafeValues {
@@ -413,6 +413,10 @@ public final class CraftMagicNumbers implements UnsafeValues {
return net.minecraft.server.EntityTypes.getByName(type.getName()).map(net.minecraft.server.EntityTypes::getDescriptionId).orElse(null);
}