From addddec1de092c8de95135a1f6507b0c0f4b341c Mon Sep 17 00:00:00 2001 From: glowredman <35727266+glowredman@users.noreply.github.com> Date: Tue, 30 Jul 2024 21:47:06 +0200 Subject: [PATCH] Wrap in try/catch, use more unique stat keys --- .../mixins/early/fml/MixinGameRegistry.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mitchej123/hodgepodge/mixins/early/fml/MixinGameRegistry.java b/src/main/java/com/mitchej123/hodgepodge/mixins/early/fml/MixinGameRegistry.java index a1908053..2f39c690 100644 --- a/src/main/java/com/mitchej123/hodgepodge/mixins/early/fml/MixinGameRegistry.java +++ b/src/main/java/com/mitchej123/hodgepodge/mixins/early/fml/MixinGameRegistry.java @@ -13,6 +13,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.sugar.Local; +import com.mitchej123.hodgepodge.Common; import cpw.mods.fml.common.registry.GameRegistry; @@ -58,9 +59,20 @@ public class MixinGameRegistry { @Unique private static StatCrafting hodgepodge$createAndRegisterStat(String key, Item item) { + String unlocalizedName; + try { + unlocalizedName = item.getUnlocalizedName(); + } catch (Exception e) { + String registryName = item.delegate.name(); + unlocalizedName = "item." + registryName + ".name"; + Common.log.warn( + "An Exception occured while invoking Item.getUnlocalizedName() after registering the item {} ({})! Using fallback unlocalized name.", + registryName, + item.getClass().getName()); + } StatCrafting stat = new StatCrafting( - key + '.' + item.delegate.name(), - new ChatComponentTranslation(key, new ChatComponentTranslation(item.getUnlocalizedName())), + key + ".autogen." + item.delegate.name(), + new ChatComponentTranslation(key, new ChatComponentTranslation(unlocalizedName)), item); stat.registerStat(); return stat;