Jump to content

getChatComponent only returning current line


DarkEyeDragon

Recommended Posts

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?

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

×
×
  • Create New...

Important Information

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