M - the value being held by the registrypublic abstract class Registry<M> extends Object
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 M 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.
| Modifier | Constructor and Description |
|---|---|
protected |
Registry(I input,
RegistryLoader<I,M> registryLoader)
Creates a new instance of this class with the given input and
RegistryLoader. |
| Modifier and Type | Method and Description |
|---|---|
M |
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. |
protected final M mappings
protected Registry(I input,
RegistryLoader<I,M> registryLoader)
RegistryLoader. The input specified is what the registry
loader needs to take in.I - the input typeinput - the inputregistryLoader - the registry loaderCopyright © 2021 GeyserMC. All rights reserved.