Class SimpleOption<T>
Option values
This class allows querying and storing of the option value via getValue()
and setValue(Object) respectively. Option values are automatically validated,
and if the value is invalid, the value resets back to the default. Some validators will
coerce the invalid value (e.g. by clamping) into a valid one instead of failing; in this
case the new value is used.
Option values are serialized using codecs. Check DataFixerUpper code for the list of
available codecs. For serialization of enums, you can check the code in GameOptions.
If the value has changed, the changeCallback passed to the constructor will
trigger with the new value.
Callbacks
This class itself cannot be extended by default; instead, the behavior of the option,
such as validation or rendering of the ClickableWidget associated with the
option, is customized by passing a SimpleOption.Callbacks instance. There are
several existing callbacks that should cover most of the needs:
SimpleOption.PotentialValuesBasedCallbacks: The most simple cycling option. Useful for enums.SimpleOption.AlternateValuesSupportingCyclingCallbacks: An option with alternate potential values that are used only when certain conditions are met. This is used in vanilla to hide "Fabulous!" graphics option after the user cancelled the warning.SimpleOption.LazyCyclingCallbacks: An option whose potential values are determined lazily.SimpleOption.MaxSuppliableIntCallbacks: A cycling option with an integer value that has a fixed minimum value and a dynamic maximum value. Values outside the range are clamped. This is used in vanilla to implement the GUI Scale option.SimpleOption.DoubleSliderCallbacks: A slider option of adoublebetween0.0and1.0. Values outside this range are considered invalid.SimpleOption.ValidatingIntSliderCallbacks: A slider option of anintwith a minimum and maximum values. Values outside this range are considered invalid.
See also several ofBoolean methods for options using boolean values.
Modifiers
Slider option callbacks allow "modifiers" to be applied. The "slider progress value"
is the value used to calculate the slider's progress and must be linear. The real value,
simply called "value" in withModifier methods, is the value used in
getValue() and passed to textGetter.
Text
Options themselves have names; the translation key of the option needs to be passed when constructing this class. This corresponds totext. Options also have the
rendered text, composed of the option name and the value; the code obtains the value using
the valueTextGetter in the constructor. The getter takes the option's name and the
current value, and returns the text. Several static methods in GameOptions can
be used to format the name and the value. For options backed by an enum that implements
TranslatableOption, enumValueText() can be passed to valueTextGetter
to obtain the rendered text from the enum.
Options can also have a tooltip, specified by passing tooltipFactoryGetter. If the
option has no tooltips, you can pass emptyTooltip(), and if the option always
uses one tooltip, you can pass constantTooltip(Text).- Mappings:
Namespace Name named net/minecraft/client/option/SimpleOptionintermediary net/minecraft/class_7172official fgr
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA set of callbacks for a cycling option with alternate potential values that are used only when certain conditions are met.(package private) static interfaceA set of callbacks to customize an option's behavior.(package private) static interfacestatic enumA set of callbacks for a slider of values from0.0to1.0(both inclusive).(package private) static interfacestatic final recordA set of callbacks for a cycling option whose potential values are determined lazily.static final recordA set of callbacks for a cycling option with a fixed minimum value and a dynamic maximum value.static final classstatic final recordA set of callbacks for a cycling option.(package private) static interfaceA set of callbacks for slider options.static interface(package private) static interfacestatic final recordA set of callbacks for a slider of integer values with a fixed minimum and maximum values.static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SimpleOption.PotentialValuesBasedCallbacks<Boolean> A set of callbacks for boolean options.static final SimpleOption.ValueTextGetter<Boolean> private final SimpleOption.Callbacks<T> private final com.mojang.serialization.Codec<T> private final Tprivate static final Logger(package private) final Textprivate final SimpleOption.TooltipFactory<T> (package private) T -
Constructor Summary
ConstructorsConstructorDescriptionSimpleOption(String key, SimpleOption.TooltipFactory<T> tooltipFactory, SimpleOption.ValueTextGetter<T> valueTextGetter, SimpleOption.Callbacks<T> callbacks, com.mojang.serialization.Codec<T> codec, T defaultValue, Consumer<T> changeCallback) SimpleOption(String key, SimpleOption.TooltipFactory<T> tooltipFactory, SimpleOption.ValueTextGetter<T> valueTextGetter, SimpleOption.Callbacks<T> callbacks, T defaultValue, Consumer<T> changeCallback) -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> SimpleOption.TooltipFactory<T> constantTooltip(Text text) Returns the getter for thetooltipFactoryGetterparameter of the constructor to indicate constant tooltips.createWidget(GameOptions options) createWidget(GameOptions options, int x, int y, int width) createWidget(GameOptions options, int x, int y, int width, Consumer<T> changeCallback) static <T> SimpleOption.TooltipFactory<T> Returns the getter for thetooltipFactoryGetterparameter of the constructor to indicate empty tooltips.static <T extends TranslatableOption>
SimpleOption.ValueTextGetter<T> Returns the getter for thevalueTextGetterparameter of the constructor to use the value's text as the option's rendered text.com.mojang.serialization.Codec<T> getCodec()getValue()Returns the option's current value.static SimpleOption<Boolean> Creates a boolean option.static SimpleOption<Boolean> Creates a boolean option.static SimpleOption<Boolean> ofBoolean(String key, SimpleOption.TooltipFactory<Boolean> tooltipFactory, boolean defaultValue) Creates a boolean option.static SimpleOption<Boolean> ofBoolean(String key, SimpleOption.TooltipFactory<Boolean> tooltipFactory, boolean defaultValue, Consumer<Boolean> changeCallback) Creates a boolean option.static SimpleOption<Boolean> ofBoolean(String key, SimpleOption.TooltipFactory<Boolean> tooltipFactory, SimpleOption.ValueTextGetter<Boolean> valueTextGetter, boolean defaultValue, Consumer<Boolean> changeCallback) voidSets the option's value.toString()
-
Field Details
-
LOGGER
- Mappings:
Namespace Name Mixin selector named LOGGERLnet/minecraft/client/option/SimpleOption;LOGGER:Lorg/slf4j/Logger;intermediary field_37862Lnet/minecraft/class_7172;field_37862:Lorg/slf4j/Logger;official cLfgr;c:Lorg/slf4j/Logger;
-
BOOLEAN
A set of callbacks for boolean options.- API Note:
- See also several
ofBooleanmethods in this class which provide easier ways of creating a boolean option. - Mappings:
Namespace Name Mixin selector named BOOLEANLnet/minecraft/client/option/SimpleOption;BOOLEAN:Lnet/minecraft/client/option/SimpleOption$PotentialValuesBasedCallbacks;intermediary field_38278Lnet/minecraft/class_7172;field_38278:Lnet/minecraft/class_7172$class_7173;official aLfgr;a:Lfgr$e;
-
BOOLEAN_TEXT_GETTER
- Mappings:
Namespace Name Mixin selector named BOOLEAN_TEXT_GETTERLnet/minecraft/client/option/SimpleOption;BOOLEAN_TEXT_GETTER:Lnet/minecraft/client/option/SimpleOption$ValueTextGetter;intermediary field_41333Lnet/minecraft/class_7172;field_41333:Lnet/minecraft/class_7172$class_7303;official bLfgr;b:Lfgr$b;
-
tooltipFactory
- Mappings:
Namespace Name Mixin selector named tooltipFactoryLnet/minecraft/client/option/SimpleOption;tooltipFactory:Lnet/minecraft/client/option/SimpleOption$TooltipFactory;intermediary field_37863Lnet/minecraft/class_7172;field_37863:Lnet/minecraft/class_7172$class_7277;official dLfgr;d:Lfgr$l;
-
textGetter
- Mappings:
Namespace Name Mixin selector named textGetterLnet/minecraft/client/option/SimpleOption;textGetter:Ljava/util/function/Function;intermediary field_37864Lnet/minecraft/class_7172;field_37864:Ljava/util/function/Function;official eLfgr;e:Ljava/util/function/Function;
-
callbacks
- Mappings:
Namespace Name Mixin selector named callbacksLnet/minecraft/client/option/SimpleOption;callbacks:Lnet/minecraft/client/option/SimpleOption$Callbacks;intermediary field_37865Lnet/minecraft/class_7172;field_37865:Lnet/minecraft/class_7172$class_7178;official fLfgr;f:Lfgr$n;
-
codec
- Mappings:
Namespace Name Mixin selector named codecLnet/minecraft/client/option/SimpleOption;codec:Lcom/mojang/serialization/Codec;intermediary field_38279Lnet/minecraft/class_7172;field_38279:Lcom/mojang/serialization/Codec;official gLfgr;g:Lcom/mojang/serialization/Codec;
-
defaultValue
- Mappings:
Namespace Name Mixin selector named defaultValueLnet/minecraft/client/option/SimpleOption;defaultValue:Ljava/lang/Object;intermediary field_37866Lnet/minecraft/class_7172;field_37866:Ljava/lang/Object;official hLfgr;h:Ljava/lang/Object;
-
changeCallback
- Mappings:
Namespace Name Mixin selector named changeCallbackLnet/minecraft/client/option/SimpleOption;changeCallback:Ljava/util/function/Consumer;intermediary field_37867Lnet/minecraft/class_7172;field_37867:Ljava/util/function/Consumer;official iLfgr;i:Ljava/util/function/Consumer;
-
text
- Mappings:
Namespace Name Mixin selector named textLnet/minecraft/client/option/SimpleOption;text:Lnet/minecraft/text/Text;intermediary field_38280Lnet/minecraft/class_7172;field_38280:Lnet/minecraft/class_2561;official jLfgr;j:Lwz;
-
value
T value- Mappings:
Namespace Name Mixin selector named valueLnet/minecraft/client/option/SimpleOption;value:Ljava/lang/Object;intermediary field_37868Lnet/minecraft/class_7172;field_37868:Ljava/lang/Object;official kLfgr;k:Ljava/lang/Object;
-
-
Constructor Details
-
SimpleOption
public SimpleOption(String key, SimpleOption.TooltipFactory<T> tooltipFactory, SimpleOption.ValueTextGetter<T> valueTextGetter, SimpleOption.Callbacks<T> callbacks, T defaultValue, Consumer<T> changeCallback) - Mappings:
Namespace Name Mixin selector named <init>Lnet/minecraft/client/option/SimpleOption;<init>(Ljava/lang/String;Lnet/minecraft/client/option/SimpleOption$TooltipFactory;Lnet/minecraft/client/option/SimpleOption$ValueTextGetter;Lnet/minecraft/client/option/SimpleOption$Callbacks;Ljava/lang/Object;Ljava/util/function/Consumer;)Vintermediary <init>Lnet/minecraft/class_7172;<init>(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;Lnet/minecraft/class_7172$class_7303;Lnet/minecraft/class_7172$class_7178;Ljava/lang/Object;Ljava/util/function/Consumer;)Vofficial <init>Lfgr;<init>(Ljava/lang/String;Lfgr$l;Lfgr$b;Lfgr$n;Ljava/lang/Object;Ljava/util/function/Consumer;)V
-
SimpleOption
public SimpleOption(String key, SimpleOption.TooltipFactory<T> tooltipFactory, SimpleOption.ValueTextGetter<T> valueTextGetter, SimpleOption.Callbacks<T> callbacks, com.mojang.serialization.Codec<T> codec, T defaultValue, Consumer<T> changeCallback) - Mappings:
Namespace Name Mixin selector named <init>Lnet/minecraft/client/option/SimpleOption;<init>(Ljava/lang/String;Lnet/minecraft/client/option/SimpleOption$TooltipFactory;Lnet/minecraft/client/option/SimpleOption$ValueTextGetter;Lnet/minecraft/client/option/SimpleOption$Callbacks;Lcom/mojang/serialization/Codec;Ljava/lang/Object;Ljava/util/function/Consumer;)Vintermediary <init>Lnet/minecraft/class_7172;<init>(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;Lnet/minecraft/class_7172$class_7303;Lnet/minecraft/class_7172$class_7178;Lcom/mojang/serialization/Codec;Ljava/lang/Object;Ljava/util/function/Consumer;)Vofficial <init>Lfgr;<init>(Ljava/lang/String;Lfgr$l;Lfgr$b;Lfgr$n;Lcom/mojang/serialization/Codec;Ljava/lang/Object;Ljava/util/function/Consumer;)V
-
-
Method Details
-
ofBoolean
public static SimpleOption<Boolean> ofBoolean(String key, boolean defaultValue, Consumer<Boolean> changeCallback) Creates a boolean option.- Mappings:
Namespace Name Mixin selector named ofBooleanLnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;ZLjava/util/function/Consumer;)Lnet/minecraft/client/option/SimpleOption;intermediary method_41751Lnet/minecraft/class_7172;method_41751(Ljava/lang/String;ZLjava/util/function/Consumer;)Lnet/minecraft/class_7172;official aLfgr;a(Ljava/lang/String;ZLjava/util/function/Consumer;)Lfgr;
-
ofBoolean
Creates a boolean option.- Mappings:
Namespace Name Mixin selector named ofBooleanLnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;Z)Lnet/minecraft/client/option/SimpleOption;intermediary method_42402Lnet/minecraft/class_7172;method_42402(Ljava/lang/String;Z)Lnet/minecraft/class_7172;official aLfgr;a(Ljava/lang/String;Z)Lfgr;
-
ofBoolean
public static SimpleOption<Boolean> ofBoolean(String key, SimpleOption.TooltipFactory<Boolean> tooltipFactory, boolean defaultValue) Creates a boolean option.- Mappings:
Namespace Name Mixin selector named ofBooleanLnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;Lnet/minecraft/client/option/SimpleOption$TooltipFactory;Z)Lnet/minecraft/client/option/SimpleOption;intermediary method_41749Lnet/minecraft/class_7172;method_41749(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;Z)Lnet/minecraft/class_7172;official aLfgr;a(Ljava/lang/String;Lfgr$l;Z)Lfgr;
-
ofBoolean
public static SimpleOption<Boolean> ofBoolean(String key, SimpleOption.TooltipFactory<Boolean> tooltipFactory, boolean defaultValue, Consumer<Boolean> changeCallback) Creates a boolean option.- Mappings:
Namespace Name Mixin selector named ofBooleanLnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;Lnet/minecraft/client/option/SimpleOption$TooltipFactory;ZLjava/util/function/Consumer;)Lnet/minecraft/client/option/SimpleOption;intermediary method_41750Lnet/minecraft/class_7172;method_41750(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;ZLjava/util/function/Consumer;)Lnet/minecraft/class_7172;official aLfgr;a(Ljava/lang/String;Lfgr$l;ZLjava/util/function/Consumer;)Lfgr;
-
ofBoolean
public static SimpleOption<Boolean> ofBoolean(String key, SimpleOption.TooltipFactory<Boolean> tooltipFactory, SimpleOption.ValueTextGetter<Boolean> valueTextGetter, boolean defaultValue, Consumer<Boolean> changeCallback) - Mappings:
Namespace Name Mixin selector named ofBooleanLnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;Lnet/minecraft/client/option/SimpleOption$TooltipFactory;Lnet/minecraft/client/option/SimpleOption$ValueTextGetter;ZLjava/util/function/Consumer;)Lnet/minecraft/client/option/SimpleOption;intermediary method_47604Lnet/minecraft/class_7172;method_47604(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;Lnet/minecraft/class_7172$class_7303;ZLjava/util/function/Consumer;)Lnet/minecraft/class_7172;official aLfgr;a(Ljava/lang/String;Lfgr$l;Lfgr$b;ZLjava/util/function/Consumer;)Lfgr;
-
emptyTooltip
Returns the getter for thetooltipFactoryGetterparameter of the constructor to indicate empty tooltips.- Returns:
- the getter for the
tooltipFactoryGetterparameter of the constructor to indicate empty tooltips - Mappings:
Namespace Name Mixin selector named emptyTooltipLnet/minecraft/client/option/SimpleOption;emptyTooltip()Lnet/minecraft/client/option/SimpleOption$TooltipFactory;intermediary method_42399Lnet/minecraft/class_7172;method_42399()Lnet/minecraft/class_7172$class_7277;official aLfgr;a()Lfgr$l;
-
constantTooltip
Returns the getter for thetooltipFactoryGetterparameter of the constructor to indicate constant tooltips.- Returns:
- the getter for the
tooltipFactoryGetterparameter of the constructor to indicate constant tooltips - Mappings:
Namespace Name Mixin selector named constantTooltipLnet/minecraft/client/option/SimpleOption;constantTooltip(Lnet/minecraft/text/Text;)Lnet/minecraft/client/option/SimpleOption$TooltipFactory;intermediary method_42717Lnet/minecraft/class_7172;method_42717(Lnet/minecraft/class_2561;)Lnet/minecraft/class_7172$class_7277;official aLfgr;a(Lwz;)Lfgr$l;
-
enumValueText
Returns the getter for thevalueTextGetterparameter of the constructor to use the value's text as the option's rendered text.- Returns:
- the getter for the
valueTextGetterparameter of the constructor to use the value's text as the option's rendered text - API Note:
- This requires the value to be an enum implementing
TranslatableOption. - Mappings:
Namespace Name Mixin selector named enumValueTextLnet/minecraft/client/option/SimpleOption;enumValueText()Lnet/minecraft/client/option/SimpleOption$ValueTextGetter;intermediary method_42720Lnet/minecraft/class_7172;method_42720()Lnet/minecraft/class_7172$class_7303;official bLfgr;b()Lfgr$b;
-
createWidget
- Mappings:
Namespace Name Mixin selector named createWidgetLnet/minecraft/client/option/SimpleOption;createWidget(Lnet/minecraft/client/option/GameOptions;)Lnet/minecraft/client/gui/widget/ClickableWidget;intermediary method_57701Lnet/minecraft/class_7172;method_57701(Lnet/minecraft/class_315;)Lnet/minecraft/class_339;official aLfgr;a(Lfgs;)Lfik;
-
createWidget
- Mappings:
Namespace Name Mixin selector named createWidgetLnet/minecraft/client/option/SimpleOption;createWidget(Lnet/minecraft/client/option/GameOptions;III)Lnet/minecraft/client/gui/widget/ClickableWidget;intermediary method_18520Lnet/minecraft/class_7172;method_18520(Lnet/minecraft/class_315;III)Lnet/minecraft/class_339;official aLfgr;a(Lfgs;III)Lfik;
-
createWidget
public ClickableWidget createWidget(GameOptions options, int x, int y, int width, Consumer<T> changeCallback) - Mappings:
Namespace Name Mixin selector named createWidgetLnet/minecraft/client/option/SimpleOption;createWidget(Lnet/minecraft/client/option/GameOptions;IIILjava/util/function/Consumer;)Lnet/minecraft/client/gui/widget/ClickableWidget;intermediary method_47603Lnet/minecraft/class_7172;method_47603(Lnet/minecraft/class_315;IIILjava/util/function/Consumer;)Lnet/minecraft/class_339;official aLfgr;a(Lfgs;IIILjava/util/function/Consumer;)Lfik;
-
getValue
Returns the option's current value.- Returns:
- the option's current value
- Mappings:
Namespace Name Mixin selector named getValueLnet/minecraft/client/option/SimpleOption;getValue()Ljava/lang/Object;intermediary method_41753Lnet/minecraft/class_7172;method_41753()Ljava/lang/Object;official cLfgr;c()Ljava/lang/Object;
-
getCodec
- Mappings:
Namespace Name Mixin selector named getCodecLnet/minecraft/client/option/SimpleOption;getCodec()Lcom/mojang/serialization/Codec;intermediary method_42404Lnet/minecraft/class_7172;method_42404()Lcom/mojang/serialization/Codec;official dLfgr;d()Lcom/mojang/serialization/Codec;
-
toString
-
setValue
Sets the option's value.The behavior for invalid
valuevaries; the validator can either coerce the passed value into a valid one by clamping etc, or fail the validation and reset to the default value.If the new value differs from the new value,
changeCallbackwill trigger.- Mappings:
Namespace Name Mixin selector named setValueLnet/minecraft/client/option/SimpleOption;setValue(Ljava/lang/Object;)Vintermediary method_41748Lnet/minecraft/class_7172;method_41748(Ljava/lang/Object;)Vofficial aLfgr;a(Ljava/lang/Object;)V
-
getCallbacks
- Mappings:
Namespace Name Mixin selector named getCallbacksLnet/minecraft/client/option/SimpleOption;getCallbacks()Lnet/minecraft/client/option/SimpleOption$Callbacks;intermediary method_41754Lnet/minecraft/class_7172;method_41754()Lnet/minecraft/class_7172$class_7178;official eLfgr;e()Lfgr$n;
-