Class CyclingOption<T>

java.lang.Object
net.uku3lig.ukulib.config.option.CyclingOption<T>
Type Parameters:
T - The type of the value
All Implemented Interfaces:
WidgetCreator

public class CyclingOption<T> extends Object implements WidgetCreator
An option type based on a finite amount of cycling values of the same type.
  • Field Details

    • BOOL_TO_TEXT

      public static final Function<Boolean,net.minecraft.text.Text> BOOL_TO_TEXT
      Boolean to text converter.
  • Constructor Details

    • CyclingOption

      public CyclingOption(String key, Collection<T> values, T initialValue, Consumer<T> setter, Function<T,net.minecraft.text.Text> valueToText, net.minecraft.client.option.SimpleOption.TooltipFactory<T> tooltipFactory, boolean active)
      Constructs a new generic cycling option.
      Parameters:
      key - The translation key
      values - The possible option values
      initialValue - The initial displayed value
      setter - The callback for the modified value
      valueToText - The function that converts the value to human-readable text
      tooltipFactory - The tooltip factory
      active - Whether the button can be clicked
    • CyclingOption

      public CyclingOption(String key, Collection<T> values, T initialValue, Consumer<T> setter, Function<T,net.minecraft.text.Text> valueToText, net.minecraft.client.option.SimpleOption.TooltipFactory<T> tooltipFactory)
      Constructs a new generic cycling option.
      Parameters:
      key - The translation key
      values - The possible option values
      initialValue - The initial displayed value
      setter - The callback for the modified value
      valueToText - The function that converts the value to human-readable text
      tooltipFactory - The tooltip factory
    • CyclingOption

      public CyclingOption(String key, Collection<T> values, T initialValue, Consumer<T> setter, Function<T,net.minecraft.text.Text> valueToText)
      Constructs a new generic cycling option, with no tooltip.
      Parameters:
      key - The translation key
      values - The possible option values
      initialValue - The initial displayed value
      setter - The callback for the modified value
      valueToText - The function that converts the value to human-readable text
      See Also:
  • Method Details

    • ofBoolean

      public static CyclingOption<Boolean> ofBoolean(String key, boolean initialValue, Consumer<Boolean> setter, net.minecraft.client.option.SimpleOption.TooltipFactory<Boolean> tooltipFactory)
      Creates a new boolean option.
      Parameters:
      key - The translation key
      initialValue - The initial boolean value
      setter - The callback for the modified value
      tooltipFactory - The tooltip factory
      Returns:
      The newly constructed option
    • ofBoolean

      public static CyclingOption<Boolean> ofBoolean(String key, boolean initialValue, Consumer<Boolean> setter)
      Creates a new boolean option, with an empty tooltip.
      Parameters:
      key - The translation key
      initialValue - The initial boolean value
      setter - The callback for the modified value
      Returns:
      The newly constructed option
      See Also:
    • ofTranslatable

      public static <T extends net.minecraft.util.TranslatableOption> CyclingOption<T> ofTranslatable(String key, Collection<T> values, T initialValue, Consumer<T> setter, net.minecraft.client.option.SimpleOption.TooltipFactory<T> tooltipFactory)
      Creates a new option from a TranslatableOption.
      Type Parameters:
      T - The type of the option
      Parameters:
      key - The translation key
      values - The values to be displayed
      initialValue - The initial value
      setter - The callback for the modified value
      tooltipFactory - The tooltip factory
      Returns:
      The newly constructed option
    • ofTranslatable

      public static <T extends net.minecraft.util.TranslatableOption> CyclingOption<T> ofTranslatable(String key, Collection<T> values, T initialValue, Consumer<T> setter)
      Creates a new option from a TranslatableOption, with an empty tooltip.
      Type Parameters:
      T - The type of the option
      Parameters:
      key - The translation key
      values - The values to be displayed
      initialValue - The initial value
      setter - The callback for the modified value
      Returns:
      The newly constructed option
    • ofEnum

      public static <T extends Enum<T>> CyclingOption<T> ofEnum(String key, Class<T> klass, T initialValue, Consumer<T> setter, Function<T,net.minecraft.text.Text> valueToText, net.minecraft.client.option.SimpleOption.TooltipFactory<T> tooltipFactory)
      Creates a new option based on an enum's values.
      Type Parameters:
      T - The type of the enum
      Parameters:
      key - The translation key
      klass - The class type of the enum
      initialValue - The initial value
      setter - The callback for the modified value
      valueToText - The function that converts the value to human-readable text
      tooltipFactory - The tooltip factory
      Returns:
      The newly created option
    • ofEnum

      public static <T extends Enum<T>> CyclingOption<T> ofEnum(String key, Class<T> klass, T initialValue, Consumer<T> setter, Function<T,net.minecraft.text.Text> valueToText)
      Creates a new option based on an enum's values, with an empty tooltip.
      Type Parameters:
      T - The type of the enum
      Parameters:
      key - The translation key
      klass - The class type of the enum
      initialValue - The initial value
      setter - The callback for the modified value
      valueToText - The function that converts the value to human-readable text
      Returns:
      The newly created option
      See Also:
    • ofEnum

      public static <T extends Enum<T>> CyclingOption<T> ofEnum(String key, Class<T> klass, T initialValue, Consumer<T> setter)
      Creates a new option based on an enum's values, with an empty tooltip. The value text is the constant's name.
      Type Parameters:
      T - The type of the enum
      Parameters:
      key - The translation key
      klass - The class type of the enum
      initialValue - The initial value
      setter - The callback for the modified value
      Returns:
      The newly created option
      See Also:
    • ofTranslatableEnum

      public static <T extends Enum<T> & net.minecraft.util.TranslatableOption> CyclingOption<T> ofTranslatableEnum(String key, Class<T> klass, T initialValue, Consumer<T> setter, net.minecraft.client.option.SimpleOption.TooltipFactory<T> tooltipFactory)
      Creates a new option based on a translatable enum's values.
      Type Parameters:
      T - The type of the enum
      Parameters:
      key - The translation key
      klass - The class type of the enum
      initialValue - The initial value
      setter - The callback for the modified value
      tooltipFactory - The tooltip factory
      Returns:
      The newly created option
    • ofTranslatableEnum

      public static <T extends Enum<T> & net.minecraft.util.TranslatableOption> CyclingOption<T> ofTranslatableEnum(String key, Class<T> klass, T initialValue, Consumer<T> setter)
      Creates a new option based on a translatable enum's values, with an empty tooltip.
      Type Parameters:
      T - The type of the enum
      Parameters:
      key - The translation key
      klass - The class type of the enum
      initialValue - The initial value
      setter - The callback for the modified value
      Returns:
      The newly created option
      See Also:
    • createWidget

      public net.minecraft.client.gui.widget.ClickableWidget createWidget(int x, int y, int width, int height)
      Description copied from interface: WidgetCreator
      Creates the widget.
      Specified by:
      createWidget in interface WidgetCreator
      Parameters:
      x - The x position
      y - The y position
      width - The widget width
      height - The widget height
      Returns:
      The created widget
    • enumNameToText

      public static <T extends Enum<T>> net.minecraft.text.Text enumNameToText(T value)
      Returns a text that contains the name of the enum constant.
      Type Parameters:
      T - The type of the enum
      Parameters:
      value - The enum constant
      Returns:
      The text