本人授权任何希望将我的模组加入整合包的人使用
Wild Battle API
Wild Battle API 是为 Cobblemon 提供的共享野生战斗 AI 框架。
对于玩家和整合包作者而言,它提供了可配置的更智能的野生战斗行为,并内置了预设和管理工具。对于开发者而言,它公开了一个受支持的公共 API,允许注册自定义的野生 BattleAI 实现,而无需直接替换 Cobblemon 的内部逻辑。
Wild Battle API 会在战斗开始时为野生战斗实体安装一个委托 AI。在每次 AI 决策时:
- 首先检查高优先级的提供程序。
- 第一个返回非空
BattleAI 的提供程序将被使用。
- 返回
null 则交由低优先级提供程序处理。
- 如果没有提供程序声明对该上下文的所有权,则将使用原始 Cobblemon AI 作为回退方案。
这使得多个模组能够安全地协作,同时在没有自定义提供程序适用的情况下保持可靠的路径回退。
包含功能
- 用于野生战斗 AI 扩展的共享 API
- 基于优先级的提供程序解析
- 安全回退至实体的原始 Cobblemon AI
- 内置的可配置智能野生 AI 行为
- 从
easy(简单)到 extreme(极端)的难度预设
- 管理界面和调试命令
- 支持 Minecraft
1.21.1 的 Fabric 和 NeoForge
管理员命令
Wild Battle API 包含了用于测试和配置的操作员/管理员命令。
命令:
/wildbattleapi ui
/wildbattleapi difficulty <easy|medium|hard|extreme>
/wildbattleapi debug on
/wildbattleapi debug off
/wildbattleapi debug status
别名:
/wba ui
/wba difficulty <easy|medium|hard|extreme>
/wba debug on|off|status
这些命令需要权限级别 2。
开发者用法
开发者用法
支持的公共 API
第三方集成仅应使用以下类:
com.github.raguto.wildbattleapi.api.WildBattleAPI
com.github.raguto.wildbattleapi.api.WildAIProvider
com.github.raguto.wildbattleapi.api.WildAIContext
请勿依赖内部包,如 impl、mixin、config 或 network。
运行时依赖
在您依赖的模组加载的任何位置安装 Wild Battle API。在正常的整合包中,这意味着客户端和服务端都需要。
模组 ID:
同时请在您的模组元数据中将其声明为依赖项。
Fabric (fabric.mod.json):
{
"depends": {
"wild_battle_api": "*"
}
}
NeoForge (META-INF/neoforge.mods.toml):
[[dependencies.your_mod_id]]
modId = "wild_battle_api"
type = "required"
versionRange = "[1.0.0,)"
ordering = "AFTER"
side = "BOTH"
将最低版本调整为您模组所支持的第一个 Wild Battle API 版本。
编译时依赖
如果您不消费已发布的 Maven 工件,请直接针对特定加载器的 jar 进行编译。
Fabric 示例:
dependencies {
modCompileOnly files("libs/wild_battle_api-fabric-1.0.0.jar")
}
NeoForge 示例:
dependencies {
compileOnly files("libs/wild_battle_api-neoforge-1.0.0.jar")
}
请使用适合您环境的加载器对应的 jar。
注册提供程序
在模组的通用初始化期间注册一次您的提供程序。
import com.github.raguto.wildbattleapi.api.WildBattleAPI;
import com.github.raguto.wildbattleapi.api.WildAIContext;
public final class MyWildAIRegistration {
public static void init() {
WildBattleAPI.registerProvider(150, context -> {
if (shouldUseMyAI(context)) {
return new MyCustomWildBattleAI();
}
return null;
});
}
private static boolean shouldUseMyAI(WildAIContext context) {
return context.getBattle() != null && context.getActor() != null;
}
}
您也可以以默认优先级注册:
WildBattleAPI.registerProvider(context -> null);
优先级指南
0:万能或默认提供程序
50:标准覆盖
100+:高优先级或 Boss 专用覆盖
200+:硬性覆盖,请谨慎使用
如果您的提供程序仅处理特定情况,请对其他所有情况返回 null。
实现自己的 BattleAI
您可以提供任何实现 Cobblemon 的 BattleAI 的类。
import com.cobblemon.mod.common.api.battles.model.PokemonBattle;
import com.cobblemon.mod.common.api.battles.model.ai.BattleAI;
import com.cobblemon.mod.common.battles.ActiveBattlePokemon;
import com.cobblemon.mod.common.battles.BattleSide;
import com.cobblemon.mod.common.battles.PassActionResponse;
import com.cobblemon.mod.common.battles.ShowdownActionResponse;
import com.cobblemon.mod.common.battles.ShowdownMoveset;
import com.cobblemon.mod.common.net.messages.client.battle.BattleHealthChangePacket;
import org.jetbrains.annotations.Nullable;
public final class MyCustomWildBattleAI implements BattleAI {
@Override
public ShowdownActionResponse choose(
ActiveBattlePokemon activeBattlePokemon,
PokemonBattle battle,
BattleSide side,
@Nullable ShowdownMoveset moveset,
boolean forceSwitch
) {
if (forceSwitch || moveset == null) {
return PassActionResponse.INSTANCE;
}
// 在此处替换为您自己的招式或切换逻辑。
return PassActionResponse.INSTANCE;
}
@Override
public void onHealthChange(BattleHealthChangePacket packet) {
// 可选的状态跟踪。
}
}
WildAIContext
WildAIContext 为提供程序提供了决定何时接管野生战斗实体所需的信息。
始终可用:
getActor()
getPokemonList()
getBattle()
isForceSwitch()
根据当前决策可能为 null:
getActiveBattlePokemon()
getAiSide()
getMoveset()
在使用这些可为 null 的字段前请进行空值检查。
集成说明
- 保持提供程序逻辑快速且可预测。
- 当你的模组不希望声明当前上下文时,返回
null。
- 避免在提供程序或 AI 逻辑中抛出异常。
- 在专用服务器和集成单人游戏中进行测试。
- 如果多个模组注册了提供程序,数值优先级较高的会先被检查。
许可协议
Wild Battle API 的代码和二进制文件均为保留所有权利(All Rights Reserved)。
第三方使用及分发权限由模组页面中的作者政策定义。
I grant permission to anyone seeking to add my mod to a modpack
Wild Battle API
Wild Battle API is a shared wild battle AI framework for Cobblemon.
For players and pack authors, it provides configurable smarter wild battle behavior with built-in presets and admin tools. For developers, it exposes a supported public API for registering custom wild BattleAI implementations without replacing Cobblemon internals directly.
Wild Battle API installs a delegating AI on wild battle actors at battle start. On each AI decision:
- Higher-priority providers are checked first.
- The first provider that returns a non-null
BattleAI is used.
- Returning
null defers to lower-priority providers.
- If no provider claims the context, the actor's original Cobblemon AI is used as fallback.
This lets multiple mods cooperate safely while keeping a reliable fallback path when no custom provider applies.
Included Features
- Shared API for wild battle AI extensions
- Priority-based provider resolution
- Safe fallback to the actor's original Cobblemon AI
- Built-in configurable smart wild AI behavior
- Difficulty presets from
easy to extreme
- Admin UI and debug commands
- Fabric and NeoForge support for Minecraft
1.21.1
Admin Commands
Wild Battle API includes operator/admin commands for testing and configuration.
Commands:
/wildbattleapi ui
/wildbattleapi difficulty <easy|medium|hard|extreme>
/wildbattleapi debug on
/wildbattleapi debug off
/wildbattleapi debug status
Aliases:
/wba ui
/wba difficulty <easy|medium|hard|extreme>
/wba debug on|off|status
These commands require permission level 2.
Developer Usage
Developer Usage
Supported Public API
Use only these classes for third-party integrations:
com.github.raguto.wildbattleapi.api.WildBattleAPI
com.github.raguto.wildbattleapi.api.WildAIProvider
com.github.raguto.wildbattleapi.api.WildAIContext
Do not depend on internal packages such as impl, mixin, config, or network.
Runtime Dependency
Install Wild Battle API anywhere your dependent mod loads. In normal modpacks, that means both client and server.
Mod ID:
Also declare it as a dependency in your mod metadata.
Fabric (fabric.mod.json):
{
"depends": {
"wild_battle_api": "*"
}
}
NeoForge (META-INF/neoforge.mods.toml):
[[dependencies.your_mod_id]]
modId = "wild_battle_api"
type = "required"
versionRange = "[1.0.0,)"
ordering = "AFTER"
side = "BOTH"
Adjust the minimum version to the first Wild Battle API version your mod supports.
Compile-Time Dependency
If you are not consuming a published Maven artifact, compile against the loader-specific jar directly.
Fabric example:
dependencies {
modCompileOnly files("libs/wild_battle_api-fabric-1.0.0.jar")
}
NeoForge example:
dependencies {
compileOnly files("libs/wild_battle_api-neoforge-1.0.0.jar")
}
Use the loader-appropriate jar for your environment.
Registering a Provider
Register your provider once during your mod's common initialization.
import com.github.raguto.wildbattleapi.api.WildBattleAPI;
import com.github.raguto.wildbattleapi.api.WildAIContext;
public final class MyWildAIRegistration {
public static void init() {
WildBattleAPI.registerProvider(150, context -> {
if (shouldUseMyAI(context)) {
return new MyCustomWildBattleAI();
}
return null;
});
}
private static boolean shouldUseMyAI(WildAIContext context) {
return context.getBattle() != null && context.getActor() != null;
}
}
You can also register at the default priority:
WildBattleAPI.registerProvider(context -> null);
Priority Guidance
0: catch-all or default provider
50: standard override
100+: high-priority or boss-specific override
200+: hard override, use carefully
If your provider only handles specific cases, return null for everything else.
Implementing Your Own BattleAI
You may provide any class that implements Cobblemon's BattleAI.
import com.cobblemon.mod.common.api.battles.model.PokemonBattle;
import com.cobblemon.mod.common.api.battles.model.ai.BattleAI;
import com.cobblemon.mod.common.battles.ActiveBattlePokemon;
import com.cobblemon.mod.common.battles.BattleSide;
import com.cobblemon.mod.common.battles.PassActionResponse;
import com.cobblemon.mod.common.battles.ShowdownActionResponse;
import com.cobblemon.mod.common.battles.ShowdownMoveset;
import com.cobblemon.mod.common.net.messages.client.battle.BattleHealthChangePacket;
import org.jetbrains.annotations.Nullable;
public final class MyCustomWildBattleAI implements BattleAI {
@Override
public ShowdownActionResponse choose(
ActiveBattlePokemon activeBattlePokemon,
PokemonBattle battle,
BattleSide side,
@Nullable ShowdownMoveset moveset,
boolean forceSwitch
) {
if (forceSwitch || moveset == null) {
return PassActionResponse.INSTANCE;
}
// Replace this with your own move or switch logic.
return PassActionResponse.INSTANCE;
}
@Override
public void onHealthChange(BattleHealthChangePacket packet) {
// Optional state tracking.
}
}
WildAIContext
WildAIContext gives providers the information needed to decide whether to claim a wild battle actor.
Always available:
getActor()
getPokemonList()
getBattle()
isForceSwitch()
Nullable depending on the current decision:
getActiveBattlePokemon()
getAiSide()
getMoveset()
Guard nullable fields before using them.
Integration Notes
- Keep provider logic fast and predictable.
- Return
null when your mod does not want to claim the current context.
- Avoid throwing exceptions from provider or AI logic.
- Test in both dedicated server and integrated singleplayer.
- If multiple mods register providers, higher numeric priority is checked first.
Licensing
Wild Battle API code and binaries are All Rights Reserved.
Third-party usage and distribution permissions are defined by the author policy on the mod page.
评论 0
登录后参与评分
还没有评论,来抢沙发吧