mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 14:30:17 +01:00
Add effective name to ItemStack (#11770)
This commit is contained in:
parent
140577b762
commit
a07cec16f8
2 changed files with 20 additions and 0 deletions
|
@ -5,6 +5,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
import java.util.LinkedHashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
|
@ -710,6 +711,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 @NotNull Component effectiveName() {
|
||||
return this.craftDelegate.effectiveName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Minecraft updates are converting simple item stacks into more complex NBT oriented Item Stacks.
|
||||
*
|
||||
|
|
|
@ -5,6 +5,8 @@ import com.google.common.collect.ImmutableMap;
|
|||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.advancements.critereon.ItemPredicate;
|
||||
import net.minecraft.advancements.critereon.MinMaxBounds;
|
||||
import net.minecraft.core.Holder;
|
||||
|
@ -25,6 +27,7 @@ import org.bukkit.enchantments.Enchantment;
|
|||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@DelegateDeserialization(ItemStack.class)
|
||||
public final class CraftItemStack extends ItemStack {
|
||||
|
@ -467,6 +470,11 @@ public final class CraftItemStack extends ItemStack {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Component effectiveName() {
|
||||
return this.handle == null ? Component.empty() : PaperAdventure.asAdventure(this.handle.getStyledHoverName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSimilar(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
|
|
Loading…
Reference in a new issue