Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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
  • Author

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.

  • Author

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

3 minutes ago, RubyNaxela said:

so what's the correct way to do this?

new TranslationTextComponent("block.moleculeforce.copper_ore").applyTextStyle(TextFormatting.GRAY);

 

Edited by vemerion

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.