Overview
Voxy World Gen V2 uses Fabric API’s event system to hook into the server lifecycle. TheServerEventHandler class provides centralized event handling that coordinates:
- Server startup and shutdown
- Player connection management
- Periodic tick processing
- Integration with
ChunkGenerationManager
Event Handler Registration
All events are registered in the main mod initializer (VoxyWorldGenV2.java):
Event Handlers
onServerStarted
Event:ServerLifecycleEvents.SERVER_STARTEDWhen: After the server finishes starting up and is ready to accept players
- Logs server startup
- Initializes the
ChunkGenerationManagersingleton with the server instance - Starts the background worker thread for chunk generation
- Loads configuration from disk
- Sets up the generation throttle (semaphore)
ChunkGenerationManager.initialize()/workspace/source/src/main/java/com/ethan/voxyworldgenv2/core/ChunkGenerationManager.java:103- Creates worker thread
- Loads
Config.DATA - Initializes throttle with
maxActiveTaskspermits
The mod will not generate any chunks until this event fires. Early-phase generation is not supported.
onServerStopping
Event:ServerLifecycleEvents.SERVER_STOPPINGWhen: Before the server begins its shutdown sequence
- Logs server shutdown
- Gracefully stops the
ChunkGenerationManager:- Stops the worker thread (with 5-second timeout)
- Saves all completed chunk tracking data to disk
- Shuts down Tellus integration if active
- Clears dimension state and pending tickets
- Clears all tracked players from
PlayerTracker
onPlayerJoin
Event:ServerPlayConnectionEvents.JOINWhen: After a player successfully connects and spawns
- Registers the player with
PlayerTrackerfor chunk generation prioritization - Sends a handshake packet to the client to enable LOD rendering
- Initializes per-player LOD sync tracking
- Worker thread will begin finding chunks near this player’s position
- Client receives initial LOD configuration and protocol version
- Player position begins influencing the generation priority queue
- Protocol version
- Server-side LOD radius
- Client capabilities negotiation
onPlayerDisconnect
Event:ServerPlayConnectionEvents.DISCONNECTWhen: After a player disconnects (gracefully or due to timeout)
- Removes the player from
PlayerTracker - Cleans up per-player LOD sync data
- Stops prioritizing chunks near the disconnected player
- If this was the last player, the worker will sleep longer between work checks
- Generation priority queue recalculates without this player’s position
- Per-player sync state is cleared (will need full resync on rejoin)
onServerTick
Event:ServerTickEvents.END_SERVER_TICKWhen: At the end of every server tick (50ms target, 20 tps)
ChunkGenerationManager.tick() which performs several critical maintenance tasks:
-
Process Pending Tickets /workspace/source/src/main/java/com/ethan/voxyworldgenv2/core/ChunkGenerationManager.java:499
- Apply queued chunk loading tickets
- Remove tickets for completed chunks
- Flush distance manager updates
-
Config Reload (if scheduled)
- Reload configuration from disk
- Adjust throttle capacity
- Restart chunk scanning with new settings
-
TPS Monitoring
- Track average TPS over the last 10 seconds
- Automatically throttle generation if TPS drops below configured threshold
-
Statistics Update
- Calculate chunks/second rate
- Update progress counters
- Prepare data for overlay UI
-
Player Movement Detection /workspace/source/src/main/java/com/ethan/voxyworldgenv2/core/ChunkGenerationManager.java:377
- Cache player positions in thread-safe maps
- Detect when players move ≥2 chunks (Manhattan distance)
- Trigger batch rescans when players change dimensions
- Switch active dimension based on player majority
-
LOD Update Broadcasting
- Process dirty chunks from
BlockUpdateMixin - Send LOD delta packets to clients
- Keep client-side LOD meshes synchronized with server changes
- Process dirty chunks from
- Most operations are O(n) where n = number of online players
- Dirty chunk processing is limited to active dimensions only
- Player movement checks use squared distance to avoid sqrt calculations
Event Lifecycle
Integration with ChunkGenerationManager
The event system serves as the primary interface between Minecraft’s lifecycle and Voxy World Gen’s chunk generation system:Startup Flow
Runtime Flow
Shutdown Flow
Thread Safety
Thread-Safe Operations
- Adding/removing players from
PlayerTracker(usesConcurrentHashMap) - Queueing ticket operations (uses
ConcurrentLinkedQueue) - Marking chunks complete (uses synchronized
LongSet)
Main-Thread-Only Operations
- Sending network packets
- Accessing player/level state
- Applying chunk tickets
- Processing dirty chunks
Custom Event Usage
If you’re building an addon that needs to hook into Voxy World Gen’s lifecycle:Related Documentation
- Mixins - Low-level hooks that events coordinate
- Distance Graph - The prioritization system driven by player positions
- Configuration - Settings that affect event-driven behavior
- Network Protocol - Handshake and LOD sync packets sent during events