OmniMixin
OmniMixin 是一个适用于 Minecraft 1.21 的 Fabric mixin 库,它为其他模组提供了一套庞大且现成的事件钩子(event hooks),用于挂钩常见的游戏行为。这样模组作者就不必为自己编写、维护和调试用于日常任务的原始 mixin。与其让每个模组都将自己的原始 mixin 注入到相同的原版类中并可能导致彼此冲突,OmniMixin 暴露了一个单一、稳定的基于事件的 API,允许多个模组同时安全地在其基础上构建。它旨在捆绑在使用它的模组内部,因此玩家无需单独安装它——只要存在依赖它的模组,它就会在后台默默运行。
以下是该库包含的所有子系统的详细说明。
Movement(移动)
此子系统涵盖实体在世界中的移动方式。它包括一个在应用之前读取和调整实体移动速度的钩子、一个实体开始或停止疾跑时的钩子、一个实体跳跃时触发的钩子、一个调整玩家飞行速度的钩子,以及一个实体被另一个实体物理推开时的钩子。这些功能共同允许模组添加速度修正、自定义疾跑行为、跳跃效果、自定义飞行速度或改变碰撞后的击退效果,而无需触碰基础移动代码本身。
Combat(战斗)
此子系统涵盖伤害、治疗和状态效果。它包括一个每当活体实体受到伤害时触发的钩子,允许模组在伤害生效前检查、修改或取消该伤害。还有一个匹配的击退钩子,以便模组可以更改实体被击中时被击飞多远或多猛。护甲方面也有覆盖,包括护甲吸收多少伤害的钩子,以及护甲耐久度磨损时的钩子。状态效果(药水效果)拥有独立的钩子,分别用于当效果添加到实体上和从实体上移除时,这两个过程都可以被拦截或取消。战斗部分还包括治疗钩子、实体死亡事件钩子,以及实体吸收之心(来自如“吸收”状态效果等效果的额外黄色心形)变化钩子。
World and blocks(世界与方块)
此子系统涵盖方块在世界中的行为。它包括一个当玩家或其他来源右键点击并与方块交互时的钩子、一个邻居更新钩子(游戏告知方块附近发生变化的方式,驱动诸如红石和物理反应等现象),以及一个关于方块输出弱红石信号强度和强红石信号强度的钩子。方块的放置和破坏各自拥有一对钩子,其中破坏钩子分为可以在完全取消破坏的“破坏前”阶段和在完成破坏后做出反应的“破坏后”阶段。此外,还有一个关于玩家方块破坏速度的钩子,以便模组可以根据特定条件调整挖掘特定方块的速度。
Items(物品)
此子系统涵盖物品使用时的行为。它包括在空中使用物品的钩子、在方块上使用物品的钩子,以及完成使用动作(例如吃完或喝完某物)的钩子,这些都可以被观察或重写。还有一个用于点击库存界面槽位的钩子,对于想要反应或限制特定库存操作的模组非常有用。装备变更也得到覆盖,有一个每当实体在给定槽位中的装备物品发生变化时触发的钩子。最后,还有一个关于方块被破坏时掉落物品的钩子,允许模组根据上下文更改或增加方块的掉落表。
Entities(实体)
此子系统涵盖实体的通用生命周期和 AI。它包括一个为每个实体每刻触发一次的钩子、一个实体被丢弃或消失时的钩子,以及一个判断在当前游戏规则下是否允许生物生成的钩子,模组可利用其添加或限制自定义生成条件。还有实体生成到服务器世界时的钩子、目标被添加到生物 AI 目标选择器时的钩子(以便模组检查、阻止或替换特定的 AI 行为),以及生物设置攻击或跟随目标时的钩子。
Data syncing(数据同步)
此子系统允许模组将自定义数据附加到任何实体,并使其随实体的常规存档数据自动保存和加载。它通过一个小注册表工作:模组在其中注册一个希望被跟踪的命名、类型化的值;OmniMixin 随后负责在保存时将那个值写入实体的 NBT 数据,并在加载时将其读回,因此模组无需为简单的每实体数据编写自己的 NBT 序列化代码。
Rendering (client-side)(渲染 - 客户端)
此子系统涵盖仅在客户端运行的视觉和屏幕相关钩子。它包括实体渲染钩子、游戏打开或更改当前屏幕时的钩子、准星显示(HUD)渲染通道的钩子、屏幕初始化和移除生命周期的钩子,以及相机使用的视野(FOV)计算钩子。这些允许模组调整视觉效果、响应屏幕变化、绘制自定义 HUD 元素或微调 FOV 行为,而无需维护单独的渲染 mixin。
Why it exists(为什么存在)
由于每个钩子都集中在一处库中,使用 OmniMixin 的模组避免了针对相同原版方法的重复 mixin,这是导致模组不兼容的更常见来源之一。如果你是玩家,看到另一个模组将 OmniMixin 列为依赖项,那是预期的——与该模组一起安装它即可,它将自动完成任务,无需任何配置。
OmniMixin
OmniMixin is a Fabric mixin library for Minecraft 1.21 that gives other mods a large, ready-made set of event hooks into common game behavior, so mod authors don't have to write, maintain, and debug their own mixins for everyday tasks. Instead of every mod injecting its own raw mixins into the same vanilla classes and risking conflicts with each other, OmniMixin exposes a single, stable, event-based API that multiple mods can safely build on at the same time. It is meant to be bundled inside the mods that use it, so players never install it separately - it just works quietly in the background whenever a mod that depends on it is present.
Below is a breakdown of every subsystem included in the library.
Movement
This subsystem covers how entities move through the world. It includes a hook for reading and adjusting an entity's movement speed before it's applied, a hook for when an entity starts or stops sprinting, a hook that fires when an entity jumps, a hook for adjusting a player's flying speed, and a hook for when an entity gets physically pushed away by another entity. Together these let a mod add speed modifiers, custom sprint behavior, jump effects, custom flight speeds, or altered collision pushback without touching the base movement code itself.
Combat
This subsystem covers damage, healing, and status effects. It includes a hook that fires whenever a living entity takes damage, letting a mod inspect, modify, or cancel the damage before it applies. There's a matching hook for knockback, so a mod can change how far or how hard an entity is thrown back when hit. Armor is covered as well, with hooks for how much damage armor absorbs and for when armor durability is worn down. Status effects (potion effects) have their own hooks for when an effect is added to an entity and when one is removed, both of which can be intercepted or cancelled. Rounding out combat are hooks for healing, for an entity's death event, and for changes to an entity's absorption hearts (the extra yellow hearts from effects like the Absorption status effect).
World and blocks
This subsystem covers how blocks behave in the world. It includes a hook for when a player or other source right-clicks and interacts with a block, a hook for neighbor updates (the game's way of telling a block that something nearby changed, which drives things like redstone and physics reactions), and hooks for how much weak and strong redstone power a block outputs. Block placement and block breaking each get their own pair of hooks, with the breaking hooks split into a "before break" stage that can cancel the break entirely and an "after break" stage for reacting once it's done. There's also a hook for a player's block breaking speed, so a mod can adjust how fast specific blocks are mined under specific conditions.
Items
This subsystem covers how items behave when used. It includes hooks for using an item in the air, using an item on a block, and finishing a use action (such as finishing eating or drinking something), each of which can be observed or overridden. There's a hook for clicking a slot in an inventory screen, useful for mods that want to react to or restrict specific inventory actions. Equipment changes are covered too, with a hook that fires whenever an entity's equipped item in a given slot changes. Finally, there's a hook for the items a block drops when broken, letting a mod change or add to a block's drop table based on context.
Entities
This subsystem covers the general lifecycle and AI of entities. It includes a hook that fires every tick for every entity, a hook for when an entity is discarded or despawns, and a hook for whether a mob is allowed to spawn under the game's current rules, which a mod can use to add or restrict custom spawn conditions. There's a hook for when an entity is spawned into a server world, a hook for when a goal is added to a mob's AI goal selector (so a mod can inspect, block, or replace specific AI behaviors), and a hook for when a mob sets its attack or follow target.
Data syncing
This subsystem lets mods attach their own custom data to any entity and have it automatically saved and loaded with that entity's normal save data. It works through a small registry where a mod registers a named, typed value it wants tracked; OmniMixin then handles writing that value into the entity's NBT data when it saves and reading it back out when it loads, so mods don't need to write their own NBT serialization code for simple per-entity data.
Rendering (client-side)
This subsystem covers visual and screen-related hooks that only run on the client. It includes a hook into entity rendering, a hook for when the game opens or changes the current screen, a hook into the heads-up display's render pass, hooks for a screen's initialization and removal lifecycle, and a hook for the field-of-view calculation used by the camera. These let a mod adjust visuals, react to screen changes, draw custom HUD elements, or tweak FOV behavior without maintaining separate render mixins.
Why it exists
Because every hook is centralized in one library, mods that use OmniMixin avoid duplicate mixins targeting the same vanilla methods, which is one of the more common sources of mod incompatibility. If you're a player and see OmniMixin required as a dependency by another mod, that's expected - install it alongside that mod and it will do its job automatically without any configuration needed.
评论 0
登录后参与评分
还没有评论,来抢沙发吧