Option<T> class
Overview
The Option<T>
class is an abstract representation of an option within a context menu. It is designed to be extended for various types of options that can be interacted with in the Minecraft client GUI.
Constructor
Option(Supplier<T> getter, Consumer<T> setter)
Creates an Option
instance with specified getter and setter for managing the option’s value.
Option(Supplier<T> getter, Consumer<T> setter, Supplier<Boolean> shouldRender)
Initializes an Option
with specified getter, setter, and a condition for rendering.
Core Methods
get()
Retrieves the current value of the option.
set(T value)
Sets the current value of the option and applies it using the provided setter.
render(DrawContext drawContext, int x, int y)
Defines how the option is rendered on the screen at the given coordinates.
isMouseOver(double mouseX, double mouseY)
Determines if the mouse cursor is over the option’s area.
setShouldRender(Supplier<Boolean> shouldRender)
Sets the condition that determines if the option should be rendered.
Usage
To use the Option<T>
class, extend it and implement the abstract render
method to define the option’s appearance and behavior. Use the setShouldRender
method to specify conditions under which the option should be displayed.
This is an example usage of all options from TextWidget:
Last updated
Was this helpful?