Jump to content

Forge 1.17 create TextComponents with ClickEvents


mistrx14

Recommended Posts

Hello, I'm currently having the problem that I can't figure out how I can add a ClickEvent or a HoverEvent to my TextComponent for my Forge 1.17 mod. I had it working in 1.16.5, but now it has changed.

I basically want to do it as shown in the image with ClickEvents for each of the elements.

 

image.png.21819c8725259d7f74d83bbe82d6b437.png

 

Edit:

Ok, I figured it out:

 

If you want to add a ClickEvent, you can use a Style.

I now have this in place:

 

TextComponent component = new TextComponent("Your Text here");

Style componentStyle = Style.EMPTY;
componentStyle = componentStyle.applyFormat(ChatFormatting.GREEN);
componentStyle = componentStyle.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, some_url));
component.setStyle(componentStyle);

 

It works, so I'm gonna leave it there

Edited by mistrx14
Solved it
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.

Announcements



×
×
  • Create New...

Important Information

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