User Tools

Site Tools


tutorial:tooltip

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
tutorial:tooltip [2024/08/23 13:10] solidblocktutorial:tooltip [2025/04/01 08:15] (current) – (not moved totally because it's not a separate page on docs and it does not include old versions) solidblock
Line 1: Line 1:
-~~REDIRECT>https://docs.fabricmc.net/develop/items/first-item#custom-tooltips~~ 
- 
 ====== Adding a tooltip ====== ====== Adding a tooltip ======
 ===== Item tooltip ===== ===== Item tooltip =====
Line 47: Line 45:
 } }
 </yarncode> </yarncode>
 +> :!: The method is deprectaed since 1.21.5. To add item tooltips for 1.21.5, please use Fabric API.
  
 ===== Block tooltip ===== ===== Block tooltip =====
Line 67: Line 66:
 </yarncode> </yarncode>
  
-For versions since 1.20.5:+For versions since 1.20.5, before 1.21.5:
 <yarncode java> <yarncode java>
 public class CustomBlock extends Block { public class CustomBlock extends Block {
Line 78: Line 77:
 } }
 </yarncode> </yarncode>
 +
 +===== Adding tooltips in 1.21.5 =====
 +
 +Since 1.21.5, the implementation of item tooltips are rewritten. Most item tooltips are implemented with item components now, which may be influenced by ''tooltip_display'' item component to decide whether to display. However, you can still use Fabric API to add custom tooltips. Add the following code in the mod initializer in your code:
 +<code java>
 +    ItemTooltipCallback.EVENT.register((itemStack, tooltipContext, tooltipType, list) -> {
 +      if (!itemStack.isOf(TutorialItems.CUSTOM_ITEM)) {
 +        return;
 +      }
 +      list.add(Text.translatable("item.tutorial.custom_item.tooltip"));
 +    });
 +</code>
 +
 +The example adds a custom tooltip for the item we created in the [[items]] tutorial.
tutorial/tooltip.txt · Last modified: 2025/04/01 08:15 by solidblock