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
Last revisionBoth sides next revision
tutorial:tooltip [2022/04/13 08:07] – map2fabricyarn daomephstatutorial:tooltip [2022/12/16 00:21] solidblock
Line 1: Line 1:
 ====== Adding a tooltip ====== ====== Adding a tooltip ======
-In your [[tutorial:items|item]] class, override ''<yarn method_7851>'' 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)
 + 
 +For versions 1.18.2 and before:
 <yarncode java> <yarncode java>
 @Override @Override
Line 6: Line 8:
  
     // default white text     // default white text
-    tooltip.add( new class_2588("item.tutorial.fabric_item.tooltip") );+    tooltip.add(new TranslatableText("item.tutorial.custom_item.tooltip"));
  
     // formatted red text     // formatted red text
-    tooltip.add( new class_2588("item.tutorial.fabric_item.tooltip").method_27692(class_124.field_1061) );+    tooltip.add(new TranslatableText("item.tutorial.custom_item.tooltip").method_27692(class_124.field_1061) );
 } }
 </yarncode> </yarncode>
-You can also append your tooltip in the [[tutorial:blocks|block]] class by overriding a similar method :+ 
 +For versions since 1.19:
 <yarncode java> <yarncode java>
 @Override @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 :
 +<yarncode java>
 @Override @Override
 public void method_9568(class_1799 itemStack, class_1922 world, List<class_2561> tooltip, class_1836 tooltipContext) { public void method_9568(class_1799 itemStack, class_1922 world, List<class_2561> tooltip, class_1836 tooltipContext) {
-    tooltip.add( new class_2588("block.tutorial.fabric_block.tooltip") );+    // 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> </yarncode>
tutorial/tooltip.txt · Last modified: 2024/04/15 01:31 by solidblock