Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 84 additions & 18 deletions docs/developers/bindings-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,46 @@ _Learn how to register new controller bindings._
## Registering a custom input binding

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

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.

To register a controller binding, you must use the `ControllerBindingsApi.`
To register a controller binding, use the `ControlifyBindApi.get()` method:

```java
private BindingSupplier action1Binding;
private InputBindingSupplier actionBinding;

@Override
public void onControlifyInit(InitContext ctx) {
action1Binding = ctx.bindings().registerBinding(
final ControlifyBindApi registrar = ControlifyBindApi.get();
registerInputBindings(registrar);
}

private void registerInputBindings(ControlifyBindApi registrar) {
actionBinding = registrar.registerBinding(
builder -> builder
.id("mymod", "action1") // the id of the binding, this should be unique to your mod
.category(Component.translatable("mymod.binding.category")) // the category of the binding, this is used to group bindings together in the settings
.allowedContexts(BindContext.IN_GAME) // a context is where the binding can be used, you can use multiple contexts
.radialCandiate(RadialIcons.getEffect/getIcon(...)) // if you want to allow your binding to be used in the radial menu
.id(ResourceLocation.fromNamespaceAndPath(MyMod.MODID, path))
// The category of the binding, this is used to group bindings together in the settings.
.category(Component.translatable("mymod.binding.category"))
// A context is where the binding can be used. Multiple contexts can be used.
.allowedContexts(BindContext.IN_GAME)
// Allow using the binding in the radial menu.
// You can't use a custom modded item directly in here, since it's not registered yet
// and a runtime error will be thrown. Continue reading for a better alternative.
.radialCandidate(RadialIcons.getItem(Items.BARRIER)))
// Prevents Controlify from auto-registering controller bindings for Epic Fight's
// vanilla key mappings due explicit native support.
// You could also use ".keyEmulation(MyModKeyMappings.ACTION) to emulates
// the vanilla KeyMapping behavior, which may not always work well.
.addKeyCorrelation(MyModKeyMappings.ACTION)
Copy link
Contributor Author

@EchoEllet EchoEllet Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should point out to consumers that they need to either use keyEmulation or addKeyCorrelation. There is no point in using both, since keyEmulation already calls addKeyCorrelation internally.

);
}
```

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.on(controller);`

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

```java
@Override
public void onControlifyInit(InitContext ctx) {
ctx.bindings().exclude(MyMod.myKeyMapping);
}
```
Registering the binding provides you with a `InputBindingSupplier`, where you can then access the binding with `actionBinding.on(controller);`

## Defining a default binding

Expand Down Expand Up @@ -83,3 +89,63 @@ There are more properties available inside of `InputBinding` which you can look
There is nothing special about rendering glyphs for controller bindings, as Controlify utilises custom fonts.

This means you can use the glyphs within localised text, or just render it with `graphics.drawString(myBinding.inputGlyph(), x, y, -1);`

## Registering Custom Radial Icons

When registering a radial menu candidate, you must provide an icon to render it in the GUI.
You can use `RadialIcons.getEffect(...)` or `RadialIcons.getItem(...)` (for example, `RadialIcons.getItem(Items.REDSTONE)`).

However, **do not reference modded items directly** (e.g., `RadialIcons.getItem(ModItems.CUSTOM.get())`),
as item registration is deferred — meaning those items are not yet registered at this stage.

What you can do instead, is to reference the texture image file in the bundled resource-pack of your mod,
using the following approach:

```java
private enum MyRadialIcons {
CUSTOM(MyMod.rl("textures/item/custom.png")),;

private final @NotNull ResourceLocation id;

MyRadialIcons(@NotNull ResourceLocation id) {
this.id = id;
}

public @NotNull ResourceLocation getId() {
return id;
}
}

@Override
public void onControlifyPreInit(PreInitContext context) {
final ControlifyBindApi registrar = ControlifyBindApi.get();
registerCustomRadialIcons();

// Must be called after registerCustomRadialIcons
registerInputBindings(registrar);
}

private void registerCustomRadialIcons() {
for (MyRadialIcons icon : MyRadialIcons.values()) {
final ResourceLocation location = icon.getId();

// For consistency with the current Controlify radial icons,
// this code is equivalent to:
// https://github.com/isXander/Controlify/blob/f5c94c57d5e0d4954e413624a0d7ead937b6e8ab/src/main/java/dev/isxander/controlify/bindings/RadialIcons.java#L106-L112
RadialIcons.registerIcon(location, (graphics, x, y, tickDelta) -> {
var pose = CGuiPose.ofPush(graphics);
pose.translate(x, y);
pose.scale(0.5f, 0.5f);
Blit.tex(graphics, location, 0, 0, 0, 0, 32, 32, 32, 32);
pose.pop();
});
}
}

private void registerInputBindings(ControlifyBindApi registrar) {
actionBinding = registrar.registerBinding(
builder -> builder
.radialCandidate(MyRadialIcons.CUSTOM.getId())
);
}
```
43 changes: 42 additions & 1 deletion docs/developers/controlify-entrypoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,51 @@ _Learn how to hook into Controlify._

Controlify provides a Fabric entrypoint to hook into important lifecycle stages of Controlify. You do this just like `ClientModInitializer`.

## Adding Controlify dependency

In your `build.gradle` (or `build.gradle.kts`), you need to add the maven
repository and the Controlify mod dependency.

<details>
<summary>Maven repository</summary>

```kotlin
repositories {
exclusiveContent {
forRepository { maven { url "https://maven.isxander.dev/releases" } }
filter { includeGroup "dev.isxander" }
}
}
```

</details>

<details>
<summary>Dependency</summary>

Add the version to your `gradle.properties`:

```properties
# You can find the versions in here: https://maven.isxander.dev/#/releases/dev/isxander/controlify
controlify_version=2.4.3+1.21.1-neoforge
```

```kotlin
dependencies {
// You can change "compileOnly" to "implementation" for testing in-game.
compileOnly("dev.isxander:controlify:${project.controlify_version}") {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like compileOnlyMod should be used instead when using Fabric Loom.

// Only need Controlify API, ignore the transitive dependencies (e.g, QuiltMC parsers)
transitive = false
}
}
```

</details>

## Registering the entrypoint

- On Fabric, you register an entrypoint like any other, by adding an entry to your `fabric.mod.json` file under the `entrypoints` section.
- On NeoForge, you register an entrypoint using a Java service provider interface (SPI) in your `META-INF/services` directory.
- On NeoForge, you register an entrypoint using a Java service provider interface (SPI) in **`META-INF/services/dev.isxander.controlify.api.entrypoint.ControlifyEntrypoint`**.

<CodeTabs>
```json !!tabs (Fabric) fabric.mod.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ public interface ControlifyEntrypoint {
* Called once Controlify has initialised some systems but controllers
* have not yet been discovered and constructed. This is the ideal
* time to register events in preparation for controller discovery.
* Input bindings cannot be registered here; use {@link #onControlifyPreInit} instead.
*/
void onControlifyInit(InitContext context);


/**
* Called at the end of Controlify's client-side entrypoint.
* You can register guides here.
* Use this to register guides, input bindings, radial icons, or screen processors,
* and to subscribe to events from {@link dev.isxander.controlify.api.event.ControlifyEvents}.
* Avoid referencing objects that are registered later (e.g. custom mod items),
* as they may not be initialized yet and could cause errors due to deferred registration.
*/
void onControlifyPreInit(PreInitContext context);

Expand Down
Loading