Record Class DisplaySpec

java.lang.Object
java.lang.Record
dev.munebase.dynamickeybinds.model.DisplaySpec

public record DisplaySpec(Optional<String> translationKey, Optional<String> fallback, List<DisplayArg> args) extends Record
Specification for how a dynamic keybind should be displayed in the UI. Contains: - translationKey: optional translation key (e.g., "key.mymod.my_instance") - fallback: optional fallback text if translation key is not found - args: optional list of typed arguments for translation string formatting If empty (no translationKey), the keybind will use its default display (typically "key." + id).
  • Constructor Details

    • DisplaySpec

      public DisplaySpec(Optional<String> translationKey, Optional<String> fallback, List<DisplayArg> args)
      Creates an instance of a DisplaySpec record class.
      Parameters:
      translationKey - the value for the translationKey record component
      fallback - the value for the fallback record component
      args - the value for the args record component
  • Method Details

    • empty

      public static DisplaySpec empty()
      Create an empty DisplaySpec (will use default display).
    • ofTranslationKey

      public static DisplaySpec ofTranslationKey(String translationKey)
      Create a DisplaySpec with only a translation key.
    • ofTranslationKeyWithFallback

      public static DisplaySpec ofTranslationKeyWithFallback(String translationKey, String fallback)
      Create a DisplaySpec with translation key and fallback.
    • ofTranslationKeyWithFallbackAndArgs

      public static DisplaySpec ofTranslationKeyWithFallbackAndArgs(String translationKey, String fallback, List<DisplayArg> args)
      Create a DisplaySpec with translation key, fallback, and arguments.
    • toComponent

      public Optional<net.minecraft.network.chat.Component> toComponent()
      Convert this DisplaySpec to a Component for rendering. If translationKey is present, returns a translatable component. Otherwise returns empty (caller should use default).
    • toNbt

      public net.minecraft.nbt.CompoundTag toNbt()
      Serialize this DisplaySpec to NBT.
    • fromNbt

      public static DisplaySpec fromNbt(net.minecraft.nbt.CompoundTag tag)
      Deserialize a DisplaySpec from NBT. If tag is empty or null, returns empty DisplaySpec.
    • isEmpty

      public boolean isEmpty()
      Check if this DisplaySpec is effectively empty.
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • translationKey

      public Optional<String> translationKey()
      Returns the value of the translationKey record component.
      Returns:
      the value of the translationKey record component
    • fallback

      public Optional<String> fallback()
      Returns the value of the fallback record component.
      Returns:
      the value of the fallback record component
    • args

      public List<DisplayArg> args()
      Returns the value of the args record component.
      Returns:
      the value of the args record component