tutorial:tooltip
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:tooltip [2024/07/03 06:07] – solidblock | tutorial:tooltip [2025/07/09 01:55] (current) – typo fix cassiancc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Adding a tooltip ====== | ====== Adding a tooltip ====== | ||
| - | Sometimes you want to add some extra information when showing the tooltip of the [[item]]. To achieve this, you should override your own ''< | + | ===== Item tooltip ===== |
| + | Sometimes you want to add some extra information when showing the tooltip of the [[items|item]]. To achieve this, you should override your own ''< | ||
| - | Here we assume you have created your own class (see [[item]]), for example, '' | + | Here we assume you have created your own class (see [[items]]), for example, '' |
| For versions 1.18.2 and before: | For versions 1.18.2 and before: | ||
| Line 44: | Line 45: | ||
| } | } | ||
| </ | </ | ||
| + | > :!: The method is deprecated since 1.21.5. To add item tooltips for 1.21.5, please use Fabric API. | ||
| - | You can also append your tooltip in the [[tutorial:blocks|block]] class by overriding a similar method: | + | ===== Block tooltip ===== |
| + | You can also append your tooltip in the [[blocks|block]] class by overriding a similar method: | ||
| For versions below 1.20.5: | For versions below 1.20.5: | ||
| Line 63: | Line 66: | ||
| </ | </ | ||
| - | For versions since 1.20.5: | + | For versions since 1.20.5, before 1.21.5: |
| < | < | ||
| public class CustomBlock extends Block { | public class CustomBlock extends Block { | ||
| Line 74: | Line 77: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | ===== 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 '' | ||
| + | <code java> | ||
| + | ItemTooltipCallback.EVENT.register((itemStack, | ||
| + | if (!itemStack.isOf(TutorialItems.CUSTOM_ITEM)) { | ||
| + | return; | ||
| + | } | ||
| + | list.add(Text.translatable(" | ||
| + | }); | ||
| + | </ | ||
| + | |||
| + | The example adds a custom tooltip for the item we created in the [[items]] tutorial. | ||
tutorial/tooltip.1719986846.txt.gz · Last modified: 2024/07/03 06:07 by solidblock