Skip to content

Commit 4263699

Browse files
committed
docs(bindings): update outdated API references
1 parent 8cc5f99 commit 4263699

1 file changed

Lines changed: 24 additions & 18 deletions

File tree

docs/developers/bindings-api.mdx

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,46 @@ _Learn how to register new controller bindings._
77
## Registering a custom input binding
88

99
<Callout variant="info">
10-
You should register bindings inside of the Controlify init entrypoint. Read more in [Controlify Entrypoint](controlify-entrypoint#using-the-entrypoint).
10+
The custom input bindings must be registered inside the Controlify pre-init entrypoint. Read more in [Controlify Entrypoint](controlify-entrypoint#using-the-entrypoint).
1111
</Callout>
1212

1313
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.
1414

15-
To register a controller binding, you must use the `ControllerBindingsApi.`
15+
To register a controller binding, use the `ControllerBindingsApi.get()` method:
1616

1717
```java
18-
private BindingSupplier action1Binding;
18+
private InputBindingSupplier actionBinding;
1919

2020
@Override
2121
public void onControlifyInit(InitContext ctx) {
22-
action1Binding = ctx.bindings().registerBinding(
22+
final ControlifyBindApi registrar = ControlifyBindApi.get();
23+
registerInputBindings(registrar);
24+
}
25+
26+
private void registerInputBindings(ControlifyBindApi registrar) {
27+
actionBinding = registrar.registerBinding(
2328
builder -> builder
24-
.id("mymod", "action1") // the id of the binding, this should be unique to your mod
25-
.category(Component.translatable("mymod.binding.category")) // the category of the binding, this is used to group bindings together in the settings
26-
.allowedContexts(BindContext.IN_GAME) // a context is where the binding can be used, you can use multiple contexts
27-
.radialCandiate(RadialIcons.getEffect/getIcon(...)) // if you want to allow your binding to be used in the radial menu
29+
.id(ResourceLocation.fromNamespaceAndPath(MyMod.MODID, path))
30+
// The category of the binding, this is used to group bindings together in the settings.
31+
.category(Component.translatable("mymod.binding.category"))
32+
// A context is where the binding can be used. Multiple contexts can be used.
33+
.allowedContexts(BindContext.IN_GAME)
34+
// Allow using the binding in the radial menu.
35+
// You can't use a custom modded item directly in here, since it's not registered yet
36+
// and a runtime error will be thrown. Continue reading for a better alternative.
37+
.radialCandidate(RadialIcons.getItem(Items.BARRIER)))
38+
// Prevents Controlify from auto-registering controller bindings for Epic Fight's
39+
// vanilla key mappings due explicit native support.
40+
// You could also use ".keyEmulation(MyModKeyMappings.ACTION) to emulates
41+
// the vanilla KeyMapping behavior, which may not always work well.
42+
.addKeyCorrelation(MyModKeyMappings.ACTION)
2843
);
2944
}
3045
```
3146

3247
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)`
3348

34-
Registering the binding provides you with a `BindingSupplier`, where you can then access the binding with `action1Binding.on(controller);`
35-
36-
Controlify automatically converts your existed modded `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...
37-
38-
```java
39-
@Override
40-
public void onControlifyInit(InitContext ctx) {
41-
ctx.bindings().exclude(MyMod.myKeyMapping);
42-
}
43-
```
49+
Registering the binding provides you with a `InputBindingSupplier`, where you can then access the binding with `actionBinding.on(controller);`
4450

4551
## Defining a default binding
4652

0 commit comments

Comments
 (0)