Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ItemStack#effectiveName #11469

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions patches/api/0495-Add-ItemStack-effectiveName.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: masmc05 <[email protected]>
Date: Sat, 5 Oct 2024 04:23:14 +0300
Subject: [PATCH] Add ItemStack#effectiveName


diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index b59222b8c262545d100a9fd28b3bf1d2a4cf4eb0..7cf153d31c85fa852e90011392d1e09034bbee34 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -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.
*
34 changes: 34 additions & 0 deletions patches/server/1065-Add-ItemStack-effectiveName.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: masmc05 <[email protected]>
Date: Sat, 5 Oct 2024 04:23:13 +0300
Subject: [PATCH] Add ItemStack#effectiveName


diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
index f84e07fa0876bb6da0f99f4de6cb811f897adca2..c6a24aca51a612a02f677f2870b5afcfb7b2d47e 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
@@ -438,6 +438,23 @@ public final class CraftItemStack extends ItemStack {
return true;
}

+ // Paper start - add ItemStack#effectiveName
+ @Override
+ public net.kyori.adventure.text.Component effectiveName() {
+ // 1.21.2: return this.handle == null ? net.kyori.adventure.text.Component.empty() : io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getStyledHoverName());
+ if (this.handle == null) {
+ return net.kyori.adventure.text.Component.empty();
+ }
+ net.kyori.adventure.text.Component hover = io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getHoverName());
+ net.kyori.adventure.text.format.Style.Builder style = hover.style().toBuilder();
+ style.color(io.papermc.paper.adventure.PaperAdventure.asAdventure(this.handle.getRarity().color()));
+ if (this.handle.has(DataComponents.CUSTOM_NAME)) {
+ style.decoration(net.kyori.adventure.text.format.TextDecoration.ITALIC, true);
+ }
+ return hover.style(style);
+ }
+ // Paper end - add ItemStack#effectiveName
+
@Override
public boolean isSimilar(ItemStack stack) {
if (stack == null) {
Loading