Craft Animation
Craft Animation 是一个用于 Forge 模组开发的可复用动画库。
这不是一个直接添加武器、生物或游戏系统的玩法模组。相反,它提供了一个共享的动画基础架构,供其他模组以一致的方式加载、播放、采样和应用动画。其目标是通过一个通用的运行时结构,支持玩家、生物、通用实体、方块、方块实体、物品以及基于显示的渲染对象。
支持的目标对象
- 玩家
- 生物
- 通用实体
- 方块
- 方块实体
- 物品
- 基于显示的渲染对象
包含的系统
- 共享动画目标类型
- 基于关键帧的剪辑结构
- 缓动支持
- 用于播放、停止、循环和播放速度的控制器
- 活动动画主体的运行时跟踪
- 基于 JSON 的动画加载
- 示例动画资源
支持的格式
Craft Animation 围绕两个主要的输入路径设计:
- 通用的内置 JSON 剪辑格式
- Emotecraft 风格的表情(emote)JSON 加载
这意味着你可以直接编写自己的剪辑格式,或者在管线中重用现有的玩家动画数据结构。
如何在你的模组中连接和使用它
此库旨在连接到你自己的渲染器、模型或游戏逻辑代码。它不会自动将完整的动画注入到每个原版渲染路径中。正常的工作流程如下:
1. 创建动画 JSON 文件
示例位置:
assets/yourmod/animations/guardian_idle.json
你可以使用内置的示例文件作为参考:
assets/craftanimation/animations/example_idle.json
2. 加载并注册剪辑
通过 CraftAnimationApi.library() 使用 AnimationLibrary。
AnimationClip clip = CraftAnimationApi.library().loadBuiltin(
"assets/yourmod/animations/guardian_idle.json",
getClass().getClassLoader()
);
如果剪辑已经注册,你可以通过以下方式稍后获取它:
AnimationClip clip = CraftAnimationApi.library().require("yourmod:guardian_idle");
3. 创建动画主体键
运行时通过 AnimationSubjectKey 为每个主体保持独立的动画状态。
玩家示例:
AnimationSubjectKey key = AnimationSubjectKey.player(
level.dimension().location().toString(),
player.getUUID()
);
生物示例:
AnimationSubjectKey key = AnimationSubjectKey.mob(
level.dimension().location().toString(),
mob.getUUID()
);
方块实体示例:
AnimationSubjectKey key = AnimationSubjectKey.blockEntity(
level.dimension().location().toString(),
pos.getX(), pos.getY(), pos.getZ()
);
4. 开始播放
CraftAnimationApi.runtime().play(key, clip);
你也可以直接访问控制器并更改播放速度:
CraftAnimationApi.runtime().controller(key).setSpeed(1.25F);
5. 每刻推进动画
CraftAnimationApi.runtime().tick(key, deltaTicks);
或者一次性更新所有活动的控制器:
CraftAnimationApi.runtime().tickAll(deltaTicks);
6. 采样当前姿态
AnimationPose pose = CraftAnimationApi.runtime().sample(key);
采样的 AnimationPose 正是你需要应用到自己玩家渲染器、实体模型、方块实体渲染器、自定义物品渲染器或显示渲染逻辑中的内容。
简而言之,正常的使用流程是:
- 加载剪辑
- 创建主体键
- 播放剪辑
- 推进运行时
- 采样姿态
- 在渲染/模型代码中应用姿态
典型用例
- 手持自定义武器时的玩家待机姿势
- 生物的待机、行走或攻击姿态
- Boss 或脚本化实体的动画播放
- 方块实体机器或结构的运动
- 基于显示的影视时间线和视觉效果
注意事项
- 此模组主要面向开发者,是一个库。
- 单独安装它不会添加主要的游戏玩法内容。
- 最终的视觉动画效果仍取决于消费模组如何将采样的姿态应用到其渲染器或模型层。
- 运行时是共享的,但针对玩家、实体、方块和自定义渲染系统的最终实现路径是不同的。
预期用户
- Forge 模组开发者
- 需要可复用数据驱动动画系统的项目
- 希望保持单一通用动画架构的多版本模组环境
Craft Animation
Craft Animation is a reusable animation library for Forge mod development.
This is not a content mod that directly adds weapons, mobs, or gameplay systems on its own. Instead, it provides a shared animation foundation that other mods can use to load, play, sample, and apply animations in a consistent way. The goal is to support players, mobs, generic entities, blocks, block entities, items, and display-based render objects through one common runtime structure.
Supported targets
- Players
- Mobs
- Generic entities
- Blocks
- Block entities
- Items
- Display-based render objects
Included systems
- Shared animation target types
- Keyframe-based clip structures
- Easing support
- Controllers for play, stop, loop, and playback speed
- Runtime tracking for active animation subjects
- JSON-based animation loading
- Example animation resources
Supported formats
Craft Animation is designed around two main input paths:
- A generic built-in JSON clip format
- Emotecraft-style emote JSON loading
That means you can either author your own clip format directly or reuse existing player animation data structures as part of your pipeline.
How to connect and use it in your mod
This library is meant to be connected to your own renderer, model, or gameplay code. It does not automatically inject finished animations into every vanilla render path by itself. The normal workflow looks like this:
1. Create an animation JSON file
Example location:
assets/yourmod/animations/guardian_idle.json
You can use the built-in example file as a reference:
assets/craftanimation/animations/example_idle.json
2. Load and register the clip
Use AnimationLibrary through CraftAnimationApi.library().
AnimationClip clip = CraftAnimationApi.library().loadBuiltin(
"assets/yourmod/animations/guardian_idle.json",
getClass().getClassLoader()
);
If the clip is already registered, you can fetch it later with:
AnimationClip clip = CraftAnimationApi.library().require("yourmod:guardian_idle");
3. Create an animation subject key
The runtime keeps separate animation state for each subject through AnimationSubjectKey.
Player example:
AnimationSubjectKey key = AnimationSubjectKey.player(
level.dimension().location().toString(),
player.getUUID()
);
Mob example:
AnimationSubjectKey key = AnimationSubjectKey.mob(
level.dimension().location().toString(),
mob.getUUID()
);
Block entity example:
AnimationSubjectKey key = AnimationSubjectKey.blockEntity(
level.dimension().location().toString(),
pos.getX(), pos.getY(), pos.getZ()
);
4. Start playback
CraftAnimationApi.runtime().play(key, clip);
You can also access the controller directly and change playback speed:
CraftAnimationApi.runtime().controller(key).setSpeed(1.25F);
5. Advance the animation every tick
CraftAnimationApi.runtime().tick(key, deltaTicks);
Or update every active controller at once:
CraftAnimationApi.runtime().tickAll(deltaTicks);
6. Sample the current pose
AnimationPose pose = CraftAnimationApi.runtime().sample(key);
The sampled AnimationPose is what you apply inside your own player renderer, entity model, block entity renderer, custom item renderer, or display rendering logic.
In short, the normal usage flow is:
- Load a clip
- Create a subject key
- Play the clip
- Tick the runtime
- Sample the pose
- Apply the pose in your render/model code
Typical use cases
- Player idle stances while holding custom weapons
- Mob idle, walk, or attack poses
- Boss or scripted entity animation playback
- Block entity machine or structure motion
- Display-based cinematic timelines and visual effects
Notes
- This mod is primarily a developer-facing library.
- Installing it by itself will not add major gameplay content.
- Final visual animation results still depend on how the consuming mod applies sampled poses to its renderer or model layer.
- The runtime is shared, but the final implementation path is different for players, entities, blocks, and custom render systems.
Intended users
- Forge mod developers
- Projects that need a reusable data-driven animation system
- Multi-version mod environments that want to keep one common animation architecture
评论 0
登录后参与评分
还没有评论,来抢沙发吧