Register copper armor material only once - #108
Closed
Mort3gar wants to merge 1 commit into
Closed
Conversation
CopperArmorMaterial.COPPER was a plain, non-memoized Supplier whose body calls
createCopper(), and createCopper() registers into BuiltInRegistries.ARMOR_MATERIAL
via Registry.registerForHolder. ModItems calls COPPER.get() five times (helmet,
chestplate, leggings, boots, horse armor), so the second call re-registers
minecraft:copper and throws:
java.lang.IllegalStateException: Adding duplicate key
'ResourceKey[minecraft:armor_material / minecraft:copper]' to registry
at CopperArmorMaterial.createCopper(CopperArmorMaterial.java:56)
at CopperArmorMaterial.lambda$init$2(CopperArmorMaterial.java:63)
at ModItems.lambda$register$75(ModItems.java:411)
On NeoForge this aborts the item RegisterEvent, so every mod dispatched after
copperagebackport fails to register its items. The result is a broken mod state
that takes down unrelated mods and crashes the client during startup.
Cache the holder so the registration happens exactly once. All callers run on the
registration thread, so no synchronization is needed.
Author
|
Just saw an existing Pull Request ( #106 ) with the same change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CopperArmorMaterial.COPPER was a plain, non-memoized Supplier whose body calls createCopper(), and createCopper() registers into BuiltInRegistries.ARMOR_MATERIAL via Registry.registerForHolder. ModItems calls COPPER.get() five times (helmet, chestplate, leggings, boots, horse armor), so the second call re-registers minecraft:copper and throws:
java.lang.IllegalStateException: Adding duplicate key
'ResourceKey[minecraft:armor_material / minecraft:copper]' to registry
at CopperArmorMaterial.createCopper(CopperArmorMaterial.java:56)
at CopperArmorMaterial.lambda$init$2(CopperArmorMaterial.java:63)
at ModItems.lambda$register$75(ModItems.java:411)
On NeoForge this aborts the item RegisterEvent, so every mod dispatched after copperagebackport fails to register its items. The result is a broken mod state that takes down unrelated mods and crashes the client during startup.
Cache the holder so the registration happens exactly once. All callers run on the registration thread, so no synchronization is needed.