Jump to content

[SOLVED] [1.16.1] Light gray tooltip on any item?


RubyNaxela

Recommended Posts

Hello,

What's the best approach to adding a light gray tooltip to either my mod item or vanilla item? I used to do it with Item.Properties#addInformation(String), but this method won't work for vanilla items.

There's a Forge event called ItemTooltipEvent. Will it do the job? How to use it?

By the way, I'd like to get the text from the language file. Can I do it with I18n? Actually an example method would be welcome.

Thanks in advance for any help!

Edited by RubyNaxela
Link to comment
Share on other sites

in ItemTooltipEvent

flags

tells you whether "advanced tooltip" is enabled (f3 + h or something), normally if it's true it will render its registry name as well such as testmod:testitem

itemStack

the itemstack in the chosen slot is being rendered

toolTip

a list of existing tooltips from

Item.addInformation()

 

If you want to add information on it just add the desire element to the list get from

event.getToolTip()

 

I'm not sure about how to get the text from the language file but you can use

TranslationTextComponent
Link to comment
Share on other sites

I tried the following:

package ...

import ...

@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class TooltipHandler {

    @SubscribeEvent(priority = EventPriority.NORMAL, receiveCanceled = true)
    public static void addItemToolTip(ItemTooltipEvent event) {
        ItemStack stack = event.getItemStack();
        if (stack.getItem() == Items.DIAMOND) {
            event.getToolTip().add(new TranslationTextComponent("desc.diamond.line1"));
        }
    }
  
  ...
}

But I get no tooltip at all.

Link to comment
Share on other sites

Okay, now the event is working with :

bus = Mod.EventBusSubscriber.Bus.FORGE

But there's one last thing, which is the color. I can't just do:

TextFormatting.GRAY + new TranslationTextComponent("desc.diamond.line1")

so what's the correct way to do this?

Edited by RubyNaxela
Link to comment
Share on other sites

Thank you for the hint. Although precisely what I need is IFormattableTextComponent#func_240699_a_(TextFormatting). I'm using a version that doesn't have this function mapped yet.

EDIT

For the most current mapping (20200723 as for today), it's IFormattableTextComponent#mergeStyle(TextFormatting)

Edited by RubyNaxela
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.