Class Registry<M>
- Type Parameters:
M
- the value being held by the registry
- Direct Known Subclasses:
AbstractMappedRegistry
,ArrayRegistry
,SimpleRegistry
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
-
Constructor Summary
ModifierConstructorDescriptionprotected
Registry(I input, RegistryLoader<I,M> registryLoader)
Creates a new instance of this class with the given input andRegistryLoader
. -
Method Summary
-
Field Details
-
mappings
-
-
Constructor Details
-
Registry
Creates a new instance of this class with the given input andRegistryLoader
. The input specified is what the registry loader needs to take in.- Type Parameters:
I
- the input type- Parameters:
input
- the inputregistryLoader
- the registry loader
-
-
Method Details
-
get
Gets the underlying value held by this registry.- Returns:
- the underlying value held by this registry.
-
set
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
Registers what is specified in the givenConsumer
into the underlying value.- Parameters:
consumer
- the consumer
-