Class SimpleOption<T>

java.lang.Object
net.minecraft.client.option.SimpleOption<T>

@Environment(CLIENT) public final class SimpleOption<T> extends Object
A class representing an option of a client. Exactly one instance of this class should be created per option. See below for how to create an instance.

Option values Link icon

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 Link icon

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:

See also several ofBoolean methods for options using boolean values.

Modifiers Link icon

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 Link icon

Options themselves have names; the translation key of the option needs to be passed when constructing this class. This corresponds to text. 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/SimpleOption
intermediary net/minecraft/class_7172
official fln
  • Field Details Link icon

    • LOGGER Link icon

      private static final Logger LOGGER
      Mappings:
      Namespace Name Mixin selector
      named LOGGER Lnet/minecraft/client/option/SimpleOption;LOGGER:Lorg/slf4j/Logger;
      intermediary field_37862 Lnet/minecraft/class_7172;field_37862:Lorg/slf4j/Logger;
      official c Lfln;c:Lorg/slf4j/Logger;
    • BOOLEAN Link icon

      A set of callbacks for boolean options.
      API Note:
      See also several ofBoolean methods in this class which provide easier ways of creating a boolean option.
      Mappings:
      Namespace Name Mixin selector
      named BOOLEAN Lnet/minecraft/client/option/SimpleOption;BOOLEAN:Lnet/minecraft/client/option/SimpleOption$PotentialValuesBasedCallbacks;
      intermediary field_38278 Lnet/minecraft/class_7172;field_38278:Lnet/minecraft/class_7172$class_7173;
      official a Lfln;a:Lfln$e;
    • BOOLEAN_TEXT_GETTER Link icon

      public static final SimpleOption.ValueTextGetter<Boolean> BOOLEAN_TEXT_GETTER
      Mappings:
      Namespace Name Mixin selector
      named BOOLEAN_TEXT_GETTER Lnet/minecraft/client/option/SimpleOption;BOOLEAN_TEXT_GETTER:Lnet/minecraft/client/option/SimpleOption$ValueTextGetter;
      intermediary field_41333 Lnet/minecraft/class_7172;field_41333:Lnet/minecraft/class_7172$class_7303;
      official b Lfln;b:Lfln$b;
    • tooltipFactory Link icon

      private final SimpleOption.TooltipFactory<T> tooltipFactory
      Mappings:
      Namespace Name Mixin selector
      named tooltipFactory Lnet/minecraft/client/option/SimpleOption;tooltipFactory:Lnet/minecraft/client/option/SimpleOption$TooltipFactory;
      intermediary field_37863 Lnet/minecraft/class_7172;field_37863:Lnet/minecraft/class_7172$class_7277;
      official d Lfln;d:Lfln$l;
    • textGetter Link icon

      final Function<T,Text> textGetter
      Mappings:
      Namespace Name Mixin selector
      named textGetter Lnet/minecraft/client/option/SimpleOption;textGetter:Ljava/util/function/Function;
      intermediary field_37864 Lnet/minecraft/class_7172;field_37864:Ljava/util/function/Function;
      official e Lfln;e:Ljava/util/function/Function;
    • callbacks Link icon

      private final SimpleOption.Callbacks<T> callbacks
      Mappings:
      Namespace Name Mixin selector
      named callbacks Lnet/minecraft/client/option/SimpleOption;callbacks:Lnet/minecraft/client/option/SimpleOption$Callbacks;
      intermediary field_37865 Lnet/minecraft/class_7172;field_37865:Lnet/minecraft/class_7172$class_7178;
      official f Lfln;f:Lfln$n;
    • codec Link icon

      private final com.mojang.serialization.Codec<T> codec
      Mappings:
      Namespace Name Mixin selector
      named codec Lnet/minecraft/client/option/SimpleOption;codec:Lcom/mojang/serialization/Codec;
      intermediary field_38279 Lnet/minecraft/class_7172;field_38279:Lcom/mojang/serialization/Codec;
      official g Lfln;g:Lcom/mojang/serialization/Codec;
    • defaultValue Link icon

      private final T defaultValue
      Mappings:
      Namespace Name Mixin selector
      named defaultValue Lnet/minecraft/client/option/SimpleOption;defaultValue:Ljava/lang/Object;
      intermediary field_37866 Lnet/minecraft/class_7172;field_37866:Ljava/lang/Object;
      official h Lfln;h:Ljava/lang/Object;
    • changeCallback Link icon

      private final Consumer<T> changeCallback
      Mappings:
      Namespace Name Mixin selector
      named changeCallback Lnet/minecraft/client/option/SimpleOption;changeCallback:Ljava/util/function/Consumer;
      intermediary field_37867 Lnet/minecraft/class_7172;field_37867:Ljava/util/function/Consumer;
      official i Lfln;i:Ljava/util/function/Consumer;
    • text Link icon

      final Text text
      Mappings:
      Namespace Name Mixin selector
      named text Lnet/minecraft/client/option/SimpleOption;text:Lnet/minecraft/text/Text;
      intermediary field_38280 Lnet/minecraft/class_7172;field_38280:Lnet/minecraft/class_2561;
      official j Lfln;j:Lwp;
    • value Link icon

      T value
      Mappings:
      Namespace Name Mixin selector
      named value Lnet/minecraft/client/option/SimpleOption;value:Ljava/lang/Object;
      intermediary field_37868 Lnet/minecraft/class_7172;field_37868:Ljava/lang/Object;
      official k Lfln;k:Ljava/lang/Object;
  • Constructor Details Link icon

    • SimpleOption Link icon

      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;)V
      intermediary <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;)V
      official <init> Lfln;<init>(Ljava/lang/String;Lfln$l;Lfln$b;Lfln$n;Ljava/lang/Object;Ljava/util/function/Consumer;)V
    • SimpleOption Link icon

      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;)V
      intermediary <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;)V
      official <init> Lfln;<init>(Ljava/lang/String;Lfln$l;Lfln$b;Lfln$n;Lcom/mojang/serialization/Codec;Ljava/lang/Object;Ljava/util/function/Consumer;)V
  • Method Details Link icon

    • ofBoolean Link icon

      public static SimpleOption<Boolean> ofBoolean(String key, boolean defaultValue, Consumer<Boolean> changeCallback)
      Creates a boolean option.
      Mappings:
      Namespace Name Mixin selector
      named ofBoolean Lnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;ZLjava/util/function/Consumer;)Lnet/minecraft/client/option/SimpleOption;
      intermediary method_41751 Lnet/minecraft/class_7172;method_41751(Ljava/lang/String;ZLjava/util/function/Consumer;)Lnet/minecraft/class_7172;
      official a Lfln;a(Ljava/lang/String;ZLjava/util/function/Consumer;)Lfln;
    • ofBoolean Link icon

      public static SimpleOption<Boolean> ofBoolean(String key, boolean defaultValue)
      Creates a boolean option.
      Mappings:
      Namespace Name Mixin selector
      named ofBoolean Lnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;Z)Lnet/minecraft/client/option/SimpleOption;
      intermediary method_42402 Lnet/minecraft/class_7172;method_42402(Ljava/lang/String;Z)Lnet/minecraft/class_7172;
      official a Lfln;a(Ljava/lang/String;Z)Lfln;
    • ofBoolean Link icon

      public static SimpleOption<Boolean> ofBoolean(String key, SimpleOption.TooltipFactory<Boolean> tooltipFactory, boolean defaultValue)
      Creates a boolean option.
      Mappings:
      Namespace Name Mixin selector
      named ofBoolean Lnet/minecraft/client/option/SimpleOption;ofBoolean(Ljava/lang/String;Lnet/minecraft/client/option/SimpleOption$TooltipFactory;Z)Lnet/minecraft/client/option/SimpleOption;
      intermediary method_41749 Lnet/minecraft/class_7172;method_41749(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;Z)Lnet/minecraft/class_7172;
      official a Lfln;a(Ljava/lang/String;Lfln$l;Z)Lfln;
    • ofBoolean Link icon

      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 ofBoolean Lnet/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_41750 Lnet/minecraft/class_7172;method_41750(Ljava/lang/String;Lnet/minecraft/class_7172$class_7277;ZLjava/util/function/Consumer;)Lnet/minecraft/class_7172;
      official a Lfln;a(Ljava/lang/String;Lfln$l;ZLjava/util/function/Consumer;)Lfln;
    • ofBoolean Link icon

      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 ofBoolean Lnet/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_47604 Lnet/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 a Lfln;a(Ljava/lang/String;Lfln$l;Lfln$b;ZLjava/util/function/Consumer;)Lfln;
    • emptyTooltip Link icon

      public static <T> SimpleOption.TooltipFactory<T> emptyTooltip()
      Returns the getter for the tooltipFactoryGetter parameter of the constructor to indicate empty tooltips.
      Returns:
      the getter for the tooltipFactoryGetter parameter of the constructor to indicate empty tooltips
      Mappings:
      Namespace Name Mixin selector
      named emptyTooltip Lnet/minecraft/client/option/SimpleOption;emptyTooltip()Lnet/minecraft/client/option/SimpleOption$TooltipFactory;
      intermediary method_42399 Lnet/minecraft/class_7172;method_42399()Lnet/minecraft/class_7172$class_7277;
      official a Lfln;a()Lfln$l;
    • constantTooltip Link icon

      public static <T> SimpleOption.TooltipFactory<T> constantTooltip(Text text)
      Returns the getter for the tooltipFactoryGetter parameter of the constructor to indicate constant tooltips.
      Returns:
      the getter for the tooltipFactoryGetter parameter of the constructor to indicate constant tooltips
      Mappings:
      Namespace Name Mixin selector
      named constantTooltip Lnet/minecraft/client/option/SimpleOption;constantTooltip(Lnet/minecraft/text/Text;)Lnet/minecraft/client/option/SimpleOption$TooltipFactory;
      intermediary method_42717 Lnet/minecraft/class_7172;method_42717(Lnet/minecraft/class_2561;)Lnet/minecraft/class_7172$class_7277;
      official a Lfln;a(Lwp;)Lfln$l;
    • enumValueText Link icon

      public static <T extends TranslatableOption> SimpleOption.ValueTextGetter<T> enumValueText()
      Returns the getter for the valueTextGetter parameter of the constructor to use the value's text as the option's rendered text.
      Returns:
      the getter for the valueTextGetter parameter 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 enumValueText Lnet/minecraft/client/option/SimpleOption;enumValueText()Lnet/minecraft/client/option/SimpleOption$ValueTextGetter;
      intermediary method_42720 Lnet/minecraft/class_7172;method_42720()Lnet/minecraft/class_7172$class_7303;
      official b Lfln;b()Lfln$b;
    • createWidget Link icon

      public ClickableWidget createWidget(GameOptions options)
      Mappings:
      Namespace Name Mixin selector
      named createWidget Lnet/minecraft/client/option/SimpleOption;createWidget(Lnet/minecraft/client/option/GameOptions;)Lnet/minecraft/client/gui/widget/ClickableWidget;
      intermediary method_57701 Lnet/minecraft/class_7172;method_57701(Lnet/minecraft/class_315;)Lnet/minecraft/class_339;
      official a Lfln;a(Lflo;)Lfos;
    • createWidget Link icon

      public ClickableWidget createWidget(GameOptions options, int x, int y, int width)
      Mappings:
      Namespace Name Mixin selector
      named createWidget Lnet/minecraft/client/option/SimpleOption;createWidget(Lnet/minecraft/client/option/GameOptions;III)Lnet/minecraft/client/gui/widget/ClickableWidget;
      intermediary method_18520 Lnet/minecraft/class_7172;method_18520(Lnet/minecraft/class_315;III)Lnet/minecraft/class_339;
      official a Lfln;a(Lflo;III)Lfos;
    • createWidget Link icon

      public ClickableWidget createWidget(GameOptions options, int x, int y, int width, Consumer<T> changeCallback)
      Mappings:
      Namespace Name Mixin selector
      named createWidget Lnet/minecraft/client/option/SimpleOption;createWidget(Lnet/minecraft/client/option/GameOptions;IIILjava/util/function/Consumer;)Lnet/minecraft/client/gui/widget/ClickableWidget;
      intermediary method_47603 Lnet/minecraft/class_7172;method_47603(Lnet/minecraft/class_315;IIILjava/util/function/Consumer;)Lnet/minecraft/class_339;
      official a Lfln;a(Lflo;IIILjava/util/function/Consumer;)Lfos;
    • getValue Link icon

      public T getValue()
      Returns the option's current value.
      Returns:
      the option's current value
      Mappings:
      Namespace Name Mixin selector
      named getValue Lnet/minecraft/client/option/SimpleOption;getValue()Ljava/lang/Object;
      intermediary method_41753 Lnet/minecraft/class_7172;method_41753()Ljava/lang/Object;
      official c Lfln;c()Ljava/lang/Object;
    • getCodec Link icon

      public com.mojang.serialization.Codec<T> getCodec()
      Mappings:
      Namespace Name Mixin selector
      named getCodec Lnet/minecraft/client/option/SimpleOption;getCodec()Lcom/mojang/serialization/Codec;
      intermediary method_42404 Lnet/minecraft/class_7172;method_42404()Lcom/mojang/serialization/Codec;
      official d Lfln;d()Lcom/mojang/serialization/Codec;
    • toString Link icon

      public String toString()
      Overrides:
      toString in class Object
    • setValue Link icon

      public void setValue(T value)
      Sets the option's value.

      The behavior for invalid value varies; 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, changeCallback will trigger.

      Mappings:
      Namespace Name Mixin selector
      named setValue Lnet/minecraft/client/option/SimpleOption;setValue(Ljava/lang/Object;)V
      intermediary method_41748 Lnet/minecraft/class_7172;method_41748(Ljava/lang/Object;)V
      official a Lfln;a(Ljava/lang/Object;)V
    • getCallbacks Link icon

      public SimpleOption.Callbacks<T> getCallbacks()
      Mappings:
      Namespace Name Mixin selector
      named getCallbacks Lnet/minecraft/client/option/SimpleOption;getCallbacks()Lnet/minecraft/client/option/SimpleOption$Callbacks;
      intermediary method_41754 Lnet/minecraft/class_7172;method_41754()Lnet/minecraft/class_7172$class_7178;
      official e Lfln;e()Lfln$n;