Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to format parts of the text in a TextComponentString?


Alsan Ali
 Share

Recommended Posts

For example, I have a TextComponentString like this:

 

new TextComponentString("Hi, there!")

 

I want the 'Hi' to be blue and 'there' to be green. Also, how do we make parts of the text clickable? Like, if the player clicks 'hi' it will execute code

Edited by Alsan Ali
Forgot to mention some things
Link to comment
Share on other sites

25 minutes ago, Alsan Ali said:

For example, I have a TextComponentString like this:

 


new TextComponentString("Hi, there!")

 

I want the 'Hi' to be blue and 'there' to be green. Also, how do we make parts of the text clickable? Like, if the player clicks 'hi' it will execute code

 

use Color Codes.

http://minecraft.tools/en/color-code.php (use the MOTD one)

 

Example of something I use in my mod (the first line is in orange/gold + Italics. the next line is normal white)

Spoiler

@Override
    public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) {
        
        tooltip.add("\u00A76\u00A7o"+"The ore must first be crushed, chemically processed and then refined using Electrolysis.");
        tooltip.add("By-Products of this ore include Gallium, Iron Oxides, Silica (Silicon Oxide) and Titania (Titanium Oxide).");
    }

 

For the commands, look at how vanilla does it in the books. you wouldn't be limited by vanilla commands though, you could directly call your own java code

Edited by Cadiboo

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

9 minutes ago, diesieben07 said:

No.

 

Create a "base" TextComponentString with an empty string in it. Then you can use ITextComponent::appendSibling on it with differently formatted components to form one big component.

Thanks, I thought about doing this, just didn't know how to nest TextComponentStrings together. And can you tell me the reason why color codes can't be used? I just want to know

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.