[Compatibility] Prevent Crash Caused by Mixins when Opening Key Binds Menu
Closed this issue · 4 comments
BeansGalaxy commented
I'm developing Beans Backpacks and we had an incompatibility when opening the key bind screen.
We both tried to add hover text to not bound key binds by redirecting but someone left a issue on my mod and I found out how to use @Inject to keep our mods compatible and I suggest you do the same. I inject right after this.changeButton.setTooltip(null)
and just use .setTooltip
agian, passing in my custom hover text.
I'm using forge's method naming so I hope nothing literally gets lost in translation but heres my @Inject
so you don't run into similar compat issues.
@Mixin(value = KeyBindsList.KeyEntry.class)
public abstract class KeyBindTooltip {
@Shadow @Final private Button changeButton;
@Shadow @Final private Component name;
@Inject(method = "refreshEntry", at = @At(value = "INVOKE", ordinal = 1, shift = At.Shift.AFTER,
target = "Lnet/minecraft/client/gui/components/Button;setTooltip(Lnet/minecraft/client/gui/components/Tooltip;)V"))
private void changeBackpackKeyHover(CallbackInfo ci) {
if (name.equals(Component.translatable(KeyPress.KEY_BACKPACK_MODIFIER))) {
this.changeButton.setTooltip(Tooltip.create(Component.translatable(KeyPress.KEY_DESCRIPTION)));
}
}
}
KrLite commented
Sure! I will implement this in the upcoming release soon.
BeansGalaxy commented
🙏🙏🙏
owosoup commented
Great work. Thanks for the quick action, I love both of your mods!