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 Summary
ConstructorsConstructorDescriptionDisplaySpec(Optional<String> translationKey, Optional<String> fallback, List<DisplayArg> args) Creates an instance of aDisplaySpecrecord class. -
Method Summary
Modifier and TypeMethodDescriptionargs()Returns the value of theargsrecord component.static DisplaySpecempty()Create an empty DisplaySpec (will use default display).final booleanIndicates whether some other object is "equal to" this one.fallback()Returns the value of thefallbackrecord component.static DisplaySpecfromNbt(net.minecraft.nbt.CompoundTag tag) Deserialize a DisplaySpec from NBT.final inthashCode()Returns a hash code value for this object.booleanisEmpty()Check if this DisplaySpec is effectively empty.static DisplaySpecofTranslationKey(String translationKey) Create a DisplaySpec with only a translation key.static DisplaySpecofTranslationKeyWithFallback(String translationKey, String fallback) Create a DisplaySpec with translation key and fallback.static DisplaySpecofTranslationKeyWithFallbackAndArgs(String translationKey, String fallback, List<DisplayArg> args) Create a DisplaySpec with translation key, fallback, and arguments.Optional<net.minecraft.network.chat.Component>Convert this DisplaySpec to a Component for rendering.net.minecraft.nbt.CompoundTagtoNbt()Serialize this DisplaySpec to NBT.final StringtoString()Returns a string representation of this record class.Returns the value of thetranslationKeyrecord component.
-
Constructor Details
-
DisplaySpec
public DisplaySpec(Optional<String> translationKey, Optional<String> fallback, List<DisplayArg> args) Creates an instance of aDisplaySpecrecord class.- Parameters:
translationKey- the value for thetranslationKeyrecord componentfallback- the value for thefallbackrecord componentargs- the value for theargsrecord component
-
-
Method Details
-
empty
Create an empty DisplaySpec (will use default display). -
ofTranslationKey
Create a DisplaySpec with only a translation key. -
ofTranslationKeyWithFallback
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
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
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
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
translationKey
Returns the value of thetranslationKeyrecord component.- Returns:
- the value of the
translationKeyrecord component
-
fallback
Returns the value of thefallbackrecord component.- Returns:
- the value of the
fallbackrecord component
-
args
Returns the value of theargsrecord component.- Returns:
- the value of the
argsrecord component
-