Overview
WorldService encapsulates all temporary world management for speedruns. It integrates with the Fantasy library to create and delete temporary dimensions (Overworld, Nether, End) on-demand without affecting the server’s main worlds.
Location: src/main/java/net/zenzty/soullink/server/run/WorldService.java
Fantasy Library Integration
What is Fantasy?
Fantasy is a library for Minecraft Fabric servers that enables creating and managing temporary dimensions at runtime. Unlike vanilla Minecraft where dimensions are permanent, Fantasy allows:- Creating worlds with custom seeds and settings
- Deleting worlds when no longer needed
- Managing multiple temporary dimension sets simultaneously
Obtaining Fantasy Instance
WorldService.java:21-42
World Handle Management
WorldService maintains handles to both current and old world sets:
WorldService.java:26-37
The dual handle system allows for smooth transitions:
- Save current worlds as “old”
- Create new worlds
- Teleport players to new worlds
- Delete old worlds
Creating Temporary Worlds
ThecreateTemporaryWorlds() method creates all three dimensions:
WorldService.java:49-95
Key Configuration Points
- Shared Seed: All three dimensions use the same seed for consistency
- Difficulty: Respects server settings (configurable via
/settings difficulty) - Time Advance: Enabled for Overworld (time progresses during the run)
- Generators: Uses vanilla chunk generators from the main worlds
RuntimeWorldConfig
Fantasy’sRuntimeWorldConfig allows configuring:
setDimensionType()- Which dimension type (Overworld/Nether/End)setDifficulty()- Peaceful, Easy, Normal, HardsetSeed()- World generation seedsetGenerator()- Chunk generator (vanilla or custom)setGameRule()- Individual game rule overrides
World Lifecycle
Saving Current Worlds as Old
Before creating new worlds, save existing ones for later cleanup:WorldService.java:101-108
Deleting Old Worlds
After players are teleported to new worlds, delete the old ones:WorldService.java:124-133,110-119
Deleting Current Worlds
When ending a run or shutting down:WorldService.java:138-147
World Access Methods
Getting ServerWorld Instances
WorldService.java:166-176
These methods convert Fantasy’s RuntimeWorldHandle to Minecraft’s ServerWorld for use with vanilla APIs.
Getting Registry Keys
WorldService.java:178-188
Registry keys uniquely identify worlds and are used for:
- Checking if a player is in a temporary world
- Portal linking between dimensions
- World-specific game logic
Checking Temporary Worlds
WorldService.java:152-162
This method determines if a given world is part of the current speedrun.
Portal Linking
For Nether portal travel between temporary dimensions:WorldService.java:197-210
This ensures portals link between temporary Overworld and Nether, not to vanilla worlds.
Error Handling
All world deletion operations use safe wrappers:- Try-catch blocks prevent crashes from deletion failures
- Null checks prevent errors when worlds don’t exist
- Logging provides visibility into world lifecycle events
Performance Considerations
Why Delete Old Worlds?
World deletion is crucial for:- Memory management - Unloaded worlds still consume memory
- Disk space - World data accumulates quickly
- Performance - Too many loaded worlds impact server tick rate
Why Wait to Delete?
The two-step deletion (save as old → delete old) prevents:- Players being forcibly kicked mid-teleport
- Chunks unloading before players finish loading new world
- Race conditions between teleport and world deletion