User Tools

Site Tools


Sidebar

Setup

Basics

Advanced

Items

Blocks and Block Entities

Fluids

Entities

World Generation

Recipe Types

Miscellaneous

Events

Mixins

Dynamic Data Generation

Tutorials for Minecraft 1.15

Tutorials for Minecraft 1.14

Contribute to Fabric

Extremely Strange People

tutorial:tooltip

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.fabric_item.tooltip") );
 
    // formatted red text
    tooltip.add( new TranslatableText("item.tutorial.fabric_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.fabric_item.tooltip") );
 
    // formatted red text
    tooltip.add(Text.translatable("item.tutorial.fabric_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 TranslatableText("block.tutorial.fabric_block.tooltip") );
 
    // for versions since 1.19
    tooltip.add(Text.translatable("block.tutorial.fabric_block.tooltip") );
}

tutorial/tooltip.txt · Last modified: 2022/05/27 15:36 by solidblock