Class AbstractWidget

java.lang.Object
net.minecraft.client.gui.components.AbstractWidget
All Implemented Interfaces:
GuiEventListener, Renderable, TabOrderedElement, LayoutElement, NarratableEntry, NarrationSupplier, IAbstractWidgetExtension
Direct Known Subclasses:
AbstractButton, AbstractContainerWidget, AbstractScrollWidget, AbstractSliderButton, AbstractStringWidget, EditBox, GameModeSwitcherScreen.GameModeSlot, ImageWidget, LoadingDotsWidget, OverlayRecipeComponent.OverlayRecipeButton, PlayerSkinWidget, RecipeButton, StateSwitchingButton, TabButton

public abstract class AbstractWidget extends Object implements Renderable, GuiEventListener, LayoutElement, NarratableEntry, IAbstractWidgetExtension
  • Field Details

    • PERIOD_PER_SCROLLED_PIXEL

      private static final double PERIOD_PER_SCROLLED_PIXEL
      See Also:
    • MIN_SCROLL_PERIOD

      private static final double MIN_SCROLL_PERIOD
      See Also:
    • width

      protected int width
    • height

      protected int height
    • x

      private int x
    • y

      private int y
    • message

      private Component message
    • isHovered

      protected boolean isHovered
    • active

      public boolean active
    • visible

      public boolean visible
    • alpha

      protected float alpha
    • tabOrderGroup

      private int tabOrderGroup
    • focused

      private boolean focused
    • tooltip

      private final WidgetTooltipHolder tooltip
    • UNSET_FG_COLOR

      public static final int UNSET_FG_COLOR
      See Also:
    • packedFGColor

      protected int packedFGColor
  • Constructor Details

    • AbstractWidget

      public AbstractWidget(int x, int y, int width, int height, Component message)
  • Method Details

    • getHeight

      public int getHeight()
      Specified by:
      getHeight in interface LayoutElement
    • render

      public final void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
      Renders the graphical user interface (GUI) element.
      Specified by:
      render in interface Renderable
      Parameters:
      guiGraphics - the GuiGraphics object used for rendering.
      mouseX - the x-coordinate of the mouse cursor.
      mouseY - the y-coordinate of the mouse cursor.
      partialTick - the partial tick time.
    • setTooltip

      public void setTooltip(@Nullable Tooltip tooltip)
    • getTooltip

      @Nullable public Tooltip getTooltip()
    • setTooltipDelay

      public void setTooltipDelay(Duration tooltipDelay)
    • createNarrationMessage

      protected MutableComponent createNarrationMessage()
    • wrapDefaultNarrationMessage

      public static MutableComponent wrapDefaultNarrationMessage(Component message)
    • renderWidget

      protected abstract void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
    • renderScrollingString

      public static void renderScrollingString(GuiGraphics guiGraphics, Font font, Component text, int minX, int minY, int maxX, int maxY, int color)
    • renderScrollingString

      public static void renderScrollingString(GuiGraphics guiGraphics, Font font, Component text, int centerX, int minX, int minY, int maxX, int maxY, int color)
    • renderScrollingString

      protected void renderScrollingString(GuiGraphics guiGraphics, Font font, int width, int color)
    • onClick

      @Deprecated public void onClick(double mouseX, double mouseY)
    • onRelease

      public void onRelease(double mouseX, double mouseY)
    • onDrag

      protected void onDrag(double mouseX, double mouseY, double dragX, double dragY)
    • mouseClicked

      public boolean mouseClicked(double mouseX, double mouseY, int button)
      Called when a mouse button is clicked within the GUI element.

      Specified by:
      mouseClicked in interface GuiEventListener
      Parameters:
      mouseX - the X coordinate of the mouse.
      mouseY - the Y coordinate of the mouse.
      button - the button that was clicked.
      Returns:
      true if the event is consumed, false otherwise.
    • mouseReleased

      public boolean mouseReleased(double mouseX, double mouseY, int button)
      Called when a mouse button is released within the GUI element.

      Specified by:
      mouseReleased in interface GuiEventListener
      Parameters:
      mouseX - the X coordinate of the mouse.
      mouseY - the Y coordinate of the mouse.
      button - the button that was released.
      Returns:
      true if the event is consumed, false otherwise.
    • isValidClickButton

      protected boolean isValidClickButton(int button)
    • mouseDragged

      public boolean mouseDragged(double mouseX, double mouseY, int button, double dragX, double dragY)
      Called when the mouse is dragged within the GUI element.

      Specified by:
      mouseDragged in interface GuiEventListener
      Parameters:
      mouseX - the X coordinate of the mouse.
      mouseY - the Y coordinate of the mouse.
      button - the button that is being dragged.
      dragX - the X distance of the drag.
      dragY - the Y distance of the drag.
      Returns:
      true if the event is consumed, false otherwise.
    • clicked

      protected boolean clicked(double mouseX, double mouseY)
    • nextFocusPath

      @Nullable public ComponentPath nextFocusPath(FocusNavigationEvent event)
      Retrieves the next focus path based on the given focus navigation event.

      Specified by:
      nextFocusPath in interface GuiEventListener
      Parameters:
      event - the focus navigation event.
      Returns:
      the next focus path as a ComponentPath, or null if there is no next focus path.
    • isMouseOver

      public boolean isMouseOver(double mouseX, double mouseY)
      Checks if the given mouse coordinates are over the GUI element.

      Specified by:
      isMouseOver in interface GuiEventListener
      Parameters:
      mouseX - the X coordinate of the mouse.
      mouseY - the Y coordinate of the mouse.
      Returns:
      true if the mouse is over the GUI element, false otherwise.
    • playDownSound

      public void playDownSound(SoundManager handler)
    • getWidth

      public int getWidth()
      Specified by:
      getWidth in interface LayoutElement
    • setWidth

      public void setWidth(int width)
    • setHeight

      public void setHeight(int height)
    • setAlpha

      public void setAlpha(float alpha)
    • setMessage

      public void setMessage(Component message)
    • getMessage

      public Component getMessage()
    • isFocused

      public boolean isFocused()
      Specified by:
      isFocused in interface GuiEventListener
    • isHovered

      public boolean isHovered()
    • isHoveredOrFocused

      public boolean isHoveredOrFocused()
    • isActive

      public boolean isActive()
      Specified by:
      isActive in interface NarratableEntry
    • setFocused

      public void setFocused(boolean focused)
      Sets the focus state of the GUI element.
      Specified by:
      setFocused in interface GuiEventListener
      Parameters:
      focused - true to apply focus, false to remove focus
    • getFGColor

      public int getFGColor()
    • setFGColor

      public void setFGColor(int color)
    • clearFGColor

      public void clearFGColor()
    • narrationPriority

      public NarratableEntry.NarrationPriority narrationPriority()
      Specified by:
      narrationPriority in interface NarratableEntry
    • updateNarration

      public final void updateNarration(NarrationElementOutput narrationElementOutput)
      Updates the narration output with the current narration information.
      Specified by:
      updateNarration in interface NarrationSupplier
      Parameters:
      narrationElementOutput - the output to update with narration information.
    • updateWidgetNarration

      protected abstract void updateWidgetNarration(NarrationElementOutput narrationElementOutput)
    • defaultButtonNarrationText

      protected void defaultButtonNarrationText(NarrationElementOutput narrationElementOutput)
    • getX

      public int getX()
      Specified by:
      getX in interface LayoutElement
    • setX

      public void setX(int x)
      Specified by:
      setX in interface LayoutElement
    • getY

      public int getY()
      Specified by:
      getY in interface LayoutElement
    • setY

      public void setY(int y)
      Specified by:
      setY in interface LayoutElement
    • getRight

      public int getRight()
    • getBottom

      public int getBottom()
    • visitWidgets

      public void visitWidgets(Consumer<AbstractWidget> consumer)
      Specified by:
      visitWidgets in interface LayoutElement
    • setSize

      public void setSize(int width, int height)
    • getRectangle

      public ScreenRectangle getRectangle()
      Specified by:
      getRectangle in interface GuiEventListener
      Specified by:
      getRectangle in interface LayoutElement
    • setRectangle

      public void setRectangle(int width, int height, int x, int y)
    • getTabOrderGroup

      public int getTabOrderGroup()
      Specified by:
      getTabOrderGroup in interface TabOrderedElement
    • setTabOrderGroup

      public void setTabOrderGroup(int tabOrderGroup)