Add ItemStack#effectiveName

This commit is contained in:
masmc05 2024-12-13 16:11:06 +02:00
parent 2e97b7fe6b
commit e4c48cb651
No known key found for this signature in database
GPG key ID: 9EC8F5B2CFD24E42
2 changed files with 18 additions and 0 deletions

View file

@ -710,6 +710,17 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
return Bukkit.getServer().getItemFactory().displayName(this);
}
/**
* Gets the effective name of this item stack shown to player in inventory.
* It takes into account the display name (with italics) from the item meta,
* the potion effect, translatable name, rarity etc.
*
* @return the effective name of this item stack
*/
public net.kyori.adventure.text.@NotNull Component effectiveName() {
return this.craftDelegate.effectiveName();
}
/**
* Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks.
*

View file

@ -467,6 +467,13 @@ public final class CraftItemStack extends ItemStack {
return true;
}
// Paper start - add ItemStack#effectiveName
@Override
public net.kyori.adventure.text.Component effectiveName() {
return this.handle == null ? net.kyori.adventure.text.Component.empty() : io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getStyledHoverName());
}
// Paper end - add ItemStack#effectiveName
@Override
public boolean isSimilar(ItemStack stack) {
if (stack == null) {