Interface ComponentBuilder<C extends Component, B extends ComponentBuilder<C,B>>

Type Parameters:
C - the component type
B - the builder type
All Superinterfaces:
AbstractBuilder<C>, ComponentBuilderApplicable, ComponentLike, MutableStyleSetter<B>, StyleSetter<B>
All Known Subinterfaces:
BlockNBTComponent.Builder, EntityNBTComponent.Builder, KeybindComponent.Builder, NBTComponentBuilder<C,B>, ObjectComponent.Builder, ScoreComponent.Builder, SelectorComponent.Builder, StorageNBTComponent.Builder, TextComponent.Builder, TranslatableComponent.Builder

@NonExtendable public sealed interface ComponentBuilder<C extends Component, B extends ComponentBuilder<C,B>> extends AbstractBuilder<C>, ComponentBuilderApplicable, ComponentLike, MutableStyleSetter<B> permits KeybindComponent.Builder, NBTComponentBuilder<C,B>, ObjectComponent.Builder, ScoreComponent.Builder, SelectorComponent.Builder, TextComponent.Builder, TranslatableComponent.Builder (not exhaustive)
A component builder.
Since:
4.0.0
  • Method Details

    • append

      @Contract("_ -> this") B append(Component component)
      Appends a component to this component.
      Parameters:
      component - the component to append
      Returns:
      this builder
      Since:
      4.0.0
    • append

      @Contract("_ -> this") default B append(ComponentLike component)
      Appends a component to this component.
      Parameters:
      component - the component to append
      Returns:
      this builder
      Since:
      4.0.0
    • append

      @Contract("_ -> this") default B append(ComponentBuilder<?,?> builder)
      Appends a component to this component.
      Parameters:
      builder - the component to append
      Returns:
      this builder
      Since:
      4.0.0
    • append

      @Contract("_ -> this") B append(Component... components)
      Appends components to this component.
      Parameters:
      components - the components to append
      Returns:
      this builder
      Since:
      4.0.0
    • append

      @Contract("_ -> this") B append(ComponentLike... components)
      Appends components to this component.
      Parameters:
      components - the components to append
      Returns:
      this builder
      Since:
      4.0.0
    • append

      @Contract("_ -> this") B append(Iterable<? extends ComponentLike> components)
      Appends components to this component.
      Parameters:
      components - the components to append
      Returns:
      this builder
      Since:
      4.0.0
    • appendNewline

      default B appendNewline()
      Appends a newline to this component.
      Returns:
      this builder
      Since:
      4.12.0
    • appendSpace

      default B appendSpace()
      Appends a space to this component.
      Returns:
      this builder
      Since:
      4.12.0
    • apply

      @Contract("_ -> this") default B apply(Consumer<? super ComponentBuilder<?,?>> consumer)
      Applies an action to this builder.
      Parameters:
      consumer - the action
      Returns:
      this builder
      Since:
      4.0.0
    • applyDeep

      @Contract("_ -> this") B applyDeep(Consumer<? super ComponentBuilder<?,?>> action)
      Applies an action to this component and all child components.
      Parameters:
      action - the action
      Returns:
      this builder
      Since:
      4.0.0
    • mapChildren

      @Contract("_ -> this") B mapChildren(Function<Component, ? extends Component> function)
      Replaces each child of this component with the resultant component from the function.
      Parameters:
      function - the mapping function
      Returns:
      this builder
      Since:
      4.0.0
    • mapChildrenDeep

      @Contract("_ -> this") B mapChildrenDeep(Function<Component, ? extends Component> function)
      Replaces each child and sub-child of this component with the resultant component of the function.
      Parameters:
      function - the mapping function
      Returns:
      this builder
      Since:
      4.0.0
    • children

      List<Component> children()
      Get an unmodifiable list containing all children currently in this builder.
      Returns:
      the list of children
      Since:
      4.6.0
    • style

      @Contract("_ -> this") B style(Style style)
      Sets the style.
      Parameters:
      style - the style
      Returns:
      this builder
      Since:
      4.0.0
    • style

      @Contract("_ -> this") B style(Consumer<Style.Builder> consumer)
      Configures the style.
      Parameters:
      consumer - the style consumer
      Returns:
      this builder
      Since:
      4.0.0
    • font

      @Contract("_ -> this") B font(@Nullable Key font)
      Sets the font of this component.
      Specified by:
      font in interface StyleSetter<C extends Component>
      Parameters:
      font - the font
      Returns:
      this builder
      Since:
      4.0.0
    • color

      @Contract("_ -> this") B color(@Nullable TextColor color)
      Sets the color of this component.
      Specified by:
      color in interface StyleSetter<C extends Component>
      Parameters:
      color - the color
      Returns:
      this builder
      Since:
      4.0.0
    • colorIfAbsent

      @Contract("_ -> this") B colorIfAbsent(@Nullable TextColor color)
      Sets the color of this component if there isn't one set already.
      Specified by:
      colorIfAbsent in interface StyleSetter<C extends Component>
      Parameters:
      color - the color
      Returns:
      this builder
      Since:
      4.0.0
    • decorations

      @Contract("_, _ -> this") default B decorations(Set<TextDecoration> decorations, boolean flag)
      Sets the state of a set of decorations to flag on this component.
      Specified by:
      decorations in interface MutableStyleSetter<C extends Component>
      Specified by:
      decorations in interface StyleSetter<C extends Component>
      Parameters:
      decorations - the decorations
      flag - true if this component should have the decorations, false if this component should not have the decorations
      Returns:
      this builder
      Since:
      4.0.0
    • decorate

      @Contract("_ -> this") default B decorate(TextDecoration decoration)
      Sets the state of decoration to TextDecoration.State.TRUE.
      Specified by:
      decorate in interface StyleSetter<C extends Component>
      Parameters:
      decoration - the decoration
      Returns:
      this builder
      Since:
      4.0.0
    • decorate

      @Contract("_ -> this") default B decorate(TextDecoration... decorations)
      Sets decorations to TextDecoration.State.TRUE.
      Specified by:
      decorate in interface MutableStyleSetter<C extends Component>
      Specified by:
      decorate in interface StyleSetter<C extends Component>
      Parameters:
      decorations - the decorations
      Returns:
      this builder
      Since:
      4.0.0
    • decoration

      @Contract("_, _ -> this") default B decoration(TextDecoration decoration, boolean flag)
      Sets the state of a decoration on this component.
      Specified by:
      decoration in interface StyleSetter<C extends Component>
      Parameters:
      decoration - the decoration
      flag - true if this component should have the decoration, false if this component should not have the decoration
      Returns:
      this builder
      Since:
      4.0.0
    • decorations

      @Contract("_ -> this") default B decorations(Map<TextDecoration, TextDecoration.State> decorations)
      Sets decorations for this component's style using the specified decorations map.

      If a given decoration does not have a value explicitly set, the value of that particular decoration is not changed.

      Specified by:
      decorations in interface MutableStyleSetter<C extends Component>
      Specified by:
      decorations in interface StyleSetter<C extends Component>
      Parameters:
      decorations - a map containing text decorations and their respective state.
      Returns:
      this builder
      Since:
      4.10.0
    • decoration

      @Contract("_, _ -> this") B decoration(TextDecoration decoration, TextDecoration.State state)
      Sets the value of a decoration on this component.
      Specified by:
      decoration in interface StyleSetter<C extends Component>
      Parameters:
      decoration - the decoration
      state - TextDecoration.State.TRUE if this component should have the decoration, TextDecoration.State.FALSE if this component should not have the decoration, and TextDecoration.State.NOT_SET if the decoration should not have a set value
      Returns:
      this builder
      Since:
      4.0.0
    • decorationIfAbsent

      @Contract("_, _ -> this") B decorationIfAbsent(TextDecoration decoration, TextDecoration.State state)
      Sets the state of a decoration on this component to state if the current state of the decoration is TextDecoration.State.NOT_SET.
      Specified by:
      decorationIfAbsent in interface StyleSetter<C extends Component>
      Parameters:
      decoration - the decoration
      state - the state
      Returns:
      this builder
      Since:
      4.12.0
    • clickEvent

      @Contract("_ -> this") B clickEvent(@Nullable ClickEvent<?> event)
      Sets the click event of this component.
      Specified by:
      clickEvent in interface StyleSetter<C extends Component>
      Parameters:
      event - the click event
      Returns:
      this builder
      Since:
      4.0.0
    • hoverEvent

      @Contract("_ -> this") B hoverEvent(@Nullable HoverEventSource<?> source)
      Sets the hover event of this component.
      Specified by:
      hoverEvent in interface StyleSetter<C extends Component>
      Parameters:
      source - the hover event source
      Returns:
      this builder
      Since:
      4.0.0
    • insertion

      @Contract("_ -> this") B insertion(@Nullable String insertion)
      Sets the string to be inserted when this component is shift-clicked.
      Specified by:
      insertion in interface StyleSetter<C extends Component>
      Parameters:
      insertion - the insertion string
      Returns:
      this builder
      Since:
      4.0.0
    • mergeStyle

      @Contract("_ -> this") default B mergeStyle(Component that)
      Merges styling from another component into this component.
      Parameters:
      that - the other component
      Returns:
      this builder
      Since:
      4.0.0
    • mergeStyle

      @Contract("_, _ -> this") default B mergeStyle(Component that, Style.Merge... merges)
      Merges styling from another component into this component.
      Parameters:
      that - the other component
      merges - the parts to merge
      Returns:
      this builder
      Since:
      4.0.0
    • mergeStyle

      @Contract("_, _ -> this") B mergeStyle(Component that, Set<Style.Merge> merges)
      Merges styling from another component into this component.
      Parameters:
      that - the other component
      merges - the parts to merge
      Returns:
      this builder
      Since:
      4.0.0
    • resetStyle

      B resetStyle()
      Resets all styling on this component.
      Returns:
      this builder
      Since:
      4.0.0
    • build

      C build()
      Build a component.
      Specified by:
      build in interface AbstractBuilder<C extends Component>
      Returns:
      the component
    • applicableApply

      @Contract("_ -> this") default B applicableApply(ComponentBuilderApplicable applicable)
      Applies applicable.
      Parameters:
      applicable - the thing to apply
      Returns:
      this builder
      Since:
      4.0.0
    • componentBuilderApply

      default void componentBuilderApply(ComponentBuilder<?,?> component)
      Description copied from interface: ComponentBuilderApplicable
      Applies to component.
      Specified by:
      componentBuilderApply in interface ComponentBuilderApplicable
      Parameters:
      component - the component builder
    • asComponent

      default Component asComponent()
      Description copied from interface: ComponentLike
      Gets a Component representation.
      Specified by:
      asComponent in interface ComponentLike
      Returns:
      a component