Bindings API
Learn how to register new controller bindings.
Bind Registry
You should register bindings inside of the Controlify pre-init entrypoint. Read more in Controlify Entrypoint.
Controlify allows users to configure different buttons on their controllers to actions in-game. You may want your own mod's actions to be able to be invoked from the controller too, or you may want your KeyMapping
to be able to used on a controller.
To register a controller binding, you must use the ControllerBindingsApi.
To add a name and description to the binding, you need to define the language keys controlify.binding.<namespace>.<path>
and controlify.binding.<namespace>.<path>.desc
respectively, alternatively, you can set .name(Component)
and .description(Component)
Registering the binding provides you with a BindingSupplier
, where you can then access the binding with action1Binding.onController(controller);
Controlify automatically converts KeyMapping
s to controller bindings, but relying on this behaviour if you are going to explicitly support Controlify is not recommended. You can stop this conversion with the following...
Using the binding
Once you have access to a binding through bindingSuppler.onController(controller)
, you can access many properties of the binding:
state()
Gets a float value between 0 - 1 which describes its analogue state.
justPressed()
Returns if the binding was pressed this tick, if it returns true, the state is consumed and will return false for the remaining tick.
justReleased()
Returns if the binding was just released this tick, if it returns true, the state is consumed and will return false for the remaining tick.
held()
Returns true if the binding is down this tick.
generateYACLOption()
Creates a YetAnotherConfigLib option that you can add to your own YACL GUIs.
There are more properties available inside of ControllerBinding
which you can look at in the sources, but the above are the most notable that you will use the most.
Rendering bindings
If you want to render a specific bind's icon, you can get ControllerBinding#renderer()
, BindingRenderer
provides two methods, size()
and render(PoseStack, int, int)
.
Last updated