Architectury API (Fabric/Forge/NeoForge)

Architectury API (Fabric/Forge/NeoForge)

158M Downloads

DeferredRegister fails with custom registries from other mods on Forge

object-Object opened this issue ยท 2 comments

commented

Description

When using DeferredRegister to register content in a custom registry added by another mod, initializing the register (eg. ACTIONS.register()) fails on Forge with the following error message (full crash report below). The same code works fine on Fabric.

java.lang.IllegalArgumentException: Registry ResourceKey[minecraft:root / hexcasting:action] does not exist!

This particular error message is for registering a value to Hex Casting's action registry. I ran the mod with a debugger, and it seems like my mod's initializer, where ACTIONS.register() is called, runs before Hex Casting's initializer, where the custom registry is added to BuiltInRegistries.REGISTRY. So, when Architectury attempts to look up the registry in ACTIONS.register(), the custom registry hasn't been added yet.

I was able to work around the issue by calling ACTIONS.register() in NewRegistryEvent, which fires after mod initialization but before RegisterEvent (docs). However, I'm not sure this is actually a good idea in general - I think it might fail if the mod adding the registry created it in NewRegistryEvent.

I guess a potential fix could be to defer actually looking up the registry until the corresponding RegisterEvent has been received?

Possibly related: #256

Example repo

I set up a minimal example based on the 1.20.1 Fabric/Forge Architectury template, attempting to register a value to Hex Casting's action registry.

Repository: object-Object/architectury-modded-registry-example (see also the workaround tag)

Relevant files:

Logs

These logs are from running the forge:runClient Gradle task in the above repo, on the failing and workaround tags respectively.

Versions

  • Minecraft: 1.20.1
  • Forge: 47.2.1
  • Architectury:
    • API: 9.1.12
    • Plugin: 3.4.155
    • Loom: 1.5.391
commented

Update: I was also able to work around the issue by calling ACTIONS.register() in the appropriate RegisterEvent, but it's a bit annoying to implement since DeferredRegister.key doesn't seem to be publicly accessible.

object-Object/architectury-modded-registry-example@4b117e5

Actually, this doesn't seem to be working - the game runs without crashing, but the custom action isn't actually registered. Not sure why.

commented

I also got this in 1.20.1 on fabric just now. working around by injecting my registration into the mod I am making a addon for