mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Allow deferred registries to be loaded/set more than once (#3892)
This commit is contained in:
parent
bed7b5d10e
commit
2368b63ad5
1 changed files with 12 additions and 8 deletions
|
@ -69,6 +69,12 @@ public final class DeferredRegistry<M> implements IRegistry<M> {
|
||||||
this.loader = () -> deferredLoader.get().load(input);
|
this.loader = () -> deferredLoader.get().load(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the underlying value held by this registry.
|
||||||
|
*
|
||||||
|
* @return the underlying value held by this registry
|
||||||
|
* @throws IllegalStateException if this deferred registry has not been loaded yet
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public M get() {
|
public M get() {
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
|
@ -80,13 +86,15 @@ public final class DeferredRegistry<M> implements IRegistry<M> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void set(M mappings) {
|
public void set(M mappings) {
|
||||||
if (!this.loaded) {
|
|
||||||
throw new IllegalStateException("Registry has not been loaded yet!");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.backingRegistry.set(mappings);
|
this.backingRegistry.set(mappings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers what is specified in the given {@link Consumer} into the underlying value.
|
||||||
|
*
|
||||||
|
* @param consumer the consumer
|
||||||
|
* @throws IllegalStateException if this deferred registry has not been loaded yet
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void register(Consumer<M> consumer) {
|
public void register(Consumer<M> consumer) {
|
||||||
if (!this.loaded) {
|
if (!this.loaded) {
|
||||||
|
@ -100,10 +108,6 @@ public final class DeferredRegistry<M> implements IRegistry<M> {
|
||||||
* Loads the registry.
|
* Loads the registry.
|
||||||
*/
|
*/
|
||||||
public void load() {
|
public void load() {
|
||||||
if (this.loaded) {
|
|
||||||
throw new IllegalStateException("Registry has already been loaded!");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.backingRegistry.set(this.loader.get());
|
this.backingRegistry.set(this.loader.get());
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue