User Tools

Site Tools


Sidebar

← Go back to the homepage

Fabric Tutorials

Setup

Basics

These pages are essential must-reads when modding with Fabric, and modding Minecraft in general, if you are new to modding, it is recommended you read the following.

Items

Blocks and Block Entities

Data Generation

World Generation

Commands

These pages will guide you through Mojang's Brigadier library which allows you to create commands with complex arguments and actions.

Events

These pages will guide you through using the many events included in Fabric API, and how to create your own events for you or other mods to use.

Entities

Fluids

Mixins & ASM

These pages will guide you through the usage of SpongePowered's Mixin library, which is a highly complex topic. We recommend you read these pages thoroughly.

Miscellaneous

Yarn

Contribute to Fabric

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.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) {
 
    // 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 TranslatableText("block.tutorial.custom_block.tooltip") );
 
    // for versions since 1.19
    tooltip.add(Text.translatable("block.tutorial.custom_block.tooltip"));
}

tutorial/tooltip.txt · Last modified: 2022/12/03 10:10 by jab125