User Tools

Site Tools


tutorial:tooltip

Differences

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

Link to this comparison view

Next revision
Previous revision
tutorial:tooltip [2019/07/24 12:48] – created fudgetutorial:tooltip [2022/12/16 00:21] (current) solidblock
Line 1: Line 1:
 ====== Adding a tooltip ====== ====== Adding a tooltip ======
-In your [[tutorial:items|item]] class, override ''appendTooltip'' like so (see [[tutorial:lang]] for how to translate the tooltip) : +In your [[tutorial:items|item]] class, override ''<yarn method_7851>'' like so (see [[tutorial:lang]] for how to translate the tooltip)
-<code java>+ 
 +For versions 1.18.2 and before
 +<yarncode java>
 @Override @Override
-public void appendTooltip(ItemStack itemStack, World world, List<Text> tooltip, TooltipContext tooltipContext) { +public void method_7851(class_1799 itemStack, class_1937 world, List<class_2561> tooltip, class_1836 tooltipContext) { 
-    tooltip.add(new TranslatableText("item.tutorial.fabric_item.tooltip"));+ 
 +    // default white text 
 +    tooltip.add(new TranslatableText("item.tutorial.custom_item.tooltip")); 
 + 
 +    // formatted red text 
 +    tooltip.add(new TranslatableText("item.tutorial.custom_item.tooltip").method_27692(class_124.field_1061) );
 } }
-</code+</yarncode> 
-For a blockdo the same but override ''buildTooltip'' in your [[tutorial:blocks|block]] class.+ 
 +For versions since 1.19: 
 +<yarncode java> 
 +@Override 
 +public void method_7851(class_1799 itemStackclass_1937 world, List<class_2561> tooltip, class_1836 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").method_27692(class_124.field_1061)); 
 +
 +</yarncode> 
 + 
 +You can also append your tooltip in the [[tutorial:blocks|block]] class by overriding a similar method : 
 +<yarncode java> 
 +@Override 
 +public void method_9568(class_1799 itemStack, class_1922 world, List<class_2561> tooltip, class_1836 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")); 
 +
 +</yarncode>
tutorial/tooltip.1563972519.txt.gz · Last modified: 2019/07/24 12:48 by fudge