Overview
TheVoxyIntegration class provides a reflection-based API to integrate with the Voxy mod for Level-of-Detail (LOD) chunk rendering. It dynamically detects and invokes Voxy’s VoxelIngestService methods without requiring compile-time dependencies.
This integration uses Java’s MethodHandle API for high-performance reflection and supports both high-level chunk ingestion and low-level section-based ingestion with custom lighting data.
Package: com.ethan.voxyworldgenv2.integration
Reflection-Based Approach
The integration uses reflection to:- Detect if Voxy is present at runtime (
me.cortex.voxy.common.world.service.VoxelIngestService) - Resolve method handles for
ingestChunk,tryAutoIngestChunk,enqueueIngest, oringestmethods - Resolve
rawIngestmethod for low-level section ingestion - Bind instance methods to the
INSTANCEsingleton if available
Methods
ingestChunk
Ingests a full chunk into Voxy’s LOD system using the high-level ingestion method.The Minecraft chunk to ingest into Voxy’s LOD system
- Automatically initializes the integration on first call
- Returns silently if Voxy is not available or integration failed
- Uses the first available method from:
ingestChunk,tryAutoIngestChunk,enqueueIngest, oringest - Logs errors if invocation fails
rawIngest (Chunk-based)
Ingests a chunk into Voxy’s LOD system with custom sky lighting data, processing all non-empty sections.The chunk containing sections to ingest
Custom sky light data to use for all sections (block light will be null)
- Iterates through all chunk sections
- Skips null or air-only sections
- Calls the low-level
rawIngestmethod for each section - Resolves the
WorldIdentifieronce per chunk for efficiency - Returns silently if
rawIngestmethod handle is unavailable
rawIngest (Section-based)
Ingests a single chunk section with full control over lighting data.The world/level containing the section
The 16×16×16 chunk section to ingest
Chunk X coordinate
Chunk section Y coordinate (vertical section index)
Chunk Z coordinate
Block light data (e.g., from torches, lava). Pass
null to use default lightingSky light data (e.g., from sunlight). Pass
null to use default lighting- Resolves the
WorldIdentifierfrom the level - Invokes Voxy’s low-level
rawIngestmethod with exact parameters - Returns silently if method handles are unavailable
- Logs errors on invocation failure
rawIngest with blockLight = null.
isVoxyAvailable
Checks if Voxy is available and the integration was successfully initialized.true if Voxy is present and at least the basic ingestChunk method was resolved, false otherwise- Triggers initialization on first call
- Returns
trueonly if the high-level ingest method handle was successfully created - Does not guarantee that
rawIngestis available (use cautiously if relying on raw ingestion)
Implementation Details
Initialization Process
The integration initializes lazily on the first API call:- Class Detection: Attempts to load
me.cortex.voxy.common.world.service.VoxelIngestService - Instance Resolution: Looks for a static
INSTANCEfield - Method Resolution: Searches for ingest methods in priority order:
ingestChunk(LevelChunk)tryAutoIngestChunk(LevelChunk)enqueueIngest(LevelChunk)ingest(LevelChunk)
- Raw Ingest Resolution: Attempts to resolve
rawIngest(WorldIdentifier, LevelChunkSection, int, int, int, DataLayer, DataLayer) - WorldIdentifier Resolution: Resolves
WorldIdentifier.of(Level)for world identification
Thread Safety
The integration is thread-safe after initialization:- Initialization is guarded by an
initializedflag MethodHandleinstances are immutable after creation- Multiple threads can safely call API methods concurrently
Error Handling
All methods fail gracefully:- Missing Voxy classes log an info message and disable integration
- Method invocation errors are logged at ERROR level
- No exceptions propagate to calling code
Source Reference
SeeVoxyIntegration.java:12-142 for the complete implementation.