tutorial:tooltip
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:tooltip [2022/07/23 19:11] – Fixed whitespace consistency. darthjake | tutorial:tooltip [2025/07/09 01:55] (current) – typo fix cassiancc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Adding a tooltip ====== | ====== Adding a tooltip ====== | ||
| - | In your [[tutorial:items|item]] | + | ===== Item tooltip ===== |
| + | Sometimes you want to add some extra information when showing the tooltip of the [[items|item]]. To achieve this, you should | ||
| + | |||
| + | 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: | ||
| < | < | ||
| - | @Override | + | public |
| - | public | + | // ... |
| - | // default white text | + | |
| - | tooltip.add( new class_2588(" | + | public void method_7851(class_1799 itemStack, class_1937 world, List< |
| - | + | ||
| - | // formatted red text | + | |
| - | tooltip.add( new class_2588(" | + | tooltip.add(new |
| + | | ||
| + | | ||
| + | tooltip.add(new | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
| Line 17: | Line 24: | ||
| For versions since 1.19: | For versions since 1.19: | ||
| < | < | ||
| - | @Override | + | public |
| - | public | + | // ... |
| - | | + | |
| - | tooltip.add(Text.translatable(" | + | |
| + | | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | For versions since 1.20.5: | ||
| + | < | ||
| + | public class CustomItem extends Item { | ||
| + | // ... | ||
| - | | + | |
| - | tooltip.add(Text.translatable(" | + | |
| + | | ||
| + | } | ||
| } | } | ||
| </ | </ | ||
| + | > :!: 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: | ||
| < | < | ||
| - | @Override | + | public class CustomBlock extends Block { |
| - | public void method_9568(class_1799 itemStack, class_1922 world, List< | + | // ... |
| - | // for versions 1.18.2 and before | + | |
| - | tooltip.add( new class_2588(" | + | |
| + | public void method_9568(class_1799 itemStack, class_1922 world, List< | ||
| + | // for versions 1.18.2 and before | ||
| + | tooltip.add(new | ||
| | | ||
| - | | + | |
| - | tooltip.add(Text.translatable(" | + | tooltip.add(Text.translatable(" |
| + | } | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | For versions since 1.20.5, before 1.21.5: | ||
| + | < | ||
| + | public class CustomBlock extends Block { | ||
| + | // ... | ||
| + | |||
| + | @Override | ||
| + | public void method_9568(class_1799 itemStack, Item.TooltipContext context, List< | ||
| + | tooltip.add(Text.translatable(" | ||
| + | } | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== 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.1658603504.txt.gz · Last modified: 2022/07/23 19:11 by darthjake