-
Notifications
You must be signed in to change notification settings - Fork 95
/
SynchronizedDeferredRegister.java
42 lines (35 loc) · 1.55 KB
/
SynchronizedDeferredRegister.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package slimeknights.mantle.registration.deferred;
import lombok.RequiredArgsConstructor;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraftforge.registries.RegistryObject;
import java.util.function.Supplier;
/** Deferred register instance that synchronizes register calls */
@RequiredArgsConstructor(staticName = "create")
public class SynchronizedDeferredRegister<T> {
private final DeferredRegister<T> internal;
/** Creates a new instance for the given resource key */
public static <T> SynchronizedDeferredRegister<T> create(ResourceKey<? extends Registry<T>> key, String modid) {
return create(DeferredRegister.create(key, modid));
}
/** Creates a new instance for the given forge registry */
public static <B extends IForgeRegistryEntry<B>> SynchronizedDeferredRegister<B> create(IForgeRegistry<B> registry, String modid) {
return create(DeferredRegister.create(registry, modid));
}
/** Registers the given object, synchronized over the internal register */
public <I extends T> RegistryObject<I> register(final String name, final Supplier<? extends I> sup) {
synchronized (internal) {
return internal.register(name, sup);
}
}
/**
* Registers the internal register with the event bus
*/
public void register(IEventBus bus) {
internal.register(bus);
}
}