Skip to content

🏛️ 架构解析与 Mixin 注入剖析

📌 代码仓库源码声明:本 Wiki 中的文档反映了代码仓库当前的最新源码状态,可能包含尚未在 CurseForge 和 Modrinth 上发布的开发中功能或最新提交。


🔬 顶层架构与生命周期流转

True Sleep 在服务端拦截原版睡眠生命周期,将瞬间时间跳转替换为受 TimeWarpManager 严格管辖的同步 Tick 加速循环。

                  [ Player Enters Bed ]


              [ BedRule.Rule.test() Intercept ]
              (Check truesleep:sleep_threshold)


           [ ServerLevel.tick() Sleep Check ]
          (SleepStatus.areEnoughDeepSleeping())

               +------------+------------+
               │                         │
     [ Not All Sleeping ]       [ All Sleeping (Enough) ]
               │                         │
               ▼                         ▼
      [ Initiate Wind-Down ]    [ Engage Time Warp Engine ]
      (15-tick Deceleration)             │
                                         ├─► Set Physical Rate (ENGINE_TPS: 50 TPS)
                                         ├─► Compute Stride: round(VIRTUAL_TPS / ENGINE_TPS)
                                         ├─► Scale RANDOM_TICK_SPEED by Stride
                                         ├─► Multi-Tick Machines & Coupled Hoppers
                                         ├─► Freeze Mob AI / Age Farm Biology
                                         ├─► Apply Sleep Hunger Exhaustion
                                         └─► Smooth Celestial Sun/Moon (Client Lerp)


                                     [ Destination Arrival ]
                                     (Cycle Dist < 20 Ticks)


                                    [ Snap Monotonic Clock ]
                                   (Set Time to WAKE_TIME: 0)


                                       [ Wake Up All Players ]

🧩 完整 Mixin 注入点清单与描述符对照表

Mixin 类目标 Minecraft 原版类注入点位置挂钩方法注入用途与功能说明
BedRuleMixinnet.minecraft.world.attribute.BedRule$Rule@At("HEAD") (Cancellable)test(Level)覆盖原版 WHEN_DARK 入睡时间检查,对接 truesleep:sleep_threshold
ServerLevelMixinnet.minecraft.server.level.ServerLevel@At("INVOKE") (Redirect)areEnoughSleeping / areEnoughDeepSleeping重定向返回 false,彻底压制原版瞬间跳夜逻辑。
ServerLevelMixinnet.minecraft.server.level.ServerLevel@At("TAIL")tick(BooleanSupplier)侦测入睡条件并驱动 TimeWarpManager.tick() 核心引擎。
LevelMixinnet.minecraft.world.level.Level@At("INVOKE") (Redirect)TickingBlockEntity.tick()对受加速机器与相连漏斗按 stride 跨步执行多重 Tick 推进。
MobMixinnet.minecraft.world.entity.Mob@At("HEAD") (Cancellable)tick()在冻结状态下取消生物移动与 AI,并执行生物学生理时钟演进。
EntityMixinnet.minecraft.world.entity.Entity@At("HEAD")baseTick()激活 drown_immunity 时持续注满氧气,实现水下呼吸停滞。
LivingEntityMixinnet.minecraft.world.entity.LivingEntity@At("HEAD")baseTick()将生效中的药水状态效果持续时间按 stride - 1 刻快速老化。
MobEffectInstanceMixinnet.minecraft.world.effect.MobEffectInstanceInterface Injectiontruesleep$ageEffect(int)递归扣减级联隐藏药水效果时间,杜绝递归死循环异常。
VibrationSystemListenerMixinnet.minecraft.world.level.gameevent.vibrations.VibrationSystem$Listener@At("HEAD") (Cancellable)handleGameEvent(...)在时间加速期间全自动抑制并静音监守者声波震动事件。
client.HudMixinnet.minecraft.client.gui.Hud@At("HEAD") (Cancellable)extractSleepOverlay(...)取消原版就寝时的全屏死黑遮罩画面。
client.SkyRendererMixinnet.minecraft.client.renderer.SkyRenderer@At("TAIL")extractRenderState(...)以 0.35 系数对天体角度执行平滑角插值,呈现电影级夜空。

⚡ 零分配热路径缓存技术 (Zero-Allocation)

在超高速时间推进期间($50\text{ 物理 TPS} \times 50\text{ 跨步} = 2{,}500\text{ 次有效迭代/秒}$),实体与方块循环中的内存对象分配极易引发剧烈的垃圾回收 (GC) 停顿。

True Sleep 在所有热路径上全面采用 静态并发无锁缓存结构

  1. truesleep$unfreezeCache:针对每个 EntityType<?> 缓存动态 GameRule 实例,彻底消除字符串拼接与哈希查找开销。
  2. truesleep$WORKER_CACHE:缓存 #truesleep:worker_mobs 标签包含性判定结果。
  3. truesleep$PRODUCTION_MACHINE_CACHE:缓存 #truesleep:accelerated_machines 方块实体类型匹配结果。
  4. TimeWarpManager 字段级规则快照:每物理刻仅获取一次规则布尔状态,而非在成千上万次实体循环内反复查询注册表。

Official documentation & web portal for Dasik Igaijinn mods.