Potential CME due to statically registering gamerules in main mod class
ChiefArug opened this issue ยท 1 comments
Issue description
In your main mod class you register some gamerules:
This calls GameRules#register, which adds entries to a non threadsafe map and thus could cause a Concurrent Modification Exception if another mod does the same thing at the same time (which is possible due to mods being constructed concurrently).
The easy fix for this is to wrap your gamerules in memoized suppliers and call get() on them for the first time in an enqueued runnable in the common setup event:
public static final Supplier<GameRules.Key<GameRules.BooleanValue>> RULE_FAKE_WATER_SOURCE_CONVERSION = Suppliers.memoized(() -> GameRules.register("fakeWaterSourceConversion", GameRules.Category.UPDATES, GameRules.BooleanValue.create(true)));You could also separate the gamerules into their own class and initialize them later, making sure to do it on the main thread (ie in an enqueued runnable in the common setup event).
Steps to reproduce
These issues are very hard to reproduce
Minecraft version
1.21.3
Forge/NeoForge version
N/A
SecurityCraft version
v1.9.12-beta1
Other relevant versions
No response
If a (crash)log is relevant for this issue, link it here: (It's almost always relevant)
N/A