Class Registry<M>

java.lang.Object
org.geysermc.geyser.registry.Registry<M>
Type Parameters:
M - the value being held by the registry
Direct Known Subclasses:
AbstractMappedRegistry, ArrayRegistry, SimpleRegistry

public abstract class Registry<M> extends Object
A wrapper around a value which is loaded based on the output from the provided RegistryLoader. This class is primarily designed to hold a registration of some kind, however no limits are set on what it can hold, as long as the specified RegistryLoader returns the same value type that is specified in the generic.

Below, a RegistryLoader is taken in the constructor. RegistryLoaders have two generic types: the input, and the output. The input is what it takes in, whether it be a string which references to a file, or nothing more than an integer. The output is what it generates based on the input, and should be the same type as the Registry generic specified in the registry.

Registries can be very simple to create. Here is an example that simply parses a number given a string:

 
     public static final SimpleRegistry<Integer> STRING_TO_INT = SimpleRegistry.create("5", Integer::parseInt);
 
 

This is a simple example which really wouldn't have much of a practical use, however it demonstrates a fairly basic use case of how this system works. Typically though, the first parameter would be a location of some sort, such as a file path where the loader will load the mappings from. The NBT registry is a good reference point for something both simple and practical. See Registries.BIOMES_NBT and NbtRegistryLoader.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected M
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Registry​(I input, RegistryLoader<I,​M> registryLoader)
    Creates a new instance of this class with the given input and RegistryLoader.
  • Method Summary

    Modifier and Type
    Method
    Description
    get()
    Gets the underlying value held by this registry.
    void
    register​(Consumer<M> consumer)
    Registers what is specified in the given Consumer into the underlying value.
    void
    set​(M mappings)
    Sets the underlying value held by this registry.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • mappings

      protected M mappings
  • Constructor Details

    • Registry

      protected Registry(I input, RegistryLoader<I,​M> registryLoader)
      Creates a new instance of this class with the given input and RegistryLoader. The input specified is what the registry loader needs to take in.
      Type Parameters:
      I - the input type
      Parameters:
      input - the input
      registryLoader - the registry loader
  • Method Details

    • get

      public M get()
      Gets the underlying value held by this registry.
      Returns:
      the underlying value held by this registry.
    • set

      public void set(M mappings)
      Sets the underlying value held by this registry. Clears any existing data associated with the previous value.
      Parameters:
      mappings - the underlying value held by this registry
    • register

      public void register(Consumer<M> consumer)
      Registers what is specified in the given Consumer into the underlying value.
      Parameters:
      consumer - the consumer