? 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
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.
评论 0
登录后参与评分
还没有评论,来抢沙发吧