Darkhax-Minecraft / Enchantment-Descriptions

Displays descriptions about an enchantment on the tooltip.
92 stars 45 forks source link

[BUG] Error key binding prompt display #235

Closed Giant-Salted-Fish closed 2 months ago

Giant-Salted-Fish commented 2 months ago

Minecraft Version

1.16.5

Mod Version

7.1.25

Mod Loader

Forge

What environment are you running the mod in?

Client

Issue Description

Someone has reported a key prompt display issue when using this mod with my Key Binding Patch mod. Original issue is here: https://github.com/Giant-Salted-Fish/Key-Binding-Patch/issues/6.

I have reviewed the code of this mod and the cause is here:

https://github.com/Darkhax-Minecraft/Enchantment-Descriptions/blob/25f4deaf94b4f17a0cc040ac066a7dcc0068fbfc/src/main/java/net/darkhax/enchdesc/EnchantmentDescriptionsClient.java#L80

Although it is called KeyBinding#getTranslationKey() in mcp mapping, it is actually called KeyBinding#saveString() in official mapping. And this method is not suitable to retrieve localized key display name because it only returns the key code of the key binding without the modifiers.

Appropriate method to use here is KeyBinding#func_238171_j_(), which has corresponding name KeyBinding#getTranslatedKeyMessage() in official mapping. It returns a ITextComponent instance that contains the right localized display string of the binding key. It is also the method that being used in the ControlsScreen to display the key of the key binding.

Hence replace I18n.format(this.keybind.getTranslationKey()) with this.keybind.func_238171_j_().getString() should be able to fix this issue.

Darkhax commented 2 months ago

Thank you for looking into this issue and providing detailed info on what to fix. I've verified the issue has been fixed and have uploaded a new version. It's fixed in 7.1.27

Giant-Salted-Fish commented 2 months ago

Thank you!