Skip to content

How to make an item with a tooltip in a Minecraft mod

The lines under an item’s name come from a method in its class: appendHoverText, called addInformation on 1.12.2. Add components to the list it gives you (from 1.21.5 you pass each line to a consumer instead). Use a translatable component with a key in the lang file so the text can be translated, and withStyle(ChatFormatting.GRAY) for the usual colour.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Make a class that extends Item and override the tooltip method (appendHoverText).
  2. Add a translatable component with the gray style to the list.
  3. Write the text for the key in en_us.json.
  4. Register the item with your class.

The example uses these values. Change them in the code.

Setting In the example What it does
text Found in a shipwreck. The tooltip’s English text.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric and NeoForge 1.20.1 to 1.20.4, Fabric 1.19 to 1.20

Section titled “Fabric and NeoForge 1.20.1 to 1.20.4, Fabric 1.19 to 1.20”

Uses:

  • Item.appendHoverText
  • Component.translatable
  • ChatFormatting.GRAY

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import java.util.List;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
// Old Map: one grey line under its name, from en_us.json's item.examplemod.old_map.tooltip.
public class OldMapItem extends Item {
public OldMapItem(Item.Properties properties) {
super(properties);
}
@Override
public void appendHoverText(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(Component.translatable("item.examplemod.old_map.tooltip").withStyle(ChatFormatting.GRAY));
super.appendHoverText(stack, level, tooltip, flag);
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Fabric and NeoForge 1.20.5 to 1.21.1, Fabric and NeoForge 1.21.2 to 1.21.4

Section titled “Fabric and NeoForge 1.20.5 to 1.21.1, Fabric and NeoForge 1.21.2 to 1.21.4”

Uses:

  • Item.appendHoverText
  • Component.translatable
  • ChatFormatting.GRAY

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import java.util.List;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
// Old Map: one grey line under its name, from en_us.json's item.examplemod.old_map.tooltip.
public class OldMapItem extends Item {
public OldMapItem(Item.Properties properties) {
super(properties);
}
@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(Component.translatable("item.examplemod.old_map.tooltip").withStyle(ChatFormatting.GRAY));
super.appendHoverText(stack, context, tooltip, flag);
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Uses:

  • Item.appendHoverText
  • TooltipDisplay
  • Component.translatable
  • ChatFormatting.GRAY

Since 1.21.5 appendHoverText takes a TooltipDisplay and a Consumer<Component> instead of a List; call tooltip.accept(line).

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import java.util.function.Consumer;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.component.TooltipDisplay;
// Old Map: one grey line under its name, from en_us.json's item.examplemod.old_map.tooltip.
public class OldMapItem extends Item {
public OldMapItem(Item.Properties properties) {
super(properties);
}
@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext context, TooltipDisplay display, Consumer<Component> tooltip, TooltipFlag flag) {
tooltip.accept(Component.translatable("item.examplemod.old_map.tooltip").withStyle(ChatFormatting.GRAY));
super.appendHoverText(stack, context, display, tooltip, flag);
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Uses:

  • Item.appendHoverText
  • Component.translatable
  • ChatFormatting.GRAY

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import net.minecraft.network.chat.TranslatableComponent;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
// Old Map: one grey line under its name, from en_us.json's item.examplemod.old_map.tooltip.
public class OldMapItem extends Item {
public OldMapItem(Item.Properties properties) {
super(properties);
}
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(new TranslatableComponent("item.examplemod.old_map.tooltip").withStyle(ChatFormatting.GRAY));
super.appendHoverText(stack, level, tooltip, flag);
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Uses:

  • Item.appendHoverText
  • Component.translatable
  • ChatFormatting.GRAY

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
// Old Map: one grey line under its name, from en_us.json's item.examplemod.old_map.tooltip.
public class OldMapItem extends Item {
public OldMapItem(Item.Properties properties) {
super(properties);
}
@Override
public void appendHoverText(ItemStack stack, @Nullable Level level, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(Component.translatable("item.examplemod.old_map.tooltip").withStyle(ChatFormatting.GRAY));
super.appendHoverText(stack, level, tooltip, flag);
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Uses:

  • Item.appendHoverText
  • TranslationTextComponent
  • TextFormatting.GRAY

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import net.minecraft.util.text.TranslationTextComponent;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.world.World;
// Old Map: one grey line under its name, from en_us.json's item.examplemod.old_map.tooltip.
public class OldMapItem extends Item {
public OldMapItem(Item.Properties properties) {
super(properties);
}
@Override
public void appendHoverText(ItemStack stack, @Nullable World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
tooltip.add(new TranslationTextComponent("item.examplemod.old_map.tooltip").withStyle(TextFormatting.GRAY));
super.appendHoverText(stack, world, tooltip, flag);
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Uses:

  • Item.appendHoverText
  • Component.translatable
  • ChatFormatting.GRAY

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import net.minecraft.network.chat.TranslatableComponent;
import java.util.List;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.level.Level;
// Old Map: one grey line under its name, from en_us.json's item.examplemod.old_map.tooltip.
public class OldMapItem extends Item {
public OldMapItem(Item.Properties properties) {
super(properties);
}
@Override
public void appendHoverText(ItemStack stack, Level level, List<Component> tooltip, TooltipFlag flag) {
tooltip.add(new TranslatableComponent("item.examplemod.old_map.tooltip").withStyle(ChatFormatting.GRAY));
super.appendHoverText(stack, level, tooltip, flag);
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Uses:

  • Item.appendHoverText
  • TextComponentTranslation
  • TextFormatting.GRAY

In 1.12.2 the method is addInformation(stack, world, tooltip, flag) and the tooltip is a list of plain Strings, not components.

src/main/java/com/example/examplemod/item/OldMapItem.java

package com.example.examplemod.item;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
// Old Map: one grey line under its name, from the item.examplemod.old_map.tooltip line of the .lang file.
public class OldMapItem extends Item {
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, @Nullable World world, List<String> tooltip, ITooltipFlag flag) {
tooltip.add(TextFormatting.GRAY + I18n.format("item.examplemod.old_map.tooltip"));
}
}

In src/main/resources/assets/examplemod/lang/en_us.json:

{
"item.examplemod.old_map.tooltip": "Found in a shipwreck."
}

It’s registered like any other item, as OldMapItem: see a new item.

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.