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

So i'm trying to get a ITextComponent from chat using 

ITextComponent textComponent = Minecraft.getMinecraft().ingameGUI.getChatGUI().getChatComponent(Mouse.getX(), Mouse.getY());

however it only returns the text on the current line.

 

Bit of context:

I'm trying to resolve image urls and display a preview of them ingame. that all works well however with links longer than a single chatline it only returns the line you click on.

 

I don't see why this is happening however as its added to a single ITextComponent

this is the code that extracts and formats URL's 

@SubscribeEvent
    public void ChatReceived(ClientChatReceivedEvent e){
        String text = e.getMessage().getUnformattedText();
        if(Filter.extractUrls(text).size() > 0){
            //e.setCanceled(true);
            for (String url : Filter.extractUrls(text)){
                ITextComponent link = new TextComponentString(url);
                link.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, url));
                link.getStyle().setColor(TextFormatting.GOLD);
                link.getStyle().setUnderlined(true);
                link.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString("Click to preview image")));
                Minecraft.getMinecraft().ingameGUI.getChatGUI().printChatMessage(link);
            }
        }
    }

this works just fine so thats not the issue.

 

is this supposed to act like this or should this be reported as a possible bug?

 

  • Author

Well not really. It's more to prove i'm actually formatting the TextComponent properly. and (hopefully) adding it correctly to the chat.

 

so that the issue must be in retreiving the textcomonent

 

Edit: my entire point being. Is there a way to get multiple (aka the whole textcomponent) lines using getTextComponent? as it name suggests it would return an entire textcomponent and not cut off halfway because the other part is on a new line

Edited by DarkEyeDragon
clarification

  • Author

I'm replacing the GuiConfirmOpenLink implementation with my own. So i need to get the textcomponent thats clicked to extract the URL from it. Unless there's any other way of doing this?

 

Edit: I found out theres getClickEvent method (duhh) which makes things a lot easier.

String link = Objects.requireNonNull(textComponent.getStyle().getClickEvent()).getValue();

Thanks for the help! this issue is resolved now ?

Edited by DarkEyeDragon

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.