Class DataComponent<T>

java.lang.Object
com.github.darksoulq.abyssallib.world.item.component.DataComponent<T>
Type Parameters:
T - The type of the value stored within this component.

public abstract class DataComponent<T> extends Object
An abstract base class representing a single piece of metadata attached to an item or block.

DataComponents are used to store structured, type-safe information (such as names, custom markers, or durability).

  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new DataComponent with the specified value.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Compares this component against another object for equality.
    abstract DataComponentType<?>
    Retrieves the specific type definition associated with this component instance.
    Gets the current value stored in this component.
    int
    Returns a hash code value for the component.
    Returns a string representation of the DataComponent.

    Methods inherited from class Object

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

    • DataComponent

      public DataComponent(T value)
      Constructs a new DataComponent with the specified value.
      Parameters:
      value - The initial value to be stored in this component.
  • Method Details

    • getType

      public abstract DataComponentType<?> getType()
      Retrieves the specific type definition associated with this component instance.

      This is used by the registry and serialization systems to identify how to handle the component's data.

      Returns:
      The DataComponentType representing this component's category.
    • getValue

      public T getValue()
      Gets the current value stored in this component.
      Returns:
      The value of type T.
    • equals

      public boolean equals(Object obj)
      Compares this component against another object for equality.

      Two components are considered equal if they share the exact same type and their internal values are logically equivalent.

      Overrides:
      equals in class Object
      Parameters:
      obj - The reference object with which to compare.
      Returns:
      true if this object is the same as the obj argument; false otherwise.
    • hashCode

      public int hashCode()
      Returns a hash code value for the component.
      Overrides:
      hashCode in class Object
      Returns:
      A hash code value derived from the type and the internal value.
    • toString

      public String toString()
      Returns a string representation of the DataComponent.

      This method attempts to resolve the component's unique identifier from Registries.DATA_COMPONENT_TYPES. If not found, it falls back to the simple name of the type class.

      Overrides:
      toString in class Object
      Returns:
      A formatted string containing the component ID and its value.