Class ForgeSlider
java.lang.Object
net.minecraft.client.gui.GuiComponent
net.minecraft.client.gui.components.AbstractWidget
net.minecraft.client.gui.components.AbstractSliderButton
net.minecraftforge.client.gui.widget.ForgeSlider
- All Implemented Interfaces:
GuiEventListener
,Renderable
,NarratableEntry
,NarrationSupplier
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
Modifier and TypeFieldDescriptionprotected boolean
private final DecimalFormat
protected double
protected double
protected Component
protected double
Allows input of discontinuous values with a certain stepprotected Component
Fields inherited from class net.minecraft.client.gui.components.AbstractSliderButton
value
Fields inherited from class net.minecraft.client.gui.components.AbstractWidget
active, alpha, height, isHovered, packedFGColor, UNSET_FG_COLOR, visible, WIDGETS_LOCATION, width
Fields inherited from class net.minecraft.client.gui.GuiComponent
BACKGROUND_LOCATION, GUI_ICONS_LOCATION, STATS_ICON_LOCATION
Fields inherited from interface net.minecraft.client.gui.components.events.GuiEventListener
DOUBLE_CLICK_THRESHOLD_MS
-
Constructor Summary
ConstructorDescriptionForgeSlider
(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, boolean drawString) Overload withstepSize
set to 1, useful for sliders with whole number values.ForgeSlider
(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 void
double
getValue()
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) 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 ofstepSize
.protected void
Methods inherited from class net.minecraft.client.gui.components.AbstractSliderButton
createNarrationMessage, getYImage, onRelease, playDownSound, renderBg, updateWidgetNarration
Methods inherited from class net.minecraft.client.gui.components.AbstractWidget
changeFocus, clearFGColor, clicked, createTooltipPositioner, defaultButtonNarrationText, getFGColor, getHeight, getMessage, getWidth, getX, getY, isActive, isFocused, isHoveredOrFocused, isMouseOver, isValidClickButton, mouseClicked, mouseDragged, mouseReleased, narrationPriority, onFocusedChanged, render, renderButton, setAlpha, setFGColor, setFocused, setHeight, setMessage, setPosition, setTooltip, setTooltipDelay, setWidth, setX, setY, updateNarration, wrapDefaultNarrationMessage
Methods inherited from class net.minecraft.client.gui.GuiComponent
blit, blit, blit, blit, blit, blitOutlineBlack, disableScissor, drawCenteredString, drawCenteredString, drawCenteredString, drawString, drawString, drawString, enableScissor, fill, fillGradient, fillGradient, fillGradient, getBlitOffset, hLine, setBlitOffset, vLine
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, keyReleased, mouseMoved, mouseScrolled
-
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
-
ForgeSlider
public ForgeSlider(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
-Component
displayed before the value stringsuffix
-Component
displayed 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 whenstepSize
is 0. Limited to a maximum of 4 (inclusive).drawString
- Should text be displayed on the widget
-
ForgeSlider
public ForgeSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue, double maxValue, double currentValue, boolean drawString) Overload withstepSize
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
-
onClick
public void onClick(double mouseX, double mouseY) - Overrides:
onClick
in classAbstractSliderButton
-
onDrag
protected void onDrag(double mouseX, double mouseY, double dragX, double dragY) - Overrides:
onDrag
in classAbstractSliderButton
-
keyPressed
public boolean keyPressed(int keyCode, int scanCode, int modifiers) - Specified by:
keyPressed
in interfaceGuiEventListener
- Overrides:
keyPressed
in classAbstractSliderButton
-
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 ofstepSize
. IfstepSize
is 0, no snapping occurs. -
updateMessage
protected void updateMessage()- Specified by:
updateMessage
in classAbstractSliderButton
-
applyValue
protected void applyValue()- Specified by:
applyValue
in classAbstractSliderButton
-