Fabric API

Fabric API

106M Downloads

Event for in-game mouse scroll

Technici4n opened this issue ยท 2 comments

commented

This event would fire on the client side and would allow intercepting the mouse scroll that would normally change the focused item to do something else. (E.g. toggle something on sneak + mouse scroll)

commented

I actually have this implemented in my own library, not just for mouse scrolling, but also mouse clicks and key presses when no screen is open. The events are implemented with a before and after callback each, here they are: InputEvents

Additionally the two required mixins are here: MouseHandlerFabricMixin and KeyboardHandlerFabricMixin

The implementation is based on Forge's InputEvent class, but has been cleaned up, since on Forge the events appear rather inconsistent the me (the scroll event fires before vanilla handles scrolling, allowing for vanilla to be cancelled, but the key pressed event fires after vanilla, mouse clicked fires before and after).

Mouse scrolling in vanilla is used for switching between hotbar slots, and for changing the flying speed in spectator mode. Key presses are used mainly for activating debug keys. The additional events for mouse clicks are a bit pointless honestly, since they are simply passed to the key mappings when no screen is open which can be handled elsewhere. I only included them because they are present on Forge.

Depending on what other think of the implementation I'd be happy to make a PR for this, possibly without mouse click events.

commented

Hi @Fuzss thanks for the offer, yes it would be nice to have these events in Fabric (mouse click too). I think they would fit nicely in the keybinding module.

PS: Careful that the classes you linked to contain mojmap names.