代码架构与 Mixin 注入
本技术参考详细介绍了 速度计 (Speedometer) 的包层级结构、源码布局和 Mixin 注入目标分析。
📊 代码包架构图解
text
net.vanillaoutsider.speedometer
├── SpeedometerMod.java <-- Constants & Identifier definitions
├── client
│ ├── SpeedometerClient.java <-- ClientModInitializer entrypoint
│ ├── DebugEntrySpeedometer.java <-- Custom DebugScreenEntry implementation
│ └── DebugEntryPlayerSpeedWrapper.java <-- Interceptor spy-wrapper for player_speed
└── mixin
├── DebugScreenEntriesMixin.java <-- Hooks into DebugScreenEntries static init
└── DebugScreenEntryListMixin.java <-- Enforces default IN_OVERLAY status🧩 Mixin 注入目标对照清单
| Mixin 类 | 目标 Minecraft 原版类 | 目标方法 / 注入点 | 注入类型 | 目的说明 |
|---|---|---|---|---|
DebugScreenEntriesMixin | net.minecraft.client.gui.components.debug.DebugScreenEntries | <clinit> @At("TAIL") | @Inject | 注册 speedometer 调试条目 ID,并在原生 player_speed 条目存在时进行包装拦截。 |
DebugScreenEntriesMixin | net.minecraft.client.gui.components.debug.DebugScreenEntries | register | @Invoker | 调用原版私有 register(Identifier, DebugScreenEntry) 注册方法。 |
DebugScreenEntryListMixin | net.minecraft.client.gui.components.debug.DebugScreenEntryList | rebuildCurrentList @At("HEAD") | @Inject | 确保 speedometer 的显示状态默认初始化为 DebugScreenEntryStatus.IN_OVERLAY。 |
🔒 线程安全与非阻塞保障
- 所有 Mixin 注入代码均严格独占运行在 Minecraft 客户端渲染线程中。
- 零加锁的完全非阻塞式实现保证零掉帧 ($<0.001\text{ ms}$)。
