Class RenderTooltipEvent.GatherComponents

java.lang.Object
net.minecraftforge.eventbus.api.Event
net.minecraftforge.client.event.RenderTooltipEvent.GatherComponents
Enclosing class:
RenderTooltipEvent

public static class RenderTooltipEvent.GatherComponents extends net.minecraftforge.eventbus.api.Event
Fired when a tooltip gathers the TooltipComponents to be rendered, before any text wrapping or processing. The list of components and the maximum width of the tooltip can be modified through this event.

This event is cancellable, and does not have a result. If this event is cancelled, then the list of components will be empty, causing the tooltip to not be rendered and the corresponding RenderTooltipEvent.Pre and RenderTooltipEvent.Color to not be fired.

This event is fired on the main Forge event bus, only on the logical client.

  • Field Details

    • itemStack

      private final ItemStack itemStack
    • screenWidth

      private final int screenWidth
    • screenHeight

      private final int screenHeight
    • tooltipElements

      private final List<com.mojang.datafixers.util.Either<FormattedText,TooltipComponent>> tooltipElements
    • maxWidth

      private int maxWidth
  • Constructor Details

    • GatherComponents

      @Internal public GatherComponents(ItemStack itemStack, int screenWidth, int screenHeight, List<com.mojang.datafixers.util.Either<FormattedText,TooltipComponent>> tooltipElements, int maxWidth)
  • Method Details

    • getItemStack

      public ItemStack getItemStack()
      Returns the item stack which the tooltip is being rendered for, or an empty item stack if there is no associated item stack.
      Returns:
      the item stack which the tooltip is being rendered for, or an empty item stack if there is no associated item stack
    • getScreenWidth

      public int getScreenWidth()
      Returns the width of the screen.. The lines of text within the tooltip are wrapped to be within the screen width, and the tooltip box itself is moved to be within the screen width.
      Returns:
      the width of the screen
    • getScreenHeight

      public int getScreenHeight()
      Returns the height of the screen. The tooltip box is moved to be within the screen height.
      Returns:
      the height of the screen
    • getTooltipElements

      public List<com.mojang.datafixers.util.Either<FormattedText,TooltipComponent>> getTooltipElements()
      Returns the modifiable list of elements to be rendered on the tooltip. These elements can be either formatted text or custom tooltip components.
      Returns:
      the modifiable list of elements to be rendered on the tooltip
    • getMaxWidth

      public int getMaxWidth()
      Returns the maximum width of the tooltip when being rendered.

      A value of -1 means an unlimited maximum width. However, an unlimited maximum width will still be wrapped to be within the screen bounds.

      Returns:
      the maximum width of the tooltip when being rendered
    • setMaxWidth

      public void setMaxWidth(int maxWidth)
      Sets the maximum width of the tooltip. Use -1 for unlimited maximum width.
      Parameters:
      maxWidth - the new maximum width