Class WBar
java.lang.Object
io.github.cottonmc.cotton.gui.widget.WWidget
io.github.cottonmc.cotton.gui.widget.WBar
A bar that displays int values from a
ContainerData.
Bars can be used for all kinds of bars including progress bars (and progress arrows) and energy bars.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe direction of aWBar, representing where the bar will grown when its field increases. -
Field Summary
FieldsModifier and TypeFieldDescriptionThe bar texture.The background texture.protected final WBar.DirectionThe direction of this bar, representing where the bar will grow when the field increases.protected final intThe ID of the displayed property in theproperties.protected final intThe ID of the property representing the maximum value of thefield.protected intThe constant maximum value of thefield.protected @Nullable net.minecraft.world.inventory.ContainerDataThe properties used for painting this bar.The translation key of the tooltip.protected @Nullable net.minecraft.network.chat.ComponentA tooltip text component. -
Constructor Summary
ConstructorsConstructorDescriptionWBar(net.minecraft.resources.Identifier bg, net.minecraft.resources.Identifier bar, int field, int maxField) WBar(net.minecraft.resources.Identifier bg, net.minecraft.resources.Identifier bar, int field, int maxField, WBar.Direction dir) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTooltip(TooltipBuilder information) Adds lines to this widget's tooltip.booleanChecks whether this widget can be resized usingWWidget.setSize(int, int).@Nullable net.minecraft.world.inventory.ContainerDataGets the current properties of this bar.voidpaint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Paints this widget.setProperties(@Nullable net.minecraft.world.inventory.ContainerData properties) Sets the current properties of this bar.voidvalidate(GuiDescription host) Creates component peers and initializes animation data for this Widget and all its children.static WBarwithConstantMaximum(Texture bg, Texture bar, int field, int maxValue, WBar.Direction dir) Creates a WBar that has a constant maximum-value instead of getting the maximum from a field.static WBarwithConstantMaximum(net.minecraft.resources.Identifier bg, net.minecraft.resources.Identifier bar, int field, int maxValue, WBar.Direction dir) Creates a WBar that has a constant maximum-value instead of getting the maximum from a field.withTooltip(String label) Adds a tooltip to the WBar.withTooltip(net.minecraft.network.chat.Component label) Adds a tooltipComponentto the WBar.Methods inherited from class WWidget
addNarrations, addPainters, canFocus, canFocusForTextInput, canHover, getAbsoluteX, getAbsoluteY, getFocusModel, getHeight, getHost, getParent, getWidth, getX, getY, hit, hoveredProperty, isActivationKey, isFocused, isHovered, isNarratable, isWithinBounds, onCharTyped, onClick, onFocusGained, onFocusLost, onHidden, onKeyPressed, onKeyReleased, onMouseDown, onMouseDrag, onMouseMove, onMouseScroll, onMouseUp, onPreeditUpdated, onShown, releaseFocus, renderTooltip, requestFocus, setHost, setHovered, setLocation, setParent, setSize, shouldRenderInDarkMode, tick
-
Field Details
-
bg
-
bar
-
field
protected final int fieldThe ID of the displayed property in theproperties. -
max
-
maxValue
-
properties
-
direction
The direction of this bar, representing where the bar will grow when the field increases. -
tooltipLabel
-
tooltipTextComponent
A tooltip text component. This can be used instead oftooltipLabel, or together with it. In that case, this component will be drawn after the other label.
-
-
Constructor Details
-
WBar
-
WBar
public WBar(@Nullable Texture bg, @Nullable Texture bar, int field, int maxField, WBar.Direction dir) -
WBar
public WBar(net.minecraft.resources.Identifier bg, net.minecraft.resources.Identifier bar, int field, int maxField) -
WBar
public WBar(net.minecraft.resources.Identifier bg, net.minecraft.resources.Identifier bar, int field, int maxField, WBar.Direction dir)
-
-
Method Details
-
withTooltip
Adds a tooltip to the WBar.Formatting Guide: The tooltip label is passed into
String.formatand can receive two integers (%d) - the first is the current value of the bar's focused field, and the second is the bar's focused maximum.- Parameters:
label- the translation key of the string to render on the tooltip- Returns:
- this bar with tooltip enabled and set
-
withTooltip
Adds a tooltipComponentto the WBar.- Parameters:
label- the added tooltip label- Returns:
- this bar
-
canResize
public boolean canResize()Description copied from class:WWidgetChecks whether this widget can be resized usingWWidget.setSize(int, int). -
paint
@Environment(CLIENT) public void paint(net.minecraft.client.gui.GuiGraphicsExtractor context, int x, int y, int mouseX, int mouseY) Description copied from class:WWidgetPaints this widget. -
addTooltip
Description copied from class:WWidgetAdds lines to this widget's tooltip. If the lines remain empty after this call, no tooltip will be drawn.- Overrides:
addTooltipin classWWidget- Parameters:
information- the builder to add tooltip lines to
-
validate
Description copied from class:WWidgetCreates component peers and initializes animation data for this Widget and all its children. The host screen handler must clear any heavyweight peers from its records before this method is called.This method must be called on the root panel of any screen once the widgets have been initialized.
-
getProperties
Gets the current properties of this bar.- Returns:
- the current property delegate, or null if not initialized yet
-
setProperties
Sets the current properties of this bar.This method is meant for situations when a GUI description is unavailable (such as HUDs).
GuiDescription.getPropertyDelegate()should be preferred over this if available.- Parameters:
properties- the properties- Returns:
- this bar
-
withConstantMaximum
public static WBar withConstantMaximum(net.minecraft.resources.Identifier bg, net.minecraft.resources.Identifier bar, int field, int maxValue, WBar.Direction dir) Creates a WBar that has a constant maximum-value instead of getting the maximum from a field.- Parameters:
bg- the background image to use for the barbar- the foreground image that represents the filled barfield- the field index for bar valuesmaxValue- the constant maximum value for the bardir- the direction the bar should grow towards- Returns:
- a new WBar with a constant maximum value
-
withConstantMaximum
public static WBar withConstantMaximum(Texture bg, Texture bar, int field, int maxValue, WBar.Direction dir) Creates a WBar that has a constant maximum-value instead of getting the maximum from a field.- Parameters:
bg- the background image to use for the barbar- the foreground image that represents the filled barfield- the field index for bar valuesmaxValue- the constant maximum value for the bardir- the direction the bar should grow towards- Returns:
- a new WBar with a constant maximum value
- Since:
- 4.1.0
-