Skip to content

Commit 8e0e979

Browse files
committed
docs(bindings): document how to register a custom radial icons
1 parent d51805e commit 8e0e979

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

docs/developers/bindings-api.mdx

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ _Learn how to register new controller bindings._
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, use the `ControllerBindingsApi.get()` method:
15+
To register a controller binding, use the `ControlifyBindApi.get()` method:
1616

1717
```java
1818
private InputBindingSupplier actionBinding;
@@ -89,3 +89,63 @@ There are more properties available inside of `InputBinding` which you can look
8989
There is nothing special about rendering glyphs for controller bindings, as Controlify utilises custom fonts.
9090

9191
This means you can use the glyphs within localised text, or just render it with `graphics.drawString(myBinding.inputGlyph(), x, y, -1);`
92+
93+
## Registering Custom Radial Icons
94+
95+
When registering a radial menu candidate, you must provide an icon to render it in the GUI.
96+
You can use `RadialIcons.getEffect(...)` or `RadialIcons.getItem(...)` (for example, `RadialIcons.getItem(Items.REDSTONE)`).
97+
98+
However, **do not reference modded items directly** (e.g., `RadialIcons.getItem(ModItems.CUSTOM.get())`),
99+
as item registration is deferred — meaning those items are not yet registered at this stage.
100+
101+
What you can do instead, is to reference the texture image file in the bundled resource-pack of your mod,
102+
using the following approach:
103+
104+
```java
105+
private enum MyRadialIcons {
106+
CUSTOM(MyMod.rl("textures/item/custom.png")),;
107+
108+
private final @NotNull ResourceLocation id;
109+
110+
MyRadialIcons(@NotNull ResourceLocation id) {
111+
this.id = id;
112+
}
113+
114+
public @NotNull ResourceLocation getId() {
115+
return id;
116+
}
117+
}
118+
119+
@Override
120+
public void onControlifyPreInit(PreInitContext context) {
121+
final ControlifyBindApi registrar = ControlifyBindApi.get();
122+
registerCustomRadialIcons();
123+
124+
// Must be called after registerCustomRadialIcons
125+
registerInputBindings(registrar);
126+
}
127+
128+
private void registerCustomRadialIcons() {
129+
for (MyRadialIcons icon : MyRadialIcons.values()) {
130+
final ResourceLocation location = icon.getId();
131+
132+
// For consistency with the current Controlify radial icons,
133+
// this code is equivalent to:
134+
// https://github.com/isXander/Controlify/blob/f5c94c57d5e0d4954e413624a0d7ead937b6e8ab/src/main/java/dev/isxander/controlify/bindings/RadialIcons.java#L106-L112
135+
RadialIcons.registerIcon(location, (graphics, x, y, tickDelta) -> {
136+
var pose = CGuiPose.ofPush(graphics);
137+
pose.translate(x, y);
138+
pose.scale(0.5f, 0.5f);
139+
Blit.tex(graphics, location, 0, 0, 0, 0, 32, 32, 32, 32);
140+
pose.pop();
141+
});
142+
}
143+
}
144+
145+
private void registerInputBindings(ControlifyBindApi registrar) {
146+
actionBinding = registrar.registerBinding(
147+
builder -> builder
148+
.radialCandidate(MyRadialIcons.CUSTOM.getId())
149+
);
150+
}
151+
```

0 commit comments

Comments
 (0)