NullDev Posted March 4, 2021 Posted March 4, 2021 (edited) I am having some issues with text formatting. I format my text like this: player.sendStatusMessage(new StringTextComponent(ticksRemaining/20 + " §f| §4" + redstoneAdded + " §f| §a" + emeraldAdded + " §f| §b" + diamondAdded + " §f| §0" + coalAdded), true) and it appears like this in the game chat: Edited March 6, 2021 by NullDev Quote
NullDev Posted March 4, 2021 Author Posted March 4, 2021 On 3/4/2021 at 6:57 PM, diesieben07 said: IFormattableTextComponent#mergeStyle(TextFormatting) Expand I've done that like this, but now it just appears all black IFormattableTextComponent toSend = new StringTextComponent("Info: "); toSend.func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(ticksRemaining/20 + " | ")) .func_240701_a_(TextFormatting.RED) .func_230529_a_(new StringTextComponent(Integer.toString(redstoneAdded))) .func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(" | ")) .func_240701_a_(TextFormatting.GREEN) .func_230529_a_(new StringTextComponent(Integer.toString(emeraldAdded))) .func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(" | ")) .func_240701_a_(TextFormatting.AQUA) .func_230529_a_(new StringTextComponent(Integer.toString(diamondAdded))) .func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(" | ")) .func_240701_a_(TextFormatting.BLACK) .func_230529_a_(new StringTextComponent(Integer.toString(coalAdded))); player.sendStatusMessage(toSend, true); Quote
Toktom Posted March 5, 2021 Posted March 5, 2021 @diesieben07 I could not understand, how do we send mixed colored messages? For an example, I wanna send a message: Quote SKIL_NAME level: N Expand Where N (is any number, got through a method) and it's color is DARK_PURPLE and everything else is GOLD. How do I achieve that? Since using .append and .mergeStyle in a sequence doesn't work, as @NullDev tried. Quote
NullDev Posted March 5, 2021 Author Posted March 5, 2021 On 3/5/2021 at 11:33 AM, diesieben07 said: ou completely ignore the result of the methods you call and just use the original, unformatted, component. Expand I changed it to this and it is still all black: StringTextComponent toSend = new StringTextComponent("Info: "); player.sendStatusMessage(toSend.func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(ticksRemaining/20 + " | ")) .func_240701_a_(TextFormatting.RED) .func_230529_a_(new StringTextComponent(Integer.toString(redstoneAdded))) .func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(" | ")) .func_240701_a_(TextFormatting.GREEN) .func_230529_a_(new StringTextComponent(Integer.toString(emeraldAdded))) .func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(" | ")) .func_240701_a_(TextFormatting.AQUA) .func_230529_a_(new StringTextComponent(Integer.toString(diamondAdded))) .func_240701_a_(TextFormatting.WHITE) .func_230529_a_(new StringTextComponent(" | ")) .func_240701_a_(TextFormatting.BLACK) .func_230529_a_(new StringTextComponent(Integer.toString(coalAdded))), true); Quote
NullDev Posted March 5, 2021 Author Posted March 5, 2021 On 3/5/2021 at 5:14 PM, diesieben07 said: Every time you do that you overwrite the previously set color Expand So how would I do it without overriding it? Quote
NullDev Posted March 6, 2021 Author Posted March 6, 2021 On 3/5/2021 at 5:14 PM, diesieben07 said: You keep calling mergeStyle on the outer text component with a color Expand For anyone else with this issue, I figured it out. Do this for each new StringTextComponent: toReturn.func_230529_a_( new StringTextComponent("New Text With New Color").func_240701_a_(TextFormatting.WHITE) ) I call the mergestyle on the new StringTextComponent that I am adding with the appendText function. Quote
Recommended Posts
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.