User Tools

Site Tools


tutorial:tooltip
no way to compare when less than two revisions

Differences

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


Previous revision
Next revision
tutorial:tooltip [2021/02/10 10:08] – Updated names and added details magistermaks
Line 1: Line 1:
 +====== Adding a tooltip ======
 +In your [[tutorial:items|item]] class, override ''appendTooltip'' like so (see [[tutorial:lang]] for how to translate the tooltip) :
 +<code java>
 +@Override
 +public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) {
  
 +    // default white text
 +    tooltip.add( new TranslatableText("item.tutorial.fabric_item.tooltip") );
 +    
 +    // formatted red text
 +    tooltip.add( new TranslatableText("item.tutorial.fabric_item.tooltip").formatted( Formatting.RED ) )
 +}
 +</code>
 +You can also append your tooltip in the [[tutorial:blocks|block]] class by overriding a similar method :
 +<code java>
 +@Override
 +public void appendTooltip(ItemStack itemStack, BlockView world, List<Text> tooltip, TooltipContext tooltipContext) {
 +    tooltip.add( new TranslatableText("block.tutorial.fabric_block.tooltip") );
 +}
 +</code>
tutorial/tooltip.txt · Last modified: 2024/04/15 01:31 by solidblock