Record Class StoredKeybind

java.lang.Object
java.lang.Record
dev.munebase.dynamickeybinds.persistence.StoredKeybind
Record Components:
id - unique identifier for the keybind (e.g., "mymod:ability_cast")
keyCode - the GLFW key code (numeric value 32-348)
category - the keybind category for menu organization
action - optional custom action that will be triggered when the key is pressed. If empty, the keybind can still be used but won't trigger any special behavior
displaySpec - optional display metadata for the keybind label. If empty, uses default display.

public record StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, DisplaySpec displaySpec) extends Record
Immutable record representing a stored keybind that can be persisted to NBT or net sync. Represents the complete state of a dynamic keybind including its ID, keycode, category, optional custom action, and optional display metadata. This record is used as the data transfer object between registration, persistence, networking, and client rendering.

Serialization: This record is serialized to NBT tags for server-side persistence and network synchronization. The action field (if present) is nested under an "action" tag containing "actionID" and "data" subtags. The displaySpec is nested under an optional "display" tag that contains translation key, fallback, and args.

Example:

 
 // Create without action or display (simple keybind)
 StoredKeybind simpleKey = new StoredKeybind("mymod:move_key", 19, "mymod");
 
 // Create with action and display (contextual keybind with custom label)
 CompoundTag actionData = new CompoundTag();
 actionData.putInt("x", 100);
 DynamicKeybindAction action = new DynamicKeybindAction("mymod:mark_location", actionData);
 DisplaySpec displaySpec = DisplaySpec.ofTranslationKeyWithFallback(
   "key.mymod.mark_instance",
   "Mark Location"
 );
 StoredKeybind contextualKey = new StoredKeybind(
   "mymod:mark_key",
   33,
   "mymod",
   Optional.of(action),
   displaySpec
 );
 
 
  • Constructor Details

    • StoredKeybind

      public StoredKeybind(String id, int keyCode, String category)
      Backward-compatible constructor for keybinds without custom actions or display.
      Parameters:
      id - the keybind identifier
      keyCode - the GLFW key code
      category - the keybind category
    • StoredKeybind

      public StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action)
      Constructor for keybinds with action but no custom display.
      Parameters:
      id - the keybind identifier
      keyCode - the GLFW key code
      category - the keybind category
      action - the optional action
    • StoredKeybind

      public StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, DisplaySpec displaySpec)
      Creates an instance of a StoredKeybind record class.
      Parameters:
      id - the value for the id record component
      keyCode - the value for the keyCode record component
      category - the value for the category record component
      action - the value for the action record component
      displaySpec - the value for the displaySpec record component
  • Method Details

    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • keyCode

      public int keyCode()
      Returns the value of the keyCode record component.
      Returns:
      the value of the keyCode record component
    • category

      public String category()
      Returns the value of the category record component.
      Returns:
      the value of the category record component
    • action

      public Optional<DynamicKeybindAction> action()
      Returns the value of the action record component.
      Returns:
      the value of the action record component
    • displaySpec

      public DisplaySpec displaySpec()
      Returns the value of the displaySpec record component.
      Returns:
      the value of the displaySpec record component