Overview
Voxy World Gen V2 is built around a multi-threaded chunk generation system that runs alongside the Minecraft server, generating chunks asynchronously without blocking the main server thread. The architecture emphasizes performance through intelligent work distribution, TPS-aware throttling, and efficient state management.Core Architecture
Worker Thread Model
The system runs a dedicated background worker thread that continuously searches for and dispatches chunk generation work:- Detects player positions across all dimensions
- Finds missing chunks using the DistanceGraph
- Acquires semaphore permits to control parallelism
- Dispatches generation tasks to the server thread
- Handles completion and cleanup
Dimension State Management
Each dimension maintains isolated state through theDimensionState class:
completedChunks- Chunks fully generated and saved to the persistence cachetrackedChunks- Chunks currently being processed (prevents duplicate work)distanceGraph- Hierarchical spatial index for efficient work discoverytrackedBatches- 4x4 batch tracking to prevent concurrent batch processingtellusActive- Flag for Tellus integration (Earth-scale terrain)
Ticket System
Voxy uses Minecraft’s chunk ticket system to force-load chunks during generation:- Added before chunk generation starts
- Removed immediately after generation completes
- Applied in batches to minimize DistanceManager updates
Component Relationships
ChunkGenerationManager
Central orchestrator that:- Manages the worker thread lifecycle
- Coordinates dimension state
- Handles player movement detection
- Controls task throttling via semaphore
- Processes ticket operations
PlayerTracker
Tracks online players and their LOD sync state:- Active player set (ConcurrentHashMap.newKeySet())
- Per-player synced chunks (tracks which LOD data has been sent)
- Thread-safe access for worker and server threads
NetworkHandler
Handles client-server communication for LOD data:HandshakePayload- Server mod presence signalLODDataPayload- Chunk section data (states, biomes, block/sky light)
VoxyIntegration
Dynamic integration with the Voxy mod (LOD rendering) using reflection:- Automatic method discovery (handles API changes)
ingestChunk()- Standard chunk ingestionrawIngest()- Direct section-level ingestion for Tellus
TellusIntegration
Optional integration for Earth-scale terrain generation (Tellus mod):- Uses dedicated worker pool for terrain sampling
- Bypasses normal Minecraft generation
- Directly ingests voxel data into Voxy
- Supports large generation radius (128+ chunks)
Lifecycle
Initialization
- Config loaded (Config.java:19-38)
- Network handlers registered (NetworkHandler.java:86-93)
- ChunkGenerationManager initialized
- Worker thread started
- Semaphore created with
maxActiveTaskspermits
Server Tick
Every tick (ChunkGenerationManager.java:352-375):- Process pending ticket operations
- Reload config if scheduled
- Update TPS monitor
- Update generation stats
- Check player movement and trigger rescans
- Broadcast chunk updates via NetworkHandler
Shutdown
- Stop worker thread (5 second grace period)
- Shutdown Tellus worker pool
- Clear LOD tracker
- Save all dimension generation progress
- Clear all state
Thread Safety
The system operates across multiple threads: Worker Thread:- Reads player positions from cached maps (ChunkGenerationManager.java:73-74)
- Searches DistanceGraph for work
- Acquires semaphore permits
- Queues work to server thread
- Processes ticket operations
- Executes chunk generation
- Updates player tracking
- Broadcasts network packets
- Chunk save interception (ChunkSaveMixin.java:32-55)
- Thread-safe player proximity checks
AtomicBoolean,AtomicInteger,AtomicLongfor flags and countersConcurrentHashMapfor shared stateLongSets.synchronize()for chunk position setsSemaphorefor task throttlingsynchronizedblocks for DistanceGraph updates
The architecture carefully avoids main-thread blocking and maintains compatibility with performance mods like C2ME through deferred ticket operations and thread-safe state access.