[Compatibility] Prevent Crash Caused by Mixins when Opening Key Binds Menu
BeansGalaxy opened this issue ยท 4 comments
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)));
}
}
}
The @Redirect
has been changed to @Inject
in 3.2.1
, and it should work now.