CFXControl Flex Wiki
English中文

接口速查

com.ifels.controlflex.api 的全部公开类型:入口、插件接口、四个 provider、状态注册表、叠层与相机接管、资源安装器。每节都给出签名与调用约束,代码片段可以直接抄。

本节: 概览 · 接入与生命周期 · 接口速查 · 官方实现 · 谁在用这套 API

类型总览

包名 com.ifels.controlflex.api,共 13 个公开类型。除 IPlayerStateRegistry.setState() 外,全部要求在客户端主线程调用。

类型 用途
ControlFlexApi静态入口:可用性检查 + 取各个 provider
IControlFlexPluginSPI 插件接口(生命周期回调)
ICompatAssetInstaller资源安装器(只在对应回调里可用)
IActionStateProvider查询动作当前是否激活
IInputProvider手柄连接状态与硬件视图
IControllerState摇杆 / 扳机 / 按键的实时视图
IControllerCapabilities硬件能力(型号、背键、陀螺仪、震动)
ButtonName按键与轴的名字常量
IPlayerStateRegistry推送 modId:state 状态给 JSON 消费
IInteractiveContextRegistrar声明交互式叠层的前台 / 后台
ICameraLookConsumer接管每帧视角增量(相机被模组接管的场景)
ControllerType · InputMode手柄型号 / 当前输入模式枚举

0.9.0 起移除了输入注入:IInputInjector 与 getInputInjector() 已删除,需要合成手柄输入的测试工具请留在 0.8.x。

ControlFlexApi(静态入口)

boolean isAvailable()               // installed and fully initialized
boolean isControllerConnected()     // a controller is connected

// Providers (null when unavailable)
IActionStateProvider getActionStateProvider()
IInputProvider getInputProvider()
IPlayerStateRegistry getPlayerStateRegistry()
IInteractiveContextRegistrar getInteractiveContextRegistrar()

String getApiVersion()              // e.g. "0.9.2"
void reloadGuides()                 // reload guide configs from disk

IActionStateProvider

boolean isGameActionActive(String actionId)   // game layer (no screen open)
boolean isGuiActionActive(String actionId)    // GUI layer
Set<String> getActiveGameActions()             // live view: never cache across ticks
Set<String> getActiveGuiActions()              // live view: never cache across ticks

动作 ID 三种写法:

IInputProvider · IControllerState · ICapabilities

// IInputProvider
boolean isConnected()
IControllerState getControllerState()          // null when disconnected
IControllerCapabilities getCapabilities()      // null when disconnected
String getGamepadName()                        // null when disconnected
int getGamepadIndex()                          // -1 when disconnected

// IControllerState — live view; sticks -1..1, triggers 0..1, +Y points down
float getLeftStickX()  / getLeftStickY()
float getRightStickX() / getRightStickY()
float getLeftTrigger() / getRightTrigger()
boolean isButtonAPressed() ... isDpadUpPressed() ...
boolean isButtonPressed(String buttonName)     // prefer ButtonName constants
float getAxisValue(String axisName)
boolean isShiftLayerActive()

// IControllerCapabilities
ControllerType getControllerType()   // XBOX / PLAYSTATION / NINTENDO_SWITCH / ...
boolean hasPaddles() / int getPaddleCount()
boolean hasTouchpad() / hasGyro() / hasRumble() / hasAnalogTriggers()
boolean isNintendoLayout()           // A/B swapped

ButtonName 提供按钮(A…Y、DPAD_UP、LEFT_BUMPER、LEFT_TRIGGER、LEFT_STICK_CLICK、BACK、START、GUIDE、PADDLE_1…PADDLE_4、TOUCHPAD)、摇杆方向(LEFT_STICK_UP …)与轴(AXIS_LEFT_X、AXIS_RIGHT_TRIGGER …)三组常量。

IPlayerStateRegistry

void setState(String stateKey, boolean active)  // thread-safe, callable from any thread
boolean getState(String stateKey)               // client thread
void clearState(String stateKey)                // drop the registration

stateKey 形如 modId:stateName(如 epicfight:battle_mode),就是 compat JSON 里 itemSuppressKeys[].playerState 读的那个字符串。

ICameraLookConsumer(0.8.8+)

boolean consumeLook(float yaw, float pitch)
// true  = this frame's look is consumed: Control Flex must not write player rotation
// false = not consumed: Control Flex keeps its normal path

IInteractiveContextRegistrar

void notifyOverlayForeground(String className)   // overlay entered the foreground
void notifyOverlayBackground(String className)   // overlay went back (pairs with foreground)
void clearAll()                                  // fallback: world unload / mod shutdown

className 是全限定类名 —— Control Flex 拿它去 compat JSON 的 overlay 表里查摇杆与光标行为。调用前先判空:getInteractiveContextRegistrar() 可能是 null。

ICompatAssetInstaller

boolean install(String resourcePath, String fileName)
// resourcePath: classpath path inside your jar, e.g. "/assets/mymod/compat/targetmod_keys.json"
// fileName:     target file name inside compat/mods/ or guides/mods/
// returns:      true when installed

继续读