Class TContextMenu.Builder

java.lang.Object
com.thecsdev.commonmc.api.client.gui.ctxmenu.TContextMenu.Builder
Enclosing class:
TContextMenu

public static final class TContextMenu.Builder extends Object
A builder for creating a simple TContextMenu instance.
  • Constructor Details

    • Builder

      public Builder(@NotNull @NotNull net.minecraft.client.Minecraft client)
  • Method Details

    • setMaxWidth

      public final TContextMenu.Builder setMaxWidth(int maxWidth)
      Sets the maximum width of the context menu.
      Parameters:
      maxWidth - The maximum width in game's GUI units.
    • setMaxHeight

      public final TContextMenu.Builder setMaxHeight(int maxHeight)
      Sets the maximum height of the context menu.
      Parameters:
      maxHeight - The maximum height in game's GUI units.
    • setMaxSize

      public final TContextMenu.Builder setMaxSize(int maxWidth, int maxHeight)
      Sets the maximum size of the context menu.
      Parameters:
      maxWidth - The maximum width in game's GUI units.
      maxHeight - The maximum height in game's GUI units.
    • addElement

      public final TContextMenu.Builder addElement(@NotNull @NotNull TElement element) throws NullPointerException
      Adds a custom TElement to the context menu.
      Parameters:
      element - The TElement to add.
      Throws:
      NullPointerException - If the argument is null.
      API Note:
      This element will be stretched horizontally to fit the context menu's width.
    • addButton

      public final TContextMenu.Builder addButton(@NotNull @NotNull net.minecraft.network.chat.Component text, @NotNull @NotNull Consumer<TClickableWidget> onClick) throws NullPointerException
      Adds a TButtonWidget with the specified text to the context menu.
      Parameters:
      text - The text to display on the button.
      onClick - The callback to invoke when the button is clicked.
      Throws:
      NullPointerException - If the argument is null.
    • addContextMenu

      public final TContextMenu.Builder addContextMenu(@NotNull @NotNull net.minecraft.network.chat.Component text, @NotNull @NotNull Function<TClickableWidget, TContextMenu> menuBuilder) throws NullPointerException
      Adds a TButtonWidget that opens a sub-menu when clicked.
      Parameters:
      text - The text to display on the entry.
      menuBuilder - The TContextMenu builder function.
      Throws:
      NullPointerException - If an argument is null.
    • addSeparator

      public final TContextMenu.Builder addSeparator()
      Adds a separator line to the context menu.
    • build

      @NotNull public final @NotNull TContextMenu build()
      Builds and returns the TContextMenu instance.