| 37 | import java.util.stream.Stream; |
| 38 | |
| 39 | public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> implements Supplier<T> |
| 40 | { |
| 41 | private final ResourceLocation name; |
| 42 | @Nullable |
| 43 | private T value; |
| 44 | |
| 45 | public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final ResourceLocation name, Supplier<Class<? super T>> registryType) { |
| 46 | return new RegistryObject<>(name, registryType); |
| 47 | } |
| 48 | |
| 49 | public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final ResourceLocation name, IForgeRegistry<T> registry) { |
| 50 | return new RegistryObject<>(name, registry); |
| 51 | } |
| 52 | |
| 53 | public static <T extends IForgeRegistryEntry<T>, U extends T> RegistryObject<U> of(final ResourceLocation name, final Class<T> baseType, String modid) { |
| 54 | return new RegistryObject<>(name, baseType, modid); |
| 55 | } |
| 56 | |
| 57 | private static RegistryObject<?> EMPTY = new RegistryObject<>(); |
| 58 | |
| 59 | private static <T extends IForgeRegistryEntry<? super T>> RegistryObject<T> empty() { |
| 60 | @SuppressWarnings("unchecked") |
| 61 | RegistryObject<T> t = (RegistryObject<T>) EMPTY; |
| 62 | return t; |
| 63 | } |
| 64 | |
| 65 | private RegistryObject() { |
| 66 | this.name = null; |
| 67 | } |
| 68 | |
| 69 | private <V extends IForgeRegistryEntry<V>> RegistryObject(ResourceLocation name, Supplier<Class<? super V>> registryType) |
| 70 | { |
| 71 | this(name, RegistryManager.ACTIVE.<V>getRegistry(registryType.get())); |
| 72 | } |
| 73 | |
| 74 | @SuppressWarnings("unchecked") |
| 75 | private <V extends IForgeRegistryEntry<V>> RegistryObject(ResourceLocation name, IForgeRegistry<V> registry) |
| 76 | { |
| 77 | if (registry == null) |
| 78 | throw new IllegalArgumentException("Invalid registry argument, must not be null"); |
| 79 | this.name = name; |
| 80 | ObjectHolderRegistry.addHandler(pred -> |
| 81 | { |
| 82 | if (pred.test(registry.getRegistryName())) |
| 83 | this.value = registry.containsKey(this.name) ? (T)registry.getValue(this.name) : null; |
| 84 | }); |
| 85 | } |
| 86 | |
| 87 | @SuppressWarnings("unchecked") |
| 88 | private <V extends IForgeRegistryEntry<V>> RegistryObject(final ResourceLocation name, final Class<V> baseType, final String modid) |
| 89 | { |
| 90 | this.name = name; |
| 91 | final Throwable callerStack = new Throwable("Calling Site from mod: " + modid); |
| 92 | ObjectHolderRegistry.addHandler(new Consumer<Predicate<ResourceLocation>>() |
| 93 | { |
| 94 | private IForgeRegistry<V> registry; |
| 95 | |
| 96 | @Override |
nothing calls this directly
no outgoing calls
no test coverage detected