🏛️ Arquitetura e Análise de Mixins
📌 Aviso Legal do Código-Fonte do Repositório: A documentação nesta Wiki reflete o estado atual do código-fonte no repositório, que pode incluir commits recentes não lançados ou recursos em desenvolvimento antes dos lançamentos públicos no CurseForge e Modrinth.
🔬 Arquitetura de Alto Nível e Ciclo de Vida
O True Sleep intercepta o sono no servidor, substituindo o salto abrupto por um loop sincronizado controlado pelo TimeWarpManager.
[ 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 ]🧩 Inventário de Mixins e Descritores de Injeção
| Classe Mixin | Classe Alvo do Minecraft | Ponto de Injeção | Método | Finalidade e Função |
|---|---|---|---|---|
BedRuleMixin | net.minecraft.world.attribute.BedRule$Rule | @At("HEAD") (Cancellable) | test(Level) | Sobrescreve a checagem WHEN_DARK em favor de truesleep:sleep_threshold. |
ServerLevelMixin | net.minecraft.server.level.ServerLevel | @At("INVOKE") (Redirect) | areEnoughSleeping / areEnoughDeepSleeping | Retorna false para impedir o pulo imediato da noite vanilla. |
ServerLevelMixin | net.minecraft.server.level.ServerLevel | @At("TAIL") | tick(BooleanSupplier) | Verifica condições e executa o TimeWarpManager.tick(). |
LevelMixin | net.minecraft.world.level.Level | @At("INVOKE") (Redirect) | TickingBlockEntity.tick() | Multi-ticka máquinas e funis acoplados com base no stride. |
MobMixin | net.minecraft.world.entity.Mob | @At("HEAD") (Cancellable) | tick() | Pausa a IA de movimento e processa o envelhecimento biológico. |
EntityMixin | net.minecraft.world.entity.Entity | @At("HEAD") | baseTick() | Enche o oxigênio para evitar afogamento quando drown_immunity está ativo. |
LivingEntityMixin | net.minecraft.world.entity.LivingEntity | @At("HEAD") | baseTick() | Acelera a duração de poções ativas em stride - 1 ticks. |
MobEffectInstanceMixin | net.minecraft.world.effect.MobEffectInstance | Interface Injection | truesleep$ageEffect(int) | Consome efeitos de poções encadeados sem travar a execução. |
VibrationSystemListenerMixin | net.minecraft.world.level.gameevent.vibrations.VibrationSystem$Listener | @At("HEAD") (Cancellable) | handleGameEvent(...) | Suprime vibrações do Warden durante a dobra temporal. |
client.HudMixin | net.minecraft.client.gui.Hud | @At("HEAD") (Cancellable) | extractSleepOverlay(...) | Remove o escurecimento de tela vanilla durante o sono. |
client.SkyRendererMixin | net.minecraft.client.renderer.SkyRenderer | @At("TAIL") | extractRenderState(...) | Interpola o ângulo do céu com fator 0.35 para movimento suave. |
⚡ Caching de Alta Eficiência sem Alocação de Memória
Em alta velocidade ($50\text{ TPS} \times 50\text{ passo} = 2{,}500\text{ iterações/s}$), alocar objetos no heap provoca pausas de Garbage Collection (GC).
O True Sleep adota estruturas estáticas concorrentes sem travas:
truesleep$unfreezeCache: Armazena GameRules porEntityType<?>eliminando concatenação de texto.truesleep$WORKER_CACHE: Salva testes da tag#truesleep:worker_mobs.truesleep$PRODUCTION_MACHINE_CACHE: Mapeia blocos de#truesleep:accelerated_machines.- Snapshots no
TimeWarpManager: Lê regras uma vez por tick em vez de buscar no registro repetidamente.
