ItemStack Tooltip API

This commit is contained in:
Yannick Lamprecht
2024-01-22 13:27:18 +01:00
parent eb68d0e1b5
commit de70580ea9
4 changed files with 112 additions and 0 deletions

View File

@@ -279,4 +279,6 @@ public interface UnsafeValues {
@org.jetbrains.annotations.ApiStatus.Internal
io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager<org.bukkit.plugin.Plugin> createPluginLifecycleEventManager(final org.bukkit.plugin.java.JavaPlugin plugin, final java.util.function.BooleanSupplier registrationCheck);
// Paper end - lifecycle event API
@NotNull java.util.List<net.kyori.adventure.text.Component> computeTooltipLines(@NotNull ItemStack itemStack, @NotNull io.papermc.paper.inventory.tooltip.TooltipContext tooltipContext, @Nullable org.bukkit.entity.Player player); // Paper - expose itemstack tooltip lines
}

View File

@@ -1124,4 +1124,21 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
return type.isAir() || amount <= 0;
}
// Paper end
// Paper start - expose itemstack tooltip lines
/**
* Computes the tooltip lines for this stack.
* <p>
* <b>Disclaimer:</b>
* Tooltip contents are not guaranteed to be consistent across different
* Minecraft versions.
*
* @param tooltipContext the tooltip context
* @param player a player for player-specific tooltip lines
* @return an immutable list of components (can be empty)
*/
@SuppressWarnings("deprecation") // abusing unsafe as a bridge
public java.util.@NotNull @org.jetbrains.annotations.Unmodifiable List<net.kyori.adventure.text.Component> computeTooltipLines(final @NotNull io.papermc.paper.inventory.tooltip.TooltipContext tooltipContext, final @Nullable org.bukkit.entity.Player player) {
return Bukkit.getUnsafe().computeTooltipLines(this, tooltipContext, player);
}
// Paper end - expose itemstack tooltip lines
}