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 organizationaction- 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 behaviordisplaySpec- 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 Summary
ConstructorsConstructorDescriptionStoredKeybind(String id, int keyCode, String category) Backward-compatible constructor for keybinds without custom actions or display.StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action) Constructor for keybinds with action but no custom display.StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, DisplaySpec displaySpec) Creates an instance of aStoredKeybindrecord class. -
Method Summary
Modifier and TypeMethodDescriptionaction()Returns the value of theactionrecord component.category()Returns the value of thecategoryrecord component.Returns the value of thedisplaySpecrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.id()Returns the value of theidrecord component.intkeyCode()Returns the value of thekeyCoderecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
StoredKeybind
Backward-compatible constructor for keybinds without custom actions or display.- Parameters:
id- the keybind identifierkeyCode- the GLFW key codecategory- 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 identifierkeyCode- the GLFW key codecategory- the keybind categoryaction- the optional action
-
StoredKeybind
public StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action, DisplaySpec displaySpec) Creates an instance of aStoredKeybindrecord class.- Parameters:
id- the value for theidrecord componentkeyCode- the value for thekeyCoderecord componentcategory- the value for thecategoryrecord componentaction- the value for theactionrecord componentdisplaySpec- the value for thedisplaySpecrecord component
-
-
Method Details
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
id
Returns the value of theidrecord component.- Returns:
- the value of the
idrecord component
-
keyCode
public int keyCode()Returns the value of thekeyCoderecord component.- Returns:
- the value of the
keyCoderecord component
-
category
Returns the value of thecategoryrecord component.- Returns:
- the value of the
categoryrecord component
-
action
Returns the value of theactionrecord component.- Returns:
- the value of the
actionrecord component
-
displaySpec
Returns the value of thedisplaySpecrecord component.- Returns:
- the value of the
displaySpecrecord component
-