tutorial:tooltip
This is an old revision of the document!
Adding a tooltip
In your item class, override appendTooltip
like so (see lang for how to translate the tooltip).
For versions 1.18.2 and before:
@Override public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { // default white text tooltip.add( new TranslatableTextContent("item.tutorial.custom_item.tooltip") ); // formatted red text tooltip.add( new TranslatableTextContent("item.tutorial.custom_item.tooltip").formatted(Formatting.RED) ); }
For versions since 1.19:
@Override public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { // default white text tooltip.add(Text.translatable("item.tutorial.custom_item.tooltip")); // formatted red text tooltip.add(Text.translatable("item.tutorial.custom_item.tooltip").formatted(Formatting.RED)); }
You can also append your tooltip in the block class by overriding a similar method :
@Override public void appendTooltip(ItemStack itemStack, BlockView world, List<Text> tooltip, TooltipContext tooltipContext) { // for versions 1.18.2 and before tooltip.add( new TranslatableTextContent("block.tutorial.custom_block.tooltip") ); // for versions since 1.19 tooltip.add(Text.translatable("block.tutorial.custom_block.tooltip")); }
tutorial/tooltip.1658603505.txt.gz · Last modified: 2022/07/23 19:11 by 127.0.0.1