World System Overview
World System Overview
Section titled “World System Overview”The World System manages the game universe, individual worlds, chunks, blocks, and lighting. It provides the spatial foundation for all gameplay.
Package Location
Section titled “Package Location”- Universe:
com.hypixel.hytale.server.core.universe.Universe - World:
com.hypixel.hytale.server.core.universe.world.World - WorldConfig:
com.hypixel.hytale.server.core.universe.world.WorldConfig - EntityStore:
com.hypixel.hytale.server.core.universe.world.storage.EntityStore - ChunkStore:
com.hypixel.hytale.server.core.universe.world.storage.ChunkStore
Architecture
Section titled “Architecture”┌─────────────────────────────────────────────────────────────────┐│ Universe ││ ┌────────────────────────────────────────────────────────────┐ ││ │ Worlds │ ││ │ ┌───────────────┐ ┌───────────────┐ ┌───────────────┐ │ ││ │ │ default │ │ nether │ │ custom │ │ ││ │ │ ┌───────────┐ │ │ ┌───────────┐ │ │ ┌───────────┐ │ │ ││ │ │ │EntityStore│ │ │ │EntityStore│ │ │ │EntityStore│ │ │ ││ │ │ └───────────┘ │ │ └───────────┘ │ │ └───────────┘ │ │ ││ │ │ ┌───────────┐ │ │ ┌───────────┐ │ │ ┌───────────┐ │ │ ││ │ │ │ChunkStore │ │ │ │ChunkStore │ │ │ │ChunkStore │ │ │ ││ │ │ └───────────┘ │ │ └───────────┘ │ │ └───────────┘ │ │ ││ │ │ ┌───────────┐ │ │ ┌───────────┐ │ │ ┌───────────┐ │ │ ││ │ │ │ Chunks │ │ │ │ Chunks │ │ │ │ Chunks │ │ │ ││ │ │ └───────────┘ │ │ └───────────┘ │ │ └───────────┘ │ │ ││ │ └───────────────┘ └───────────────┘ └───────────────┘ │ ││ └────────────────────────────────────────────────────────────┘ ││ ┌────────────────────────────────────────────────────────────┐ ││ │ Player Storage │ ││ └────────────────────────────────────────────────────────────┘ │└─────────────────────────────────────────────────────────────────┘Universe
Section titled “Universe”The Universe class is the top-level container for all worlds and player data.
Accessing the Universe
Section titled “Accessing the Universe”import com.hypixel.hytale.server.core.universe.Universe;
Universe universe = Universe.get();Key Methods
Section titled “Key Methods”| Method | Return Type | Description |
|---|---|---|
get() | Universe | Get the singleton universe instance |
getWorlds() | Map<String, World> | Get all loaded worlds |
getWorld(name) | World | Get world by name |
getWorld(uuid) | World | Get world by UUID |
getDefaultWorld() | World | Get the default world |
getPlayers() | List<PlayerRef> | Get all online players |
getPlayer(uuid) | PlayerRef | Get player by UUID |
getPlayerStorage() | PlayerStorage | Access player data storage |
World Management
Section titled “World Management”// Get all worldsMap<String, World> worlds = universe.getWorlds();
// Get specific worldWorld netherWorld = universe.getWorld("nether");
// Get default worldWorld defaultWorld = universe.getDefaultWorld();
// Check if world existsif (universe.getWorlds().containsKey("custom")) { // World exists}Player Access
Section titled “Player Access”// Get all online players across all worldsfor (PlayerRef player : universe.getPlayers()) { // Process each player}
// Find player by namePlayerRef player = universe.getPlayerByUsername("username", NameMatching.DEFAULT);Each World represents a separate game world with its own chunks, entities, and rules.
Accessing a World
Section titled “Accessing a World”// From UniverseWorld world = Universe.get().getWorld("default");
// From a player command contextWorld world = player.getWorld();
// From an entityWorld world = entity.getWorld();Key Properties
Section titled “Key Properties”| Property | Type | Description |
|---|---|---|
name | String | World’s unique name |
savePath | Path | Filesystem path for world data |
worldConfig | WorldConfig | World configuration |
entityStore | EntityStore | Entity ECS store |
chunkStore | ChunkStore | Chunk ECS store |
tick | long | Current world tick |
random | Random | World’s random generator |
World Methods
Section titled “World Methods”// Get world nameString name = world.getName();
// Get storesEntityStore entityStore = world.getEntityStore();ChunkStore chunkStore = world.getChunkStore();
// Get current ticklong tick = world.getTick();
// Check world stateboolean isTicking = world.isTicking();boolean isPaused = world.isPaused();
// Get world seedlong seed = world.getWorldConfig().getSeed();Player Management
Section titled “Player Management”// Get players in this worldCollection<PlayerRef> players = world.getPlayerRefs();
// Check player countint playerCount = world.getPlayerRefs().size();
// Send message to all playersworld.sendMessage(Message.raw("Hello everyone!"));Block Operations
Section titled “Block Operations”// Get block at positionint blockId = world.getBlock(x, y, z);BlockType blockType = world.getBlockType(x, y, z);
// Set blockworld.setBlock(x, y, z, blockType);
// With settingsSetBlockSettings settings = new SetBlockSettings() .withNotifyNeighbors(true) .withUpdateLighting(true);world.setBlock(x, y, z, blockType, settings);
// Check if position is loadedif (world.isChunkLoaded(chunkX, chunkZ)) { // Safe to access blocks}Chunk Operations
Section titled “Chunk Operations”// Get chunk at positionWorldChunk chunk = world.getChunk(chunkX, chunkZ);
// Get chunk containing block positionWorldChunk chunk = world.getChunkAt(blockX, blockZ);
// Check chunk stateboolean loaded = world.isChunkLoaded(chunkX, chunkZ);
// Load chunk asyncCompletableFuture<WorldChunk> future = world.loadChunkAsync(chunkX, chunkZ);World Configuration
Section titled “World Configuration”WorldConfig defines how a world behaves.
Key Configuration Options
Section titled “Key Configuration Options”| Option | Type | Description |
|---|---|---|
seed | long | World generation seed |
gameTime | long | Starting game time |
ticking | boolean | Whether world ticks |
worldGenProvider | IWorldGenProvider | World generator |
chunkStorageProvider | IChunkStorageProvider | Chunk storage type |
spawnProvider | ISpawnProvider | Spawn location logic |
gameplayConfig | GameplayConfig | Combat, death, gameplay rules |
World Generator Providers
Section titled “World Generator Providers”| Provider | Description |
|---|---|
FlatWorldGenProvider | Flat world generation |
VoidWorldGenProvider | Empty void world |
DummyWorldGenProvider | No generation |
Chunk Storage Providers
Section titled “Chunk Storage Providers”| Provider | Description |
|---|---|
DefaultChunkStorageProvider | Default file-based storage |
EmptyChunkStorageProvider | No persistence |
IndexedStorageChunkStorageProvider | Optimized indexed storage |
Spawn Providers
Section titled “Spawn Providers”| Provider | Description |
|---|---|
GlobalSpawnProvider | Single spawn point for all |
IndividualSpawnProvider | Per-player spawn points |
FitToHeightMapSpawnProvider | Spawn on terrain surface |
Entity Store & Chunk Store
Section titled “Entity Store & Chunk Store”Each world has two ECS stores:
EntityStore
Section titled “EntityStore”For world entities (players, mobs, items):
EntityStore entityStore = world.getEntityStore();Store<EntityStore> store = entityStore.getStore();
// Spawn entityHolder<EntityStore> holder = store.getRegistry().newHolder();holder.addComponent(positionType, new PositionComponent(x, y, z));Ref<EntityStore> ref = store.spawn(holder);
// Access entity componentsPositionComponent pos = store.getComponent(ref, positionType);ChunkStore
Section titled “ChunkStore”For chunk-level data:
ChunkStore chunkStore = world.getChunkStore();Store<ChunkStore> store = chunkStore.getStore();
// Access chunk componentsChunkComponent data = store.getComponent(chunkRef, chunkDataType);World Events
Section titled “World Events”World Lifecycle Events
Section titled “World Lifecycle Events”// World startinggetEventRegistry().register(StartWorldEvent.class, event -> { World world = event.getWorld(); // Initialize world-specific resources});
// World added to universegetEventRegistry().register(AddWorldEvent.class, event -> { World world = event.getWorld();});
// World removed from universegetEventRegistry().register(RemoveWorldEvent.class, event -> { World world = event.getWorld();});
// All worlds loadedgetEventRegistry().register(AllWorldsLoadedEvent.class, event -> { // Server fully initialized});Player World Events
Section titled “Player World Events”// Player added to worldgetEventRegistry().register(AddPlayerToWorldEvent.class, event -> { World world = event.getWorld(); PlayerRef player = event.getPlayerRef();});
// Player removed from worldgetEventRegistry().register(DrainPlayerFromWorldEvent.class, event -> { World world = event.getWorld(); PlayerRef player = event.getPlayerRef();});Chunk System
Section titled “Chunk System”Chunk Structure
Section titled “Chunk Structure”Chunks are 16x256x16 block columns divided into 16x16x16 sections:
Chunk Column (16 x 256 x 16)├── Section 0 (y: 0-15)├── Section 1 (y: 16-31)├── Section 2 (y: 32-47)│ ...└── Section 15 (y: 240-255)Chunk Coordinates
Section titled “Chunk Coordinates”// Convert block coords to chunk coordsint chunkX = Math.floorDiv(blockX, 16);int chunkZ = Math.floorDiv(blockZ, 16);
// Or use utilityint chunkX = ChunkUtil.blockToChunk(blockX);int chunkZ = ChunkUtil.blockToChunk(blockZ);
// Local position within chunk (0-15)int localX = blockX & 15;int localZ = blockZ & 15;Working with Chunks
Section titled “Working with Chunks”// Get chunkWorldChunk chunk = world.getChunk(chunkX, chunkZ);
// Check if chunk is generatedif (chunk != null && chunk.isGenerated()) { // Safe to read blocks}
// Load chunk asyncworld.loadChunkAsync(chunkX, chunkZ).thenAccept(chunk -> { // Chunk is now loaded});Block Operations
Section titled “Block Operations”Block Types
Section titled “Block Types”// Get block type by IDBlockType blockType = BlockType.getAssetMap().get("Rock_Stone");
// Get block type at positionBlockType type = world.getBlockType(x, y, z);
// Get block IDint blockId = world.getBlock(x, y, z);Setting Blocks
Section titled “Setting Blocks”// Simple setworld.setBlock(x, y, z, blockType);
// With custom settingsSetBlockSettings settings = new SetBlockSettings();settings.setNotifyNeighbors(true);settings.setUpdateLighting(true);settings.setTriggerBlockUpdate(true);
world.setBlock(x, y, z, blockType, settings);Block States
Section titled “Block States”Block states provide additional block data:
// Get block stateBlockState state = world.getBlockState(x, y, z);
// Check state propertiesif (state.hasProperty("powered")) { boolean powered = state.getBoolean("powered");}Lighting System
Section titled “Lighting System”The lighting system handles both sky and block light:
// Get light level at positionint skyLight = world.getSkyLight(x, y, z);int blockLight = world.getBlockLight(x, y, z);int combinedLight = world.getLight(x, y, z);
// Lighting is updated automatically when blocks changeRunning Tasks on World Thread
Section titled “Running Tasks on World Thread”Worlds run on their own thread. Schedule tasks appropriately:
// Execute on world threadworld.execute(() -> { // This runs on the world's thread world.setBlock(x, y, z, blockType);});
// Or use CompletableFutureCompletableFuture.runAsync(() -> { // World thread operations}, world);Best Practices
Section titled “Best Practices”- Check chunk loading: Always verify chunks are loaded before block access
- Use async loading: Load chunks asynchronously to avoid blocking
- Run on correct thread: World operations must run on the world’s thread
- Cache block types: Store BlockType references, don’t look up repeatedly
- Batch operations: Group multiple block changes when possible
Related
Section titled “Related”- ECS Overview - Entity Component System
- Entity System - Entity management
- Block Types - Block type assets