From b117722d8401be6b05669e502c34c61297553987 Mon Sep 17 00:00:00 2001 From: Take Weiland Date: Mon, 22 Jun 2020 09:52:30 +0200 Subject: [PATCH] Throw an exception from DeferredRegister when trying to register entries after registry event has fired (#6789) --- .../java/net/minecraftforge/registries/DeferredRegister.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/net/minecraftforge/registries/DeferredRegister.java b/src/main/java/net/minecraftforge/registries/DeferredRegister.java index 277720470..c3ad63414 100644 --- a/src/main/java/net/minecraftforge/registries/DeferredRegister.java +++ b/src/main/java/net/minecraftforge/registries/DeferredRegister.java @@ -82,6 +82,7 @@ public class DeferredRegister> private IForgeRegistry type; private Supplier> registryFactory; + private boolean seenRegisterEvent = false; private DeferredRegister(Class base, String modid) { @@ -106,6 +107,8 @@ public class DeferredRegister> @SuppressWarnings("unchecked") public RegistryObject register(final String name, final Supplier 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> { if (this.type != null && event.getGenericType() == this.type.getRegistrySuperType()) { + this.seenRegisterEvent = true; @SuppressWarnings("unchecked") IForgeRegistry reg = (IForgeRegistry)event.getRegistry(); for (Entry, Supplier> e : entries.entrySet())