? DevKit API
一个轻量级、模块化的工具包,用于构建 Fabric 模组,减少样板代码并提供更一致的基础设施。
DevKit API 是专为 Minecraft 1.21.x 开发者设计的库。它将许多模组所需的常见系统——注册表、网络通信、Data Components(数据组件)、同步配置和数据生成——整合到小型、可重用的 API 背后。
它本身不添加任何游戏玩法内容。玩家仅在另一个模组将 DevKit API 列为依赖项时才应安装它。
✨ DevKit 提供的内容
? Registry Kit
KRegister 按照声明顺序收集注册表条目,并通过类型安全的 RegistrySupplier 引用暴露它们。
它提供:
- 紧凑且类型安全的声明;
- 重复标识符检测;
- 在过早访问条目时显示清晰错误;
- 部分注册失败后的安全重试行为;
- 针对较新 Minecraft 版本的区块和物品的注册表键感知工厂。
public static final KRegister<Item> ITEMS =
KRegister.create("mymod", RegistryKeys.ITEM);
public static final RegistrySupplier<Item> RUBY =
ITEMS.register("ruby", key ->
new Item(new Item.Settings().registryKey(key)));
? Payload Networking
DevKit 基于 Fabric 的 Payload API 构建,同时保持仅客户端的网络通信与通用及专用服务器代码隔离。
数据包类声明稳定的 ID、编解码器和方向。AutoPacketRegistry 验证元数据、注册 payload,并为 S2C 或 C2S 流量连接正确的接收器。
包含的帮助程序涵盖常见的发送模式:
- 发送给单个玩家;
- 发送给追踪某位置的玩家;
- 向所有玩家广播;
- 从客户端发送给已连接的服务器。
@AutoPacket(
value = "mymod:energy_sync",
direction = AutoPacket.Direction.S2C
)
public record EnergySyncPacket(int energy) implements SyncedPacket {
// ID, CODEC, and handler
}
客户端接收器在数据包注册后自动接线,包括在初始化过程中稍后注册的数据包。
⚙️ Synchronized JSON Config
ConfigManager 加载可读的 JSON 配置文件,或在不存在时创建默认文件。
添加 @SyncedConfig 可使配置成为服务器权威。DevKit 可以在玩家加入时同步其值,并在重载后广播更新。
配置系统支持:
- 每个模组多个命名配置;
- 无需替换配置对象即可实时更新;
- 在支持的条件下更安全的文件替换;
- 损坏文件的保护;
- 同步 payload 大小验证。
@SyncedConfig("mymod")
public final class MyConfig {
public int maxEnergy = 10_000;
public boolean enableParticles = true;
}
MyConfig config =
ConfigManager.loadOrCreate(MyConfig.class, "mymod", "main");
? Data Components
Components API 围绕 Minecraft 的 Data Component 系统提供流畅的构建器。
持久化编解码器、数据包编解码器、缓存和注册表插入可以通过一个紧凑的声明进行配置。
public static final ComponentType<Integer> ENERGY =
Components.intComponent("mymod", "energy")
.cache()
.buildAndRegister();
?️ Datagen Helpers
DevKit 包含了可重用的基础结构,用于处理频繁重复的数据生成任务:
- 物品和方块模型;
- 方块和物品标签;
- 通用的
c:约定标签; - 方块战利品表。
版本特定的实现处理了 Minecraft 客户端模型系统的变化,同时保持公共帮助程序 API 的一致性。
? 它如何融入模组
依赖模组通常遵循一个简单的生命周期:
- 声明注册表容器、组件、数据包和配置类。
- 从模组初始化程序引导注册表条目。
- 在通用初始化期间注册数据包类。
- 通过
ConfigManager加载配置。 - 在游戏玩法代码中使用网络和帮助程序配置。
DevKit 尽早执行验证,并将物理客户端代码与专用服务器分离,从而减少通常仅在运行时出现的设置错误。
? 示例和文档
集成示例随每个受支持的构建一起编译,并演示了注册表条目、Data Components、S2C/C2S 数据包和同步配置。
⚠️ 项目状态
DevKit API 目前处于 alpha 阶段。
其核心系统正在运行,但公共 API 签名可能在稳定发布之前发生变化。模组开发人员应锁定其项目使用的确切 DevKit 版本。
由 jrxmod 创建和维护
根据 Apache License 2.0 许可。
? DevKit API
A lightweight, modular toolkit for building Fabric mods with less boilerplate and more consistent infrastructure.
DevKit API is a developer-focused library for Minecraft 1.21.x. It brings together common systems that many mods need-registries, networking, Data Components, synchronized configuration, and data generation-behind small, reusable APIs.
It does not add gameplay content on its own. Players should install it only when another mod lists DevKit API as a dependency.
✨ What DevKit Provides
? Registry Kit
KRegister collects registry entries in declaration order and exposes them through typed RegistrySupplier references.
It provides:
- compact and type-safe declarations;
- duplicate identifier detection;
- clear errors when an entry is accessed too early;
- safe retry behavior after partial registration failures;
- registry-key-aware factories for blocks and items on newer Minecraft versions.
public static final KRegister<Item> ITEMS =
KRegister.create("mymod", RegistryKeys.ITEM);
public static final RegistrySupplier<Item> RUBY =
ITEMS.register("ruby", key ->
new Item(new Item.Settings().registryKey(key)));
? Payload Networking
DevKit builds on Fabric's Payload API while keeping client-only networking isolated from common and dedicated-server code.
Packet classes declare a stable ID, codec, and direction. AutoPacketRegistry validates that metadata, registers the payload, and connects the correct receiver for S2C or C2S traffic.
Included helpers cover common sending patterns:
- send to one player;
- send to players tracking a position;
- broadcast to all players;
- send from the client to the connected server.
@AutoPacket(
value = "mymod:energy_sync",
direction = AutoPacket.Direction.S2C
)
public record EnergySyncPacket(int energy) implements SyncedPacket {
// ID, CODEC, and handler
}
Client receivers are wired automatically after packet registration, including packets registered later in initialization.
⚙️ Synchronized JSON Config
ConfigManager loads a readable JSON configuration or creates a default file when none exists.
Add @SyncedConfig to make a config server-authoritative. DevKit can then synchronize its values when a player joins and broadcast updates after a reload.
The config system supports:
- multiple named configs per mod;
- live updates without replacing the config object;
- safer file replacement where supported;
- malformed-file protection;
- synchronized payload size validation.
@SyncedConfig("mymod")
public final class MyConfig {
public int maxEnergy = 10_000;
public boolean enableParticles = true;
}
MyConfig config =
ConfigManager.loadOrCreate(MyConfig.class, "mymod", "main");
? Data Components
The Components API provides fluent builders around Minecraft's Data Component system.
Persistent codecs, packet codecs, caching, and registry insertion can be configured through one compact declaration.
public static final ComponentType<Integer> ENERGY =
Components.intComponent("mymod", "energy")
.cache()
.buildAndRegister();
?️ Datagen Helpers
DevKit includes reusable foundations for frequently repeated data generation tasks:
- item and block models;
- block and item tags;
- common
c:convention tags; - block loot tables.
Version-specific implementations handle changes to Minecraft's client model system while keeping the public helper API consistent.
? How It Fits Into a Mod
A dependent mod normally follows a simple lifecycle:
- Declare registry containers, components, packets, and config classes.
- Bootstrap registry entries from the mod initializer.
- Register packet classes during common initialization.
- Load configs through
ConfigManager. - Use the networking and config helpers from normal gameplay code.
DevKit performs validation early and keeps physical-client code away from dedicated servers, reducing setup mistakes that otherwise appear only at runtime.
? Examples and Documentation
- Quick start and focused API examples
- Consumer setup and example usage
- Complete integration example
- Source code
- Issue tracker
The integration example is compiled with every supported build and demonstrates registry entries, Data Components, S2C/C2S packets, and synchronized configuration.
⚠️ Project Status
DevKit API is currently in alpha.
Its core systems are operational, but public API signatures may evolve before the stable release. Mod developers should pin the exact DevKit version used by their projects.
Created and maintained by jrxmod
Licensed under the Apache License 2.0.
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 DevKit API
? DevKit API 0.2.0-alpha.4
一次维护与工具更新:注册表查找、定向配置同步、运行时诊断以及跨版本标签生成。
DevKit API 是一个面向 Fabric 模组开发者的轻量级库。它提供了用于注册表、网络、数据组件(Data Components)、同步配置和数据生成的可复用工具,且不包含任何游戏内容。
✨ 亮点
注册表查找
已声明的条目可以通过路径进行解析,这在注册和使用位于不同类中时非常有用:
KRegister.get(path)返回Optional<RegistrySupplier<T>>,对于未知路径则返回空值;KRegister.contains(path)报告是否声明了某个路径;KRegister.size()报告容器中包含的条目数量;- 以上三个方法在
bootstrap()运行前即可使用,且供应器(supplier)在完成之前保持未绑定状态。
定向配置同步
配置同步不再局限于全量广播:
ConfigSyncManager.sendTo(player, configId)将单个配置推送给指定玩家;- 非权威配置将被拒绝,这与客户端在接收时拒绝它们的检查逻辑一致;
ConfigManager.delete(modId, name)移除配置文件,并报告是否成功移除;- 在客户端应用同步配置时会以信息级别记录日志,显示写入的字段数量,从而无需调试器即可观察同步过程。
运行时诊断
该统一制品注册了一个只读状态命令 /devkit info。它会报告已安装的 DevKit 版本、网络功能、已注册的包数量、已绑定的已声明注册表条目数量以及同步配置的数量。
DevkitCore.getApiVersion() 和 DevkitCore.getModVersion() 以编程方式暴露相同的信息,这对于崩溃报告和故障排除请求非常有用。
跨版本标签生成
vanilla 标签提供器 API 在 1.21.1 到 1.21.11 之间发生了两次更改。TagHelper 现在通过单一钩子隐藏了这两次重命名:
- 重写
buildTags()而非特定版本的提供器钩子; add(key, entries...)和addOptional(key, entries...)直接写入标识符,无需先解析注册表键;tag(path)和cTag(path)构建命名空间标签键和规范标签键;- 直接重写提供器钩子仍然有效,因此现有代码仍可编译。
一个提供器源文件现在可以在 1.21.1、1.21.8 和 1.21.11 上无需修改即可编译。
? 修复
- 配置同步初始化:同步负载和玩家加入监听器按需初始化。即使从未显式初始化同步管理器,服务器权威配置也能到达客户端。此前,配置可能已注册但随后被静默忽略而未发送。
- 配置路径验证:以点开头的段会被拒绝,而不是解析到
config/<modId>之外。 - 客户端初始化失败:作为错误报告,因此缺失的客户端数据包接收器不再隐藏在调试消息之后。
- devkit-core 依赖项:模块声明了其 Fabric API 依赖。在没有 Fabric API 的情况下安装模块现在会因依赖错误而失败,而不是在启动期间发生类加载失败。
- ModelGen.simpleItem:记录警告而非静默跳过未注册的标识符。
- 配置同步日志:管理器在启动时不再记录具有误导性的零配置计数。
? 开发者须知
依赖模组可以通过 Modrinth Maven 消费 DevKit API:
repositories {
maven { url = "https://api.modrinth.com/maven/" }
}
dependencies {
modImplementation "maven.modrinth:devkitapi:0.2.0-alpha.4+1.21.1"
}
Maven Local 发布仍可作为备选方案提供。完整设置说明请参阅 README。
Alpha 软件。 在 1.0 版本发布之前,公共 API 签名仍可能发生变化。
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
查看物品与配方
模组
适用于 MC 1.18+ 的 Effekseer 加载器
模组
添加区块认领和玩家组队功能,并与 Xaero's Minimap 和 World Map 集成
评论 0
登录后参与评分
还没有评论,来抢沙发吧