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 TranslatableText("item.tutorial.custom_item.tooltip")); // formatted red text tooltip.add(new TranslatableText("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) { tooltip.add(Text.translatable("item.tutorial.custom_item.tooltip")); }
For versions since 1.20.5:
@Override public void appendTooltip(ItemStack itemStack, TooltipContext context, List<Text> tooltip, TooltipType type) { tooltip.add(Text.translatable("item.tutorial.custom_item.tooltip")); }
You can also append your tooltip in the block class by overriding a similar method:
For versions below 1.20.5:
@Override public void appendTooltip(ItemStack itemStack, BlockView world, List<Text> tooltip, TooltipContext tooltipContext) { // for versions 1.18.2 and before tooltip.add(new TranslatableText("block.tutorial.custom_block.tooltip")); // for versions since 1.19 tooltip.add(Text.translatable("block.tutorial.custom_block.tooltip")); }
For versions since 1.20.5:
@Override public void appendTooltip(ItemStack itemStack, Item.TooltipContext context, List<Text> tooltip, TooltipType options) { tooltip.add(Text.translatable("block.tutorial.custom_block.tooltip")); }
tutorial/tooltip.1713144696.txt.gz · Last modified: 2024/04/15 01:31 by solidblock