Posted July 25, 20205 yr 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 July 25, 20205 yr by RubyNaxela
July 25, 20205 yr 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
July 25, 20205 yr 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.
July 25, 20205 yr 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 July 25, 20205 yr by RubyNaxela
July 25, 20205 yr 3 minutes ago, RubyNaxela said: so what's the correct way to do this? new TranslationTextComponent("block.moleculeforce.copper_ore").applyTextStyle(TextFormatting.GRAY); Edited July 25, 20205 yr by vemerion
July 25, 20205 yr 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 July 25, 20205 yr 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.