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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Forge Version: 38.0.6 Minecraft Version: 1.18 Downloads: Changelog: (Direct) Installer: (AdFocus) (Direct) MDK: (AdFocus) (Direct) However, as this is the start of a new version, it is recommended that you check the Downloads Page and use the latest version to receive any bug fixes. Intro: 1.17 was a stepping stone, and 1.18 is the real target. The culmination of the Caves & Cliffs update, with few real code changes from 1.17 except those required to plug in the new biome system. This is our new Latest version. As we had some time before the release, we handled some refactors beforehand. Those will be listed here. Changelog: Refactors (not comprehensive): 99% of the fmllegacy package. Most classes were simply moved from x.y.fmllegacy.z to x.y.z. All instances of Gui -> Screen (GuiOpenEvent -> ScreenOpenEvent, for example) GuiScreenEvent -> ScreenEvent, GuiOverlayDebugForge -> ForgeDebugScreenOverlay All instances of GameMode -> GameType (ClientPlayerChangeGameModeEvent -> ClientPlayerChangedGameTypeEvent, for example) All instances of MatrixStack -> PoseStack (DrawSelectionEvent.matrix -> DrawSelectionEvent.poseStack, for example All instances of KeyBinding -> KeyMapping (ClickInputEvent.keyBinding -> ClickInputEvent.keyMapping, for example All instances of World -> Level All instances of WorldType -> WorldPreset (ForgeHooksClient.getDefaultWorldType -> ForgeHooksClient.getDefaultWorldPreset, for example All instances of NBT -> Tag (BlockSnapshot.getNbt -> BlockSnapshot.getTag, for example) All instances of Container -> Menu (IForgeContainerType -> IForgeMenuType, for example) PlaySoundEvent.sound -> PlaySoundEvent.originalSound PlaySoundEvent.result -> PlaySoundEvent.sound SoundEvent.manager -> SoundEvent.engine SoundEvent.SoundSourceEvent.source -> SoundEvent.SoundSourceEvent.channel FOVUpdateEvent -> FOVModifierEvent EntityViewRenderEvent.FOVModiier -> EntityViewRenderEvent.FieldOfView InputUpdateEvent -> MovementInputUpdateEvent InitScreenEvent.{...Widget...} -> {...Listener...} ForgeItemTagsProvider.func_240521_a_Colored -> copyColored MobSpawnInfoBuilder -> MobSpawnSettingBuilder BasicTrade -> BasicItemListing ModelLoader -> ForgeModelBakery ForgeWorldTypeScreens -> ForgeWorldPresetEditors StackList -> MultItemValue Removals: Entire Animation API IForgeTextureAtlasSprite IForgeItem.{showDurabiityBar, getDurabilityForDisplay, getRGBDurabilityForDisplay} ForgeHooksClient.refreshResources ModelBuilder.gui3d BlockInfo.{updateShift, getShx, getShy, getShz} CapabilityInject CapabilityManager.register ConditionalAdvancement.processConditions IForgeItem.isShield IForgeStructureFeature.{getDefaultSpawnList, getDefaultCreatureSpawnList} Forge's Constants class VanillaResourceType ForgeHooksClient.worldRenderPass (+ accessor) ForgeHooksClient.{preDraw, postDraw, getColorIndex} ScrollPanel.drawBackground Screen.{RenderToolTip, RenderComponentToolTip} ResourceManager.getResourceType LootPool.bonusRolls ForgeConfig - selectiveResourceReload PotionEvent.PotionAddedEvent ClientHooks ModFileResourcePack ResourcePackLoader.getResourcePackFor ResourcePackLoader.IPackInfoFinder ServerLifecycleHooks.buildPackFinder IResourceType ReloadRequirements CommandSetDimension
    • This is the error that I'm getting. WARNING: Unknown module: cpw.mods.securejarhandler specified to --add-exports WARNING: Unknown module: cpw.mods.securejarhandler specified to --add-opens Exception in thread "main" java.lang.module.FindException: Module org.objectweb.asm.util not found, required by org.openjdk.nashorn at java.base/java.lang.module.Resolver.findFail(Resolver.java:893) at java.base/java.lang.module.Resolver.resolve(Resolver.java:192) at java.base/java.lang.module.Resolver.resolve(Resolver.java:141) at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:492) at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:298) at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:83)   Tried various java versions,   8 and 16 to no avail. even tried bellsoft liberica full jre  and openjre   No clue what is going on and why there are such problems with Java now, seems like Oracle took their ball and wants to go home with the Java project. So many issues with various versions of it.  Any advice? Thanks,.
    • Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • I was whanting to play the classic crashlanding modpack but...: Java HotSpot(TM) 64-Bit Server VM warning: Using incremental CMS is deprecated and will likely be removed in a future release dez 01, 2021 6:40:13 PM net.minecraft.launchwrapper.LogWrapper log INFORMAÇÕES: Loading tweak class name cpw.mods.fml.common.launcher.FMLTweaker dez 01, 2021 6:40:13 PM net.minecraft.launchwrapper.LogWrapper log INFORMAÇÕES: Using primary tweak class name cpw.mods.fml.common.launcher.FMLTweaker dez 01, 2021 6:40:13 PM net.minecraft.launchwrapper.LogWrapper log INFORMAÇÕES: Calling tweak class cpw.mods.fml.common.launcher.FMLTweaker 2021-12-01 18:40:14 [INFORMAÇÕES] [ForgeModLoader] Forge Mod Loader version 6.4.50.1,345 for Minecraft 1.6.4 loading 2021-12-01 18:40:14 [INFORMAÇÕES] [ForgeModLoader] Java is Java HotSpot(TM) 64-Bit Server VM, version 1.8.0_311, running on Windows 7:amd64:6.1, installed at C:\Program Files\Java\jre1.8.0_311 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod net.minecraftforge.lex.sortfix.CorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod appeng.transformer.AppEngCore does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] [AppEng] Core Init 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod codechicken.core.launch.DepLoader does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod invtweaks.forge.asm.FMLPlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod codechicken.nei.asm.NEICorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod openblocks.OpenBlocksCorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [ADVERTÊNCIA] [ForgeModLoader] The coremod openmods.OpenModsCorePlugin does not have a MCVersion annotation, it may cause issues with this version of Minecraft 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Loading tweak class name cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Loading tweak class name cpw.mods.fml.common.launcher.FMLDeobfTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker 2021-12-01 18:40:15 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:15 [INFORMAÇÕES] [STDOUT] Loaded 40 rules from AccessTransformer config file fml_at.cfg 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Found valid fingerprint for Minecraft Forge. Certificate fingerprint e3c3d50c7c986df74c645c0ac54639741c90a557 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Found valid fingerprint for Minecraft. Certificate fingerprint cd99959656f753dc28d863b46769f7f8fbaefcfc 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [STDOUT] Loaded 110 rules from AccessTransformer config file forge_at.cfg 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Warning: version of CodeChickenLib-universal-1.6.4-, 1.0.0.62 is newer than request 1.0.0.43 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [ForgeModLoader] Calling tweak class cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Exception in thread "main" java.lang.NoClassDefFoundError: codechicken/core/launch/CodeChickenCorePlugin 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at codechicken.nei.asm.NEICorePlugin.getASMTransformerClass(NEICorePlugin.java:18) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at cpw.mods.fml.relauncher.CoreModManager$FMLPluginWrapper.injectIntoClassLoader(CoreModManager.java:97) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.Launch.launch(Launch.java:111) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.Launch.main(Launch.java:27) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Caused by: java.lang.ClassNotFoundException: codechicken.core.launch.CodeChickenCorePlugin 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:186) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at java.lang.ClassLoader.loadClass(Unknown Source) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at java.lang.ClassLoader.loadClass(Unknown Source) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     ... 4 more 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR] Caused by: java.lang.NullPointerException 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at org.objectweb.asm.ClassReader.<init>(Unknown Source) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at invtweaks.forge.asm.ContainerTransformer.transform(ContainerTransformer.java:116) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.LaunchClassLoader.runTransformers(LaunchClassLoader.java:274) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     at net.minecraft.launchwrapper.LaunchClassLoader.findClass(LaunchClassLoader.java:172) 2021-12-01 18:40:19 [INFORMAÇÕES] [STDERR]     ... 6 more How do i fix this?
    • Hi, I would like to know if it's possible to render the glowing effect with depth test so it won't be visible through walls? Should I implement my own render type buffer? Thanks!
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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