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:
GuiEventListener,Renderable,TabOrderedElement,LayoutElement,NarratableEntry,NarrationSupplier,IAbstractWidgetExtension
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
NarratableEntry.NarrationPriority -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanprivate final DecimalFormatprotected doubleprotected doubleprotected Componentprotected doubleAllows input of discontinuous values with a certain stepprotected ComponentFields inherited from class net.minecraft.client.gui.components.AbstractSliderButton
TEXT_MARGIN, valueFields inherited from class net.minecraft.client.gui.components.AbstractWidget
active, alpha, height, isHovered, packedFGColor, UNSET_FG_COLOR, visible, widthFields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
DOUBLE_CLICK_THRESHOLD_MS -
Constructor Summary
ConstructorsConstructorDescriptionExtendedSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, boolean drawString) Overload withstepSizeset to 1, useful for sliders with whole number values.ExtendedSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoublegetValue()intlongbooleankeyPressed(int keyCode, int scanCode, int modifiers) Called when a keyboard key is pressed within the GUI element.voidonClick(double mouseX, double mouseY) protected voidonDrag(double mouseX, double mouseY, double dragX, double dragY) voidrenderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) private voidsetFractionalValue(double fractionalValue) voidsetValue(double value) private voidsetValueFromMouse(double mouseX) private doublesnapToNearest(double value) Snaps the value, so that the displayed value is the nearest multiple ofstepSize.protected voidMethods inherited from class net.minecraft.client.gui.components.AbstractSliderButton
createNarrationMessage, getHandleSprite, getSprite, onRelease, playDownSound, setFocused, updateWidgetNarrationMethods 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, wrapDefaultNarrationMessageMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
charTyped, getBorderForArrowNavigation, getCurrentFocusPath, keyReleased, mouseMoved, mouseScrolledMethods inherited from interface net.neoforged.neoforge.client.extensions.IAbstractWidgetExtension
onClickMethods inherited from interface net.minecraft.client.gui.layouts.LayoutElement
setPositionMethods inherited from interface net.minecraft.client.gui.narration.NarratableEntry
getNarratables
-
Field Details
-
prefix
-
suffix
-
minValue
protected double minValue -
maxValue
protected double maxValue -
stepSize
protected double stepSizeAllows input of discontinuous values with a certain step -
drawString
protected boolean drawString -
format
-
-
Constructor Details
-
ExtendedSlider
public ExtendedSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, double stepSize, int precision, boolean drawString) - Parameters:
x- x position of upper left cornery- y position of upper left cornerwidth- Width of the widgetheight- Height of the widgetprefix-Componentdisplayed before the value stringsuffix-Componentdisplayed after the value stringminValue- Minimum (left) value of slidermaxValue- Maximum (right) value of slidercurrentValue- Starting value when widget is first displayedstepSize- Size of step used. Precision will automatically be calculated based on this value if this value is not 0.precision- Only used whenstepSizeis 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, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, boolean drawString) Overload withstepSizeset 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
-
onClick
public void onClick(double mouseX, double mouseY) - Overrides:
onClickin classAbstractSliderButton
-
onDrag
protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) - Overrides:
onDragin classAbstractSliderButton
-
keyPressed
public boolean keyPressed(int keyCode, int scanCode, int modifiers) Description copied from interface:GuiEventListenerCalled when a keyboard key is pressed within the GUI element.- Specified by:
keyPressedin interfaceGuiEventListener- Overrides:
keyPressedin classAbstractSliderButton- Parameters:
keyCode- the key code of the pressed key.scanCode- the scan code of the pressed key.modifiers- the keyboard modifiers.- Returns:
trueif the event is consumed,falseotherwise.
-
setValueFromMouse
private void setValueFromMouse(double mouseX) -
setFractionalValue
private void setFractionalValue(double fractionalValue) - Parameters:
fractionalValue- fractional progress between 0 and 1
-
snapToNearest
private double snapToNearest(double value) Snaps the value, so that the displayed value is the nearest multiple ofstepSize. IfstepSizeis 0, no snapping occurs.- Parameters:
value- fractional progress between 0 and 1- Returns:
- fractional progress between 0 and 1, snapped to the nearest allowed value
-
updateMessage
protected void updateMessage()- Specified by:
updateMessagein classAbstractSliderButton
-
applyValue
protected void applyValue()- Specified by:
applyValuein classAbstractSliderButton
-
renderWidget
- Overrides:
renderWidgetin classAbstractSliderButton
-