Posted June 27, 20187 yr 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?
June 27, 20187 yr 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 June 27, 20187 yr by DarkEyeDragon clarification
June 27, 20187 yr 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 June 27, 20187 yr 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.