Missing blocks on client side lead to NullPointerException while connecting
Minecraft Version: 1.21.1
NeoForge Version: at least 21.1.206 <-> 21.1.215, possibly until HEAD of 1.21.x branch (code has not changed from what i found)
Error:
java.lang.NullPointerException: null
at MC-BOOTSTRAP/[email protected]/com.google.common.collect.Iterators$6.transform(Iterators.java:829) ~[guava-32.1.2-jre.jar%23117!/:?] {}
at MC-BOOTSTRAP/[email protected]/com.google.common.collect.TransformedIterator.next(TransformedIterator.java:52) ~[guava-32.1.2-jre.jar%23117!/:?] {}
at TRANSFORMER/[email protected]/net.neoforged.neoforge.registries.NeoForgeRegistryCallbacks$BlockCallbacks.onBake(NeoForgeRegistryCallbacks.java:61) ~[neoforge-21.1.215.jar%23295!/:?] {re:mixin,re:classloading,pl:mixin:APP:modernfix-neoforge.mixins.json:perf.reduce_blockstate_cache_rebuilds.BlockCallbacksMixin from mod modernfix,pl:mixin:A}
at TRANSFORMER/[email protected]/net.minecraft.core.MappedRegistry.lambda$freeze$7(MappedRegistry.java:376) ~[neoforge-21.1.215.jar%23294!/:?]
(...)
Steps to Reproduce:
- Have a mod that adds blocks on the server side, but don't add mod to client side
- Try to connect
- The connection will be closed due to a
NullPointerException
Description of issue:
In MappedRegistry.java is a comment 'Don't use byId() method, it will return the default value if the entry is absent'
However, the default iterator() method in MappedRegistry uses exactly that list.
Then when the onbake callback for blocks tries to through the registry, Iterators.transform(...) tries to call Holder::value on null, and throws this exception.
A few things could be done to solve this;
- Refuse to freeze (or bake) a registry with missing keys
- Change iterator to use the
toKey.keyset().iterator()instead - Use a non-null default value (Blocks.AIR maybe?)
I ran into this when trying to test my own mods interaction with others' on a development server, hopefully my few hours of debugging weren’t for nothing :)
I feel like using a default value will just break down the line, so IMO a better error message is the best fix (unless I just missed this being added as an intentional feature)
Is there a specific reason you needed to connect despite the missing registry entries, or is this a case of a user being unaware that the mod was missing and getting an unhelpful error?
The latter, without the user knowing there is a mod mismatch you get the above error, blocking any useful error messages.