Class ExtendedSlider

java.lang.Object
net.minecraft.client.gui.components.AbstractWidget
net.minecraft.client.gui.components.AbstractSliderButton
net.neoforged.neoforge.client.gui.widget.ExtendedSlider
All Implemented Interfaces:
net.minecraft.client.gui.components.events.GuiEventListener, net.minecraft.client.gui.components.Renderable, net.minecraft.client.gui.components.TabOrderedElement, net.minecraft.client.gui.layouts.LayoutElement, net.minecraft.client.gui.narration.NarratableEntry, net.minecraft.client.gui.narration.NarrationSupplier, IAbstractWidgetExtension

public class ExtendedSlider extends net.minecraft.client.gui.components.AbstractSliderButton
Slider widget implementation which allows inputting values in a certain range with optional step size.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.client.gui.narration.NarratableEntry

    net.minecraft.client.gui.narration.NarratableEntry.NarrationPriority
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
     
    private final DecimalFormat
     
    protected double
     
    protected double
     
    protected net.minecraft.network.chat.Component
     
    protected double
    Allows input of discontinuous values with a certain step
    protected net.minecraft.network.chat.Component
     

    Fields inherited from class net.minecraft.client.gui.components.AbstractSliderButton

    TEXT_MARGIN, value

    Fields inherited from class net.minecraft.client.gui.components.AbstractWidget

    active, alpha, height, isHovered, packedFGColor, UNSET_FG_COLOR, visible, width

    Fields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener

    DOUBLE_CLICK_THRESHOLD_MS
  • Constructor Summary

    Constructors
    Constructor
    Description
    ExtendedSlider(int x, int y, int width, int height, net.minecraft.network.chat.Component prefix, net.minecraft.network.chat.Component suffix, double minValue, double maxValue, double currentValue, boolean drawString)
    Overload with stepSize set to 1, useful for sliders with whole number values.
    ExtendedSlider(int x, int y, int width, int height, net.minecraft.network.chat.Component prefix, net.minecraft.network.chat.Component suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
     
    double
     
    int
     
    long
     
     
    boolean
    keyPressed(int keyCode, int scanCode, int modifiers)
     
    void
    onClick(double mouseX, double mouseY)
     
    protected void
    onDrag(double mouseX, double mouseY, double dragX, double dragY)
     
    void
    renderWidget(net.minecraft.client.gui.GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
     
    private void
    setSliderValue(double value)
     
    void
    setValue(double value)
     
    private void
    setValueFromMouse(double mouseX)
     
    private double
    snapToNearest(double value)
    Snaps the value, so that the displayed value is the nearest multiple of stepSize.
    protected void
     

    Methods inherited from class net.minecraft.client.gui.components.AbstractSliderButton

    createNarrationMessage, getHandleSprite, getSprite, onRelease, playDownSound, setFocused, updateWidgetNarration

    Methods inherited from class net.minecraft.client.gui.components.AbstractWidget

    clearFGColor, defaultButtonNarrationText, getBottom, getFGColor, getHeight, getMessage, getRectangle, getRight, getTabOrderGroup, getTooltip, getWidth, getX, getY, isActive, isFocused, isHovered, isHoveredOrFocused, isMouseOver, isValidClickButton, mouseClicked, mouseDragged, mouseReleased, narrationPriority, nextFocusPath, playButtonClickSound, render, renderScrollingString, renderScrollingString, renderScrollingString, setAlpha, setFGColor, setHeight, setMessage, setRectangle, setSize, setTabOrderGroup, setTooltip, setTooltipDelay, setWidth, setX, setY, updateNarration, visitWidgets, wrapDefaultNarrationMessage

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener

    charTyped, getBorderForArrowNavigation, getCurrentFocusPath, keyReleased, mouseMoved, mouseScrolled

    Methods inherited from interface net.neoforged.neoforge.client.extensions.IAbstractWidgetExtension

    onClick

    Methods inherited from interface net.minecraft.client.gui.layouts.LayoutElement

    setPosition

    Methods inherited from interface net.minecraft.client.gui.narration.NarratableEntry

    getNarratables
  • Field Details

    • prefix

      protected net.minecraft.network.chat.Component prefix
    • suffix

      protected net.minecraft.network.chat.Component suffix
    • minValue

      protected double minValue
    • maxValue

      protected double maxValue
    • stepSize

      protected double stepSize
      Allows input of discontinuous values with a certain step
    • drawString

      protected boolean drawString
    • format

      private final DecimalFormat format
  • Constructor Details

    • ExtendedSlider

      public ExtendedSlider(int x, int y, int width, int height, net.minecraft.network.chat.Component prefix, net.minecraft.network.chat.Component suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString)
      Parameters:
      x - x position of upper left corner
      y - y position of upper left corner
      width - Width of the widget
      height - Height of the widget
      prefix - Component displayed before the value string
      suffix - Component displayed after the value string
      minValue - Minimum (left) value of slider
      maxValue - Maximum (right) value of slider
      currentValue - Starting value when widget is first displayed
      stepSize - Size of step used. Precision will automatically be calculated based on this value if this value is not 0.
      precision - Only used when stepSize is 0. Limited to a maximum of 4 (inclusive).
      drawString - Should text be displayed on the widget
    • ExtendedSlider

      public ExtendedSlider(int x, int y, int width, int height, net.minecraft.network.chat.Component prefix, net.minecraft.network.chat.Component suffix, double minValue, double maxValue, double currentValue, boolean drawString)
      Overload with stepSize set to 1, useful for sliders with whole number values.
  • Method Details

    • getValue

      public double getValue()
      Returns:
      Current slider value as a double
    • getValueLong

      public long getValueLong()
      Returns:
      Current slider value as an long
    • getValueInt

      public int getValueInt()
      Returns:
      Current slider value as an int
    • setValue

      public void setValue(double value)
      Parameters:
      value - The new slider value
    • getValueString

      public String getValueString()
    • onClick

      public void onClick(double mouseX, double mouseY)
      Overrides:
      onClick in class net.minecraft.client.gui.components.AbstractSliderButton
    • onDrag

      protected void onDrag(double mouseX, double mouseY, double dragX, double dragY)
      Overrides:
      onDrag in class net.minecraft.client.gui.components.AbstractSliderButton
    • keyPressed

      public boolean keyPressed(int keyCode, int scanCode, int modifiers)
      Specified by:
      keyPressed in interface net.minecraft.client.gui.components.events.GuiEventListener
      Overrides:
      keyPressed in class net.minecraft.client.gui.components.AbstractSliderButton
    • setValueFromMouse

      private void setValueFromMouse(double mouseX)
    • setSliderValue

      private void setSliderValue(double value)
      Parameters:
      value - Percentage of slider range
    • snapToNearest

      private double snapToNearest(double value)
      Snaps the value, so that the displayed value is the nearest multiple of stepSize. If stepSize is 0, no snapping occurs.
    • updateMessage

      protected void updateMessage()
      Specified by:
      updateMessage in class net.minecraft.client.gui.components.AbstractSliderButton
    • applyValue

      protected void applyValue()
      Specified by:
      applyValue in class net.minecraft.client.gui.components.AbstractSliderButton
    • renderWidget

      public void renderWidget(net.minecraft.client.gui.GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick)
      Overrides:
      renderWidget in class net.minecraft.client.gui.components.AbstractSliderButton