AnvilLib
AnvilLib 是由 Anvil Dev 开发的 NeoForge 模组库,为 Minecraft 模组开发者提供一系列实用的工具和框架。
功能特性
AnvilLib 采用模块化设计,包含以下功能模块:
| 模块 |
描述 |
| Config |
基于注解的配置系统 |
| Integration |
模组兼容性集成框架 |
| Network |
支持自动注册数据包的联网 API |
| Recipe |
世界内配方系统 |
| Moveable Entity Block |
支持由活塞移动的方块实体 |
| Registrum |
简化的注册系统 |
| Main |
聚合模块,捆绑所有子模块 |
模块介绍
Config 模块
提供基于注解的配置管理系统,简化模组配置的定义和管理。
关键特性:
- 使用
@Config 注解定义配置类
- 使用
@Comment 添加配置注释
- 使用
@BoundedDiscrete 定义数值范围
- 使用
@CollapsibleObject 创建嵌套配置
- 自动生成客户端配置 GUI
使用示例:
@Config(name = "my_mod", type = ModConfig.Type.COMMON)
public class MyModConfig {
@Comment("启用调试模式")
public boolean debugMode = false;
@Comment("最大数量")
@BoundedDiscrete(min = 1, max = 100)
public int maxCount = 10;
}
// 注册配置
MyModConfig config = ConfigManager.register("my_mod", MyModConfig::new);
Integration 模块
提供模组集成框架,支持根据其他模组的存在情况自动加载集成代码。
关键特性:
- 使用
@Integration 注解声明集成类
- 支持版本范围匹配
- 支持不同的运行时环境(CLIENT / DEDICATED_SERVER / DATA)
使用示例:
@Integration(value = "jei", version = "[19.0,)")
public class JEIIntegration {
public void init() {
// JEI 集成逻辑
}
}
Network 模块
提供 NeoForge 网络抽象层,支持基于包的数据包自动注册。
关键特性:
- 使用
IClientboundPacket / IServerboundPacket / IInsensitiveBiPacket 定义数据包方向
- 通过
NetworkRegistrar.register(...) 在包内自动注册数据包类
- 支持
PLAY、CONFIGURATION 和 COMMON 协议
使用示例:
@SubscribeEvent
public static void onRegisterPayload(RegisterPayloadHandlersEvent event) {
PayloadRegistrar registrar = event.registrar("1");
NetworkRegistrar.register(registrar, "my_mod");
}
Recipe 模块
提供世界内配方系统,允许在世界中执行配方(而非仅在合成台中)。
关键特性:
- 支持自定义配方触发器 (Trigger)
- 支持用于条件检查的配方谓词 (Predicate)
- 支持多种配方结果 (Outcome)
- 内置优先级系统
- 完整的数据包支持
配方组件:
- Trigger: 触发配方的条件(例如物品掉落、爆炸)
- Predicate: 配方匹配条件
- Outcome: 配方执行结果(例如生成物品、设置方块)
Moveable Entity Block 模块
允许带有方块实体的方块在被活塞推动时保留其数据。
使用示例:
public class MyBlock extends Block implements IMoveableEntityBlock {
@Override
public CompoundTag clearData(Level level, BlockPos pos) {
// 返回要保留的方块实体数据
BlockEntity be = level.getBlockEntity(pos);
return be != null ? be.saveWithoutMetadata(level.registryAccess()) : new CompoundTag();
}
@Override
public void setData(Level level, BlockPos pos, CompoundTag nbt) {
// 在新位置恢复方块实体数据
BlockEntity be = level.getBlockEntity(pos);
if (be != null) {
be.loadAdditional(nbt, level.registryAccess());
}
}
}
Registrum 模块
基于 Registrate 的注册系统,简化物品、方块、实体等的注册过程。
关键特性:
- 链式 API 设计
- 自动生成语言文件
- 自动生成数据包
- 支持各种构建器
使用示例:
public static final Registrum REGISTRUM = Registrum.create("my_mod");
public static final RegistryEntry<Item> MY_ITEM = REGISTRUM
.item("my_item", Item::new)
.properties(p -> p.stacksTo(16))
.register();
Main 模块
anvillib-neoforge-1.21.1 是聚合产物。它捆绑并重新导出以下内容:
config
integration
network
recipe
moveable-entity-block
registrum
依赖集成
Gradle (Groovy DSL)
repositories {
mavenCentral() // 本项目已上传至 Maven Central
}
dependencies {
// 完整库
implementation "dev.anvilcraft.lib:anvillib-neoforge-1.21.1:2.0.0"
// 或按需导入各个模块
implementation "dev.anvilcraft.lib:anvillib-config-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-integration-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-network-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-recipe-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-moveable-entity-block-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-registrum-neoforge-1.21.1:2.0.0"
}
Gradle (Kotlin DSL)
repositories {
mavenCentral() // 该项目已上传至 Maven Central
}
dependencies {
implementation("dev.anvilcraft.lib:anvillib-neoforge-1.21.1:2.0.0")
// 可选的单模块示例
implementation("dev.anvilcraft.lib:anvillib-network-neoforge-1.21.1:2.0.0")
}
请确保依赖版本号与发布标签保持一致(当前项目属性为 mod_version=2.0.0)。
构建项目
# 克隆仓库
git clone https://github.com/Anvil-Dev/AnvilLib.git
cd AnvilLib
# 在 macOS / Linux 上构建
./gradlew build
# 在 Windows 上构建(PowerShell / CMD)
gradlew.bat build
环境要求
- Java 21+
- Minecraft 1.21.1
- NeoForge 21.1.x
许可证
本项目采用 MIT 许可证。
Registrum 模块的部分代码基于 Registrate,并遵循 Mozilla Public License 2.0。
作者
链接
AnvilLib
AnvilLib is a NeoForge mod library developed by Anvil Dev, providing Minecraft mod developers with a
series of practical tools and frameworks.
Features
AnvilLib adopts a modular design and includes the following functional modules:
| Module |
Description |
| Config |
Annotation-based configuration system |
| Integration |
Mod compatibility integration framework |
| Network |
Networking API with automatic packet registration |
| Recipe |
In-world recipe system |
| Moveable Entity Block |
Support for block entities movable by pistons |
| Registrum |
Simplified registration system |
| Main |
Aggregated module that bundles all submodules |
Module Introduction
Config Module
Provides an annotation-based configuration management system to simplify the definition and management of mod configurations.
Key Features:
- Define configuration classes using
@Config annotation
- Add configuration comments with
@Comment
- Define numerical ranges with
@BoundedDiscrete
- Create nested configurations with
@CollapsibleObject
- Automatically generate client configuration GUI
Usage Example:
@Config(name = "my_mod", type = ModConfig.Type.COMMON)
public class MyModConfig {
@Comment("Enable debug mode")
public boolean debugMode = false;
@Comment("Maximum count")
@BoundedDiscrete(min = 1, max = 100)
public int maxCount = 10;
}
// Register configuration
MyModConfig config = ConfigManager.register("my_mod", MyModConfig::new);
Integration Module
Provides a framework for mod integrations, supporting automatic loading of integration code based on the presence of other mods.
Key Features:
- Declare integration classes with
@Integration annotation
- Support for version range matching
- Support for different runtime environments (CLIENT / DEDICATED_SERVER / DATA)
Usage Example:
@Integration(value = "jei", version = "[19.0,)")
public class JEIIntegration {
public void init() {
// JEI integration logic
}
}
Network Module
Provides a NeoForge networking abstraction with package-based packet auto-registration.
Key Features:
- Define packet direction using
IClientboundPacket / IServerboundPacket / IInsensitiveBiPacket
- Automatically register packet classes in a package via
NetworkRegistrar.register(...)
- Supports
PLAY, CONFIGURATION, and COMMON protocols
Usage Example:
@SubscribeEvent
public static void onRegisterPayload(RegisterPayloadHandlersEvent event) {
PayloadRegistrar registrar = event.registrar("1");
NetworkRegistrar.register(registrar, "my_mod");
}
Recipe Module
Provides an in-world recipe system, allowing recipes to be executed in the world (rather than in crafting tables).
Key Features:
- Supports custom recipe triggers (Trigger)
- Supports recipe predicates (Predicate) for conditional checks
- Supports multiple recipe outcomes (Outcome)
- Built-in priority system
- Full datapack support
Recipe Components:
- Trigger: Conditions to trigger the recipe (e.g., item dropping, explosions)
- Predicate: Recipe matching conditions
- Outcome: Recipe execution results (e.g., spawning items, setting blocks)
Moveable Entity Block Module
Allows blocks with block entities to be pushed by pistons while preserving their data.
Usage Example:
public class MyBlock extends Block implements IMoveableEntityBlock {
@Override
public CompoundTag clearData(Level level, BlockPos pos) {
// Return block entity data to preserve
BlockEntity be = level.getBlockEntity(pos);
return be != null ? be.saveWithoutMetadata(level.registryAccess()) : new CompoundTag();
}
@Override
public void setData(Level level, BlockPos pos, CompoundTag nbt) {
// Restore block entity data at new position
BlockEntity be = level.getBlockEntity(pos);
if (be != null) {
be.loadAdditional(nbt, level.registryAccess());
}
}
}
Registrum Module
A registration system based on Registrate, simplifying the registration process for items, blocks,
entities, etc.
Key Features:
- Chain-style API design
- Automatic language file generation
- Automatic datapack generation
- Support for various builders
Usage Example:
public static final Registrum REGISTRUM = Registrum.create("my_mod");
public static final RegistryEntry<Item> MY_ITEM = REGISTRUM
.item("my_item", Item::new)
.properties(p -> p.stacksTo(16))
.register();
Main Module
anvillib-neoforge-1.21.1 is the aggregate artifact. It bundles and re-exports:
config
integration
network
recipe
moveable-entity-block
registrum
Dependency Integration
Gradle (Groovy DSL)
repositories {
mavenCentral() // This project is already uploaded to Maven Central
}
dependencies {
// Full library
implementation "dev.anvilcraft.lib:anvillib-neoforge-1.21.1:2.0.0"
// Or import individual modules as needed
implementation "dev.anvilcraft.lib:anvillib-config-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-integration-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-network-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-recipe-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-moveable-entity-block-neoforge-1.21.1:2.0.0"
implementation "dev.anvilcraft.lib:anvillib-registrum-neoforge-1.21.1:2.0.0"
}
Gradle (Kotlin DSL)
repositories {
mavenCentral() // This project is already uploaded to Maven Central
}
dependencies {
implementation("dev.anvilcraft.lib:anvillib-neoforge-1.21.1:2.0.0")
// Optional single-module example
implementation("dev.anvilcraft.lib:anvillib-network-neoforge-1.21.1:2.0.0")
}
Keep the dependency version aligned with release tags (current project property is mod_version=2.0.0).
Building the Project
# Clone repository
git clone https://github.com/Anvil-Dev/AnvilLib.git
cd AnvilLib
# Build on macOS / Linux
./gradlew build
# Build on Windows (PowerShell / CMD)
gradlew.bat build
Requirements
- Java 21+
- Minecraft 1.21.1
- NeoForge 21.1.x
License
This project is licensed under the MIT License.
Part of the Registrum module code is based on Registrate and follows the Mozilla Public License
2.0.
Author
Links
评论 0
登录后参与评分
还没有评论,来抢沙发吧