Throw an exception from DeferredRegister when trying to register entries after registry event has fired (#6789)

This commit is contained in:
Take Weiland 2020-06-22 09:52:30 +02:00 committed by cpw
parent 2acf2110ef
commit b117722d84
No known key found for this signature in database
GPG key ID: 8EB3DF749553B1B7

View file

@ -82,6 +82,7 @@ public class DeferredRegister<T extends IForgeRegistryEntry<T>>
private IForgeRegistry<T> type;
private Supplier<RegistryBuilder<T>> registryFactory;
private boolean seenRegisterEvent = false;
private DeferredRegister(Class<T> base, String modid)
{
@ -106,6 +107,8 @@ public class DeferredRegister<T extends IForgeRegistryEntry<T>>
@SuppressWarnings("unchecked")
public <I extends T> RegistryObject<I> register(final String name, final Supplier<? extends I> sup)
{
if (seenRegisterEvent)
throw new IllegalStateException("Cannot register new entries to DeferredRegister after RegistryEvent.Register has been fired.");
Objects.requireNonNull(name);
Objects.requireNonNull(sup);
final ResourceLocation key = new ResourceLocation(modid, name);
@ -173,6 +176,7 @@ public class DeferredRegister<T extends IForgeRegistryEntry<T>>
{
if (this.type != null && event.getGenericType() == this.type.getRegistrySuperType())
{
this.seenRegisterEvent = true;
@SuppressWarnings("unchecked")
IForgeRegistry<T> reg = (IForgeRegistry<T>)event.getRegistry();
for (Entry<RegistryObject<T>, Supplier<? extends T>> e : entries.entrySet())