Jump to content

Need Help to make an TextComponent with a Clickable Event in 1.18.2


Jonas Handtke

Recommended Posts

One Question:

What is the best Method to implement MutableComponent inside of displayClientMessage Method?

Here is a Code and tried to implement it inside it:
 

if (entity instanceof Player _player && !_player.level.isClientSide())
			_player.displayClientMessage(new TextComponent(("§6" + "Seed: " + "§r" new MutableComponent(world.getServer().overworld().getSeed()).withStyle(style -> style.bold(true)).build())), (false));

 

But got this Error:
error: MutableComponent is abstract; cannot be instantiated

Link to comment
Share on other sites

There is already is a command that does what you want.

See SeedCommand

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

No. You should do your own research. We are not going to write your mod for you.

 

In this case, look at how Mojang creates theirs in SeedCommand.

If you did this, you spent less than 20 minutes trying to figure it out for yourself.

hint: (Mutable)Component is an interface so you are looking for one of its concrete subclasses.

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

I got to made the Component that I copied from SeedCommand to work.

But the only issue that if I get the Component Variable inside the displayClientMessage and using getString() it only prints the String but not the Style to the chat.

I think I'm missing something...

Component TestComponent = ComponentUtils.wrapInSquareBrackets((new TextComponent(TestString)).withStyle((TestStyle) -> {
			return TestStyle.withColor(ChatFormatting.RED).withInsertion(TestString);
		}));
		if (entity instanceof Player _player && !_player.level.isClientSide())
			_player.displayClientMessage(new TextComponent(TestComponent.getString()), (false));

 

Link to comment
Share on other sites

Why are calling toString() on your Component and then wrapping that in another Component?

A java.lang.String is just an array of unicode characters. It has no way to understand or store Minecraft's style attachments.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

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.