Introduction
The Soul Link Speedrun mod is built with a clean, service-oriented architecture that separates concerns into distinct packages. The core design uses the Facade pattern through theRunManager class, which coordinates multiple specialized services to manage the speedrun lifecycle.
Main Packages
The mod is organized into the following key packages:net.zenzty.soullink.server.run
Core run management and lifecycle services:
- RunManager - Central facade coordinating all run services
- WorldService - Temporary world creation and cleanup
- TimerService - Run timer management
- SpawnFinder - Spawn point search algorithm
- PlayerTeleportService - Player teleportation utilities
- RunState - Run lifecycle state enum
net.zenzty.soullink.server.health
Shared stats synchronization:
- SharedStatsHandler - Health and hunger synchronization
- SharedPotionHandler - Potion effect sharing
- SharedJumpHandler - Jump boost synchronization
net.zenzty.soullink.server.manhunt
Manhunt mode features:
- ManhuntManager - Runner/Hunter team management
- CompassTrackingHandler - Hunter compass tracking
net.zenzty.soullink.server.settings
Configuration management:
- Settings - Game mode and difficulty settings
- SettingsPersistence - Settings serialization
net.zenzty.soullink.server.inventory
Inventory synchronization:
- SharedInventoryHandler - Synced inventory mode
net.zenzty.soullink.server.event
Event handling:
- EventRegistry - Delayed task scheduling
net.zenzty.soullink.server.command
Command implementations:
- Various command classes for
/start,/end, etc.
net.zenzty.soullink.mixin
Minecraft mixins for hooking into vanilla behavior:
- player/ - Player-related hooks
- server/ - Server-side hooks
- item/ - Item behavior modifications
Design Patterns
Facade Pattern
TheRunManager class implements the Facade pattern, providing a simplified interface to coordinate multiple complex subsystems:
RunManager.java:45-110
This pattern keeps the run management logic organized and testable by delegating to specialized services rather than implementing everything in one monolithic class.
Singleton Pattern
Many core services use thread-safe singleton initialization:RunManager.java:47,112-125
Service Layer Pattern
Each major feature is encapsulated in a dedicated service class:WorldServicehandles Fantasy world lifecycleTimerServicemanages timing and action bar displaySpawnFinderimplements incremental spawn searchPlayerTeleportServicehandles all teleportation logic
State Machine Pattern
The run lifecycle is managed through theRunState enum:
RunState.java:6-17
State transitions are carefully controlled:
IDLE→GENERATING_WORLD(when/startis run)GENERATING_WORLD→RUNNING(when spawn found)RUNNING→GAMEOVER(on death or dragon kill)GAMEOVER→IDLE(automatic cleanup)
Data Flow
Run Start Flow
- User runs
/startcommand RunManager.startRun()coordinates:- Save old world handles
- Create new temporary worlds via
WorldService - Reset shared stats via
SharedStatsHandler - Reset timer via
TimerService - Start spawn search via
SpawnFinder - Put players in spectator mode
- Each tick,
SpawnFinderincrementally searches for spawn - When found, transition to
RUNNINGstate - Teleport players and start timer
Stat Synchronization Flow
- Player takes damage/heals/eats
- Mixin intercepts the event
SharedStatsHandlerupdates master values- Master values sync to all other players
- Sync flag prevents infinite loops
Thread Safety
The architecture uses several thread-safety mechanisms:volatilefields for state shared across threadssynchronizedmethods for critical initializationisSyncingflags to prevent recursive updates- Accumulators for fractional damage/healing to prevent rounding errors
Integration Points
Fantasy Library
The mod uses the Fantasy library for temporary world management.WorldService wraps Fantasy’s API to create and delete dimensions on-demand.
Minecraft Mixins
Mixins hook into vanilla Minecraft behavior at critical points:- Player damage/healing
- Hunger changes
- Portal usage
- End dragon fight
mixin/ package for implementation details.