package net.minecraft.network.chat; import com.google.common.collect.Lists; import java.util.List; import java.util.Objects; import java.util.function.UnaryOperator; import net.minecraft.ChatFormatting; import net.minecraft.locale.Language; import net.minecraft.util.FormattedCharSequence; import org.jetbrains.annotations.Nullable; /** * A Component which can have its Style and siblings modified. */ public class MutableComponent implements Component { private final ComponentContents contents; private final List siblings; private Style style; private FormattedCharSequence visualOrderText = FormattedCharSequence.EMPTY; @Nullable private Language decomposedWith; MutableComponent(ComponentContents contents, List siblings, Style style) { this.contents = contents; this.siblings = siblings; this.style = style; } public static MutableComponent create(ComponentContents contents) { return new MutableComponent(contents, Lists.newArrayList(), Style.EMPTY); } @Override public ComponentContents getContents() { return this.contents; } @Override public List getSiblings() { return this.siblings; } /** * Sets the style for this component and returns the component itself. */ public MutableComponent setStyle(Style style) { this.style = style; return this; } @Override public Style getStyle() { return this.style; } /** * Add the given text to this component's siblings. * * Note: If this component turns the text bold, that will apply to all the siblings until a later sibling turns the text something else. */ public MutableComponent append(String string) { return string.isEmpty() ? this : this.append(Component.literal(string)); } /** * Add the given component to this component's siblings. * * Note: If this component turns the text bold, that will apply to all the siblings until a later sibling turns the text something else. */ public MutableComponent append(Component sibling) { this.siblings.add(sibling); return this; } public MutableComponent withStyle(UnaryOperator