diff --git a/src/main/java/net/minecraftforge/registries/DeferredRegister.java b/src/main/java/net/minecraftforge/registries/DeferredRegister.java index 7a979a3c36..5e76cba081 100644 --- a/src/main/java/net/minecraftforge/registries/DeferredRegister.java +++ b/src/main/java/net/minecraftforge/registries/DeferredRegister.java @@ -43,8 +43,8 @@ import com.google.common.reflect.TypeToken; * *Example Usage: *
- * private static final DeferredRegister- ITEMS = new DeferredRegister<>(ForgeRegistries.ITEMS, MODID); - * private static final DeferredRegister
BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, MODID); + * private static final DeferredRegister - ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); + * private static final DeferredRegister
BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); * * public static final RegistryObject ROCK_BLOCK = BLOCKS.register("rock", () -> new Block(Block.Properties.create(Material.ROCK))); * public static final RegistryObject - ROCK_ITEM = ITEMS.register("rock", () -> new BlockItem(ROCK_BLOCK.get(), new Item.Properties().group(ItemGroup.MISC))); @@ -155,11 +155,8 @@ public class DeferredRegister
> public void register(IEventBus bus) { bus.addListener(this::addEntries); - if (this.type == null) { - if (this.registryFactory != null) - bus.addListener(this::createRegistry); - else - bus.addListener(EventPriority.LOWEST, this::captureRegistry); + if (this.type == null && this.registryFactory != null) { + bus.addListener(this::createRegistry); } } @@ -173,6 +170,14 @@ public class DeferredRegister > private void addEntries(RegistryEvent.Register> event) { + if (this.type == null && this.registryFactory == null) + { + //If there is no type yet and we don't have a registry factory, attempt to capture the registry + //Note: This will only ever get run on the first registry event, as after that time, + // the type will no longer be null. This is needed here rather than during the NewRegistry event + // to ensure that mods can properly use deferred registers for custom registries added by other mods + captureRegistry(); + } if (this.type != null && event.getGenericType() == this.type.getRegistrySuperType()) { this.seenRegisterEvent = true; @@ -191,7 +196,7 @@ public class DeferredRegister > this.type = this.registryFactory.get().create(); } - private void captureRegistry(RegistryEvent.NewRegistry event) + private void captureRegistry() { if (this.superType != null) {