Skip to content

Register copper armor material only once - #108

Closed
Mort3gar wants to merge 1 commit into
Smallinger:mainfrom
Mort3gar:fix/copper-armor-material-duplicate-registration
Closed

Register copper armor material only once#108
Mort3gar wants to merge 1 commit into
Smallinger:mainfrom
Mort3gar:fix/copper-armor-material-duplicate-registration

Conversation

@Mort3gar

Copy link
Copy Markdown

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.

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.
@Mort3gar

Copy link
Copy Markdown
Author

Just saw an existing Pull Request ( #106 ) with the same change.
Closing my PR

@Mort3gar Mort3gar closed this Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant