Jump to content

[1.12] Why do setRegistryName calls with differing modids to the active mod container always cause warnings?


Recommended Posts

I've recently been working on a lib mod to make tedious modding tasks less, well, tedious. Among the first features I added was a simple registry system that keeps a list of every item and block I wish to register, posts an event that is received by dependent mods wherein they can add their content to the list, then handles registry of the items/blocks and their respective models in the relevant Forge events.


This works fine, but I've run into a somewhat annoying issue: since I dispatch my RegisterContentEvent from my lib mod, I instantiate my blocks and items while the lib mod is currently the active mod container. So, as I call setRegistryName, the following code from the IForgeRegistry Impl is executed and a big warning is printed:

        public final T setRegistryName(String name)
            if (getRegistryName() != null)
                throw new IllegalStateException("Attempted to set registry name with existing registry name! New: " + name + " Old: " + getRegistryName());

            int index = name.lastIndexOf(':');
            String oldPrefix = index == -1 ? "" : name.substring(0, index);
            name = index == -1 ? name : name.substring(index + 1);
            ModContainer mc = Loader.instance().activeModContainer();
            String prefix = mc == null || (mc instanceof InjectedModContainer && ((InjectedModContainer)mc).wrappedContainer instanceof FMLContainer) ? "minecraft" : mc.getModId().toLowerCase();
            if (!oldPrefix.equals(prefix) && oldPrefix.length() > 0)
                FMLLog.bigWarning("Dangerous alternative prefix `{}` for name `{}`, expected `{}` invalid registry invocation/invalid name?", oldPrefix, name, prefix);
                prefix = oldPrefix;
            this.registryName = new ResourceLocation(prefix, name);
            return (T)this;


I can adapt my setup so that I'm not relying on this event, but I was wondering if I was missing any reasons why this warning was fired. Obviously it's best to keep content from a given mod using the modid of that mod, but in this case content from respective mods will be using the modids of those respective mods -- I'm just trying to avoid having to recode a registry for every mod. And yeah, of course, I can work around this no problem. But for future reference, are there any consequences for registering a registry entry with a modid not matching the currently-active mod container, other than potential confusion and not obeying the standard?


I would personally rather rely on the event than sticking all of my content instantiation in a preinit somewhere, to try and be more in-line with Forge's registry changes, which as I understand are working towards the goal of the potential for mods to be loaded somewhat dynamically. Obviously this isn't the case now, and it wouldn't impact my mods at the moment to rely on the old initialization events, but I feel as if moving forward relying on a freely-postable event will be more of a positive than a negative -- unless, of course, this mismatched modid issue has some dire consequences I'm not aware of.


My apologies if this is the wrong subforum, since it's more of a general Forge clarification question than a direct issue with my code.


Thank you!

Edited by Elucent
Link to comment
Share on other sites

58 minutes ago, Elucent said:

My apologies if this is the wrong subforum, since it's more of a general Forge clarification question than a direct issue with my code.

Right forum and this is done to prevent modders from misstyping their modid when registering something.


I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.