Jump to content

How to Reset Style for a TextComponent in 1.18.2?


Jonas Handtke

Recommended Posts

I made an Command that provides Information about the current World.

That includes the World Name.

Here is the Code:

Style WorldInfoStyle = Style.EMPTY;
WorldInfoStyle = Style.EMPTY.withColor(TextColor.fromRgb(0xFFAA00));
	if (entity instanceof Player _player && !_player.level.isClientSide())
		_player.displayClientMessage(new TextComponent("World Name: ").setStyle(WorldInfoStyle).append(new TextComponent(world.getServer().getWorldData().getLevelName()).setStyle(Style.EMPTY)), (false));

I want after "World Name: " that the Style gets resets to its default Plain Text/String.

I tried for myself at least 2-3 hours and tested a lot of other methods to reset the Style.

Am I missing something?

Link to comment
Share on other sites

https://forge.gemwire.uk/wiki/Components/1.18#BaseComponent

i.e. siblings inherit style from their parent (the thing they are append to).

You need to set a color instead of that setStyle(Style.EMPTY) which literally means propogate all the parent style to me.

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.



×
×
  • Create New...

Important Information

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