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 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 Summary
ConstructorsConstructorDescriptionStoredKeybind(String id, int keyCode, String category) Backward-compatible constructor for keybinds without custom actions.StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action) Creates an instance of aStoredKeybindrecord class. -
Method Summary
Modifier and TypeMethodDescriptionaction()Returns the value of theactionrecord component.category()Returns the value of thecategoryrecord 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.- Parameters:
id- the keybind identifierkeyCode- the GLFW key codecategory- the keybind category
-
StoredKeybind
public StoredKeybind(String id, int keyCode, String category, Optional<DynamicKeybindAction> action) Creates an instance of aStoredKeybindrecord class.
-
-
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
-