User Tools

Site Tools


tutorial:tooltip

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:tooltip [2021/02/10 10:08] – Updated names and added details magistermakstutorial:tooltip [2022/12/03 10:10] jab125
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) {
  
     // default white text     // default white text
-    tooltip.add( new TranslatableText("item.tutorial.fabric_item.tooltip") ); +    tooltip.add( new class_2588("item.tutorial.custom_item.tooltip")); 
-    +
     // formatted red text     // formatted red text
-    tooltip.add( new TranslatableText("item.tutorial.fabric_item.tooltip").formattedFormatting.RED ) )+    tooltip.add( new class_2588("item.tutorial.custom_item.tooltip").method_27692(class_124.field_1061) );
 } }
-</code>+</yarncode> 
 + 
 +For versions since 1.19: 
 +<yarncode java> 
 +@Override 
 +public void method_7851(class_1799 itemStack, class_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 : You can also append your tooltip in the [[tutorial:blocks|block]] class by overriding a similar method :
-<code java>+<yarncode java>
 @Override @Override
-public void appendTooltip(ItemStack itemStack, BlockView world, List<Text> tooltip, TooltipContext tooltipContext) { +public void method_9568(class_1799 itemStack, class_1922 world, List<class_2561> tooltip, class_1836 tooltipContext) { 
-    tooltip.add( new TranslatableText("block.tutorial.fabric_block.tooltip") );+    // for versions 1.18.2 and before 
 +    tooltip.add( new class_2588("block.tutorial.custom_block.tooltip") ); 
 +     
 +    // for versions since 1.19 
 +    tooltip.add(Text.translatable("block.tutorial.custom_block.tooltip"));
 } }
-</code>+</yarncode>
tutorial/tooltip.txt · Last modified: 2024/04/15 01:31 by solidblock