Record Class JavaRegistryKey<T>

java.lang.Object
java.lang.Record
org.geysermc.geyser.session.cache.registry.JavaRegistryKey<T>
Type Parameters:
T - the object type this registry holds.
Record Components:
registryKey - the registry key, as it appears on Java.
networkSerializer - a method that converts an object in this registry to its network ID.
networkDeserializer - a method that converts a network ID to an object in this registry.

public record JavaRegistryKey<T>(net.kyori.adventure.key.Key registryKey, @Nullable JavaRegistryKey.NetworkSerializer<T> networkSerializer, @Nullable JavaRegistryKey.NetworkDeserializer<T> networkDeserializer) extends Record
Defines a Java registry, which can be hardcoded or data-driven. This class doesn't store registry contents itself, that is handled by RegistryCache in the case of data-driven registries and other classes in the case of hardcoded registries.

This class is used when, for a Java registry, data-driven objects or tags need to be loaded. Only one instance of this class should be created for each Java registry. Instances of this class are kept in JavaRegistries, which also has useful methods for creating instances of this class. When only using a registry to load data-driven objects, the network (de)serializer parameters can be null. For tag loading however, these are required, as TagCache relies on their functionality.

  • Constructor Details

  • Method Details

    • toNetworkId

      public int toNetworkId(GeyserSession session, T object)
      Converts an object in this registry to its network ID. This will fail if this registry doesn't have a network serializer.
    • fromNetworkId

      public T fromNetworkId(GeyserSession session, int networkId)
      Converts a network ID to an object in this registry. This will fail if this registry doesn't have a network deserializer.
    • shouldStoreTags

      public boolean shouldStoreTags()
      Returns:
      true if this registry has a network serializer and deserializer.
    • 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.
    • registryKey

      public net.kyori.adventure.key.Key registryKey()
      Returns the value of the registryKey record component.
      Returns:
      the value of the registryKey record component
    • networkSerializer

      @Nullable public JavaRegistryKey.NetworkSerializer<T> networkSerializer()
      Returns the value of the networkSerializer record component.
      Returns:
      the value of the networkSerializer record component
    • networkDeserializer

      @Nullable public JavaRegistryKey.NetworkDeserializer<T> networkDeserializer()
      Returns the value of the networkDeserializer record component.
      Returns:
      the value of the networkDeserializer record component