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

public record StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action) 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, and optional custom action. 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.

Example:

 
 // Create without action (simple keybind)
 StoredKeybind simpleKey = new StoredKeybind("mymod:move_key", 19, "mymod");
 
 // Create with action (contextual keybind)
 CompoundTag actionData = new CompoundTag();
 actionData.putInt("x", 100);
 DynamicKeybindAction action = new DynamicKeybindAction("mymod:mark_location", actionData);
 StoredKeybind contextualKey = new StoredKeybind(
   "mymod:mark_key",
   33,
   "mymod",
   Optional.of(action)
 );
 
 
  • Constructor Details

    • StoredKeybind

      public StoredKeybind(String id, int keyCode, String category)
      Backward-compatible constructor for keybinds without custom actions.
      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)
      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
  • 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