Search in sources :

Example 1 with IMixinText

use of org.spongepowered.common.interfaces.text.IMixinText in project SpongeCommon by SpongePowered.

the class MixinText method initializeComponent.

private ITextComponent initializeComponent() {
    if (this.component == null) {
        this.component = createComponent();
        Style style = this.component.getStyle();
        if (this.format.getColor() != TextColors.NONE) {
            style.setColor(((SpongeTextColor) this.format.getColor()).getHandle());
        }
        if (!this.format.getStyle().isEmpty()) {
            style.setBold(this.format.getStyle().isBold().orElse(null));
            style.setItalic(this.format.getStyle().isItalic().orElse(null));
            style.setUnderlined(this.format.getStyle().hasUnderline().orElse(null));
            style.setStrikethrough(this.format.getStyle().hasStrikethrough().orElse(null));
            style.setObfuscated(this.format.getStyle().isObfuscated().orElse(null));
        }
        if (this.clickAction.isPresent()) {
            style.setClickEvent(SpongeClickAction.getHandle(this.clickAction.get()));
        }
        if (this.hoverAction.isPresent()) {
            style.setHoverEvent(SpongeHoverAction.getHandle(this.hoverAction.get()));
        }
        if (this.shiftClickAction.isPresent()) {
            ShiftClickAction.InsertText insertion = (ShiftClickAction.InsertText) this.shiftClickAction.get();
            style.setInsertion(insertion.getResult());
        }
        for (Text child : this.children) {
            this.component.appendSibling(((IMixinText) child).toComponent());
        }
    }
    return this.component;
}
Also used : ShiftClickAction(org.spongepowered.api.text.action.ShiftClickAction) Style(net.minecraft.util.text.Style) IMixinText(org.spongepowered.common.interfaces.text.IMixinText) Text(org.spongepowered.api.text.Text)

Aggregations

Style (net.minecraft.util.text.Style)1 Text (org.spongepowered.api.text.Text)1 ShiftClickAction (org.spongepowered.api.text.action.ShiftClickAction)1 IMixinText (org.spongepowered.common.interfaces.text.IMixinText)1