You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/developers/bindings-api.mdx
+29-13Lines changed: 29 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,18 +7,20 @@ _Learn how to register new controller bindings._
7
7
## Registering a custom input binding
8
8
9
9
<Calloutvariant="info">
10
-
You should register bindings inside of the Controlify init entrypoint. Read more in [Controlify Entrypoint](controlify-entrypoint#using-the-entrypoint).
10
+
You should register bindings inside of the Controlify init entrypoint.
11
+
Read more in [Controlify Entrypoint](controlify-entrypoint#using-the-entrypoint).
11
12
</Callout>
12
13
13
-
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.
14
+
Controlify allows users to configure different buttons on their controllers to actions in-game.
15
+
You may want your own mod's actions to be able to be invoked from the controller too.
14
16
15
17
To register a controller binding, you must use the `ControllerBindingsApi.`
.id("mymod", "action1") // the id of the binding, this should be unique to your mod
@@ -29,24 +31,32 @@ public void onControlifyInit(InitContext ctx) {
29
31
}
30
32
```
31
33
32
-
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)`
34
+
To add a name and description to the binding, you need to define the language keys
35
+
`controlify.binding.<namespace>.<path>` and `controlify.binding.<namespace>.<path>.desc`
36
+
respectively, alternatively, you can set `.name(Component)` and `.description(Component)`.
33
37
34
-
Registering the binding provides you with a `BindingSupplier`, where you can then access the binding with `action1Binding.on(controller);`
38
+
Registering the binding provides you with a `BindingSupplier`, where you can then access the
39
+
binding with `action1Binding.on(controller);`
35
40
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...
41
+
Controlify automatically converts your existed modded `KeyMapping`s to controller bindings,
42
+
but relying on this behaviour if you are going to explicitly support Controlify is not recommended.
43
+
You can stop this conversion with the following...
You may have noticed that in the above code, we did not define a default binding, such as the A button. This is because default bindings are data-driven and defined by resource packs. If you want to define a default binding, you can do so by creating a JSON file in your mod's resources.
54
+
You may have noticed that in the above code, we did not define a default binding, such as the A button.
55
+
This is because default bindings are data-driven and defined by resource packs.
56
+
If you want to define a default binding, you can do so by creating a JSON file in your mod's resources.
48
57
49
-
```json
58
+
<CodeTabs>
59
+
```json !!tabs (Default for all controllers) assets/controlify/controllers/default_bind/default.json
50
60
{
51
61
"defaults": {
52
62
"mymod:action1": {
@@ -55,14 +65,18 @@ You may have noticed that in the above code, we did not define a default binding
55
65
}
56
66
}
57
67
```
68
+
</CodeTabs>
58
69
59
-
This will set the default binding for `mymod:action1` to the south face button on all controllers. You can also define defaults for specific controller namespaces by creating a file in `assets/<namespace>/controllers/default_bind/<path>.json`.
70
+
This will set the default binding for `mymod:action1` to the south face button on all controllers.
71
+
You can also define defaults for specific controller namespaces by creating a file in
@@ -76,10 +90,12 @@ Once you have access to a binding through `bindingSupplier.on(controller)`, you
76
90
|`justTapped()`| Returns if the binding was just tapped this tick, if it returns true, the state is consumed and will return false for the remaining tick. |
77
91
|`guiPressed().get()`| Returns true if the binding is pressed this tick in the GUI context. |
78
92
79
-
There are more properties available inside of `InputBinding` which you can look at in the sources, but the above are the most notable that you will use the most.
93
+
There are more properties available inside of `InputBinding` which you can look at in the sources,
94
+
but the above are the most notable that you will use the most.
80
95
81
96
## Rendering binding glyphs
82
97
83
98
There is nothing special about rendering glyphs for controller bindings, as Controlify utilises custom fonts.
84
99
85
-
This means you can use the glyphs within localised text, or just render it with `graphics.drawString(myBinding.inputGlyph(), x, y, -1);`
100
+
This means you can use the glyphs within localised text, or just render it with
101
+
`graphics.drawString(myBinding.inputGlyph(), x, y, -1);`
0 commit comments