Record Class DynamicKeybindAction

java.lang.Object
java.lang.Record
dev.munebase.dynamickeybinds.action.DynamicKeybindAction
Record Components:
actionID - unique identifier for the action type (e.g., "example:read_block_above")
data - NBT compound containing action-specific data (e.g., {dimension, pos})

public record DynamicKeybindAction(String actionID, net.minecraft.nbt.CompoundTag data) extends Record
Represents a custom action triggered by a dynamic keybind. This immutable record stores an action identifier and optional NBT data payload, allowing third-party mods to define custom context-aware keybind behaviors. The action can be serialized to NBT for persistence and network synchronization.

Purpose: Enables extensibility by allowing other mods to create contextual keybind actions. For example, a library mod might define an action that stores block coordinates and dimension, enabling the keybind to perform different operations depending on where in the world it was created.

Example:

 
 // Create an action with custom data
 CompoundTag data = new CompoundTag();
 data.putInt("dimension", 0);
 data.putInt("x", 250);
 data.putInt("y", 64);
 data.putInt("z", 300);

 DynamicKeybindAction action = new DynamicKeybindAction("example:read_block_above", data);
 
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Convenience constructor for actions without data payload.
    DynamicKeybindAction(String actionID, net.minecraft.nbt.CompoundTag data)
    Creates a new DynamicKeybindAction with null-safe data.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the actionID record component.
    net.minecraft.nbt.CompoundTag
    Returns the value of the data record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • DynamicKeybindAction

      public DynamicKeybindAction(String actionID)
      Convenience constructor for actions without data payload.
      Parameters:
      actionID - the action identifier
    • DynamicKeybindAction

      public DynamicKeybindAction(String actionID, net.minecraft.nbt.CompoundTag data)
      Creates a new DynamicKeybindAction with null-safe data.
      Parameters:
      actionID - the action identifier
      data - the action data (null values become empty CompoundTag)
  • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • actionID

      public String actionID()
      Returns the value of the actionID record component.
      Returns:
      the value of the actionID record component
    • data

      public net.minecraft.nbt.CompoundTag data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component