Class AbstractButtonWidget

java.lang.Object
net.minecraft.client.gui.DrawableHelper
net.minecraft.client.gui.widget.AbstractButtonWidget
All Implemented Interfaces:
Drawable, Element
Direct Known Subclasses:
AbstractPressableButtonWidget, AnimatedResultButton, GameModeSelectionScreen.ButtonWidget, RecipeAlternativesWidget.AlternativeButtonWidget, SliderWidget, TextFieldWidget, ToggleButtonWidget

@Environment(CLIENT)
public abstract class AbstractButtonWidget
extends DrawableHelper
implements Drawable, Element
  • Field Details

    • WIDGETS_LOCATION

      public static final Identifier WIDGETS_LOCATION
    • width

      protected int width
    • height

      protected int height
    • x

      public int x
    • y

      public int y
    • message

      private Text message
    • wasHovered

      private boolean wasHovered
    • hovered

      protected boolean hovered
    • active

      public boolean active
    • visible

      public boolean visible
    • alpha

      protected float alpha
    • nextNarration

      protected long nextNarration
    • focused

      private boolean focused
  • Constructor Details

    • AbstractButtonWidget

      public AbstractButtonWidget​(int x, int y, int width, int height, Text message)
  • Method Details

    • getHeight

      public int getHeight()
    • getYImage

      protected int getYImage​(boolean hovered)
    • render

      public void render​(MatrixStack matrices, int mouseX, int mouseY, float delta)
      Specified by:
      render in interface Drawable
    • narrate

      protected void narrate()
    • getNarrationMessage

      protected MutableText getNarrationMessage()
    • renderButton

      public void renderButton​(MatrixStack matrices, int mouseX, int mouseY, float delta)
    • renderBg

      protected void renderBg​(MatrixStack matrices, MinecraftClient client, int mouseX, int mouseY)
    • onClick

      public void onClick​(double mouseX, double mouseY)
    • onRelease

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

      protected void onDrag​(double mouseX, double mouseY, double deltaX, double deltaY)
    • mouseClicked

      public boolean mouseClicked​(double mouseX, double mouseY, int button)
      Callback for when a mouse button down event has been captured. The button number is identified by the constants in GLFW class.
      Specified by:
      mouseClicked in interface Element
      Parameters:
      mouseX - the X coordinate of the mouse
      mouseY - the Y coordinate of the mouse
      button - the mouse button number
      Returns:
      true to indicate that the event handling is successful/valid
      See Also:
      Mouse.onMouseButton(long, int, int, int), GLFW.GLFW_MOUSE_BUTTON_1
    • mouseReleased

      public boolean mouseReleased​(double mouseX, double mouseY, int button)
      Callback for when a mouse button release event has been captured. The button number is identified by the constants in GLFW class.
      Specified by:
      mouseReleased in interface Element
      Parameters:
      mouseX - the X coordinate of the mouse
      mouseY - the Y coordinate of the mouse
      button - the mouse button number
      Returns:
      true to indicate that the event handling is successful/valid
      See Also:
      Mouse.onMouseButton(long, int, int, int), GLFW.GLFW_MOUSE_BUTTON_1
    • isValidClickButton

      protected boolean isValidClickButton​(int button)
    • mouseDragged

      public boolean mouseDragged​(double mouseX, double mouseY, int button, double deltaX, double deltaY)
      Callback for when a mouse button drag event has been captured. The button number is identified by the constants in GLFW class.
      Specified by:
      mouseDragged in interface Element
      Parameters:
      mouseX - the current X coordinate of the mouse
      mouseY - the current Y coordinate of the mouse
      button - the mouse button number
      deltaX - the difference of the current X with the previous X coordinate
      deltaY - the difference of the current Y with the previous Y coordinate
      Returns:
      true to indicate that the event handling is successful/valid
      See Also:
      Mouse.onCursorPos(long, double, double), GLFW.GLFW_MOUSE_BUTTON_1
    • clicked

      protected boolean clicked​(double mouseX, double mouseY)
    • isHovered

      public boolean isHovered()
    • changeFocus

      public boolean changeFocus​(boolean lookForwards)
      Changes the focusing element by cycling to the next/previous element. This action is done typically when the user has pressed the 'Tab' or 'Ctrl+Tab' key.
      Specified by:
      changeFocus in interface Element
      Parameters:
      lookForwards - true to cycle forwards, otherwise cycle backwards
      Returns:
      true to indicate that the event handling is successful/valid
    • onFocusedChanged

      protected void onFocusedChanged​(boolean bool)
    • isMouseOver

      public boolean isMouseOver​(double mouseX, double mouseY)
      Checks if the mouse position is within the bound of the element.
      Specified by:
      isMouseOver in interface Element
      Parameters:
      mouseX - the X coordinate of the mouse
      mouseY - the Y coordinate of the mouse
      Returns:
      true if the mouse is within the bound of the element, otherwise false
    • renderToolTip

      public void renderToolTip​(MatrixStack matrices, int mouseX, int mouseY)
    • playDownSound

      public void playDownSound​(SoundManager soundManager)
    • getWidth

      public int getWidth()
    • setWidth

      public void setWidth​(int value)
    • setAlpha

      public void setAlpha​(float value)
    • setMessage

      public void setMessage​(Text text)
    • queueNarration

      public void queueNarration​(int delay)
    • getMessage

      public Text getMessage()
    • isFocused

      public boolean isFocused()
    • setFocused

      protected void setFocused​(boolean focused)