5 min

Worlds & Universe

Access worlds, spawn entities, and manage the game universe.

Universe

Universe is a singleton that manages all worlds and players:

1import com.hypixel.hytale.server.core.universe.Universe;
2
3Universe universe = Universe.get();
4
5// Get all worlds
6Map<String, World> worlds = universe.getWorlds();
7
8// Get specific world by name
9World world = universe.getWorld("default");
10
11// Get default world
12World defaultWorld = universe.getDefaultWorld();
13
14// Get all players across all worlds
15List allPlayers = universe.getPlayers();
16
17// Get player by UUID
18PlayerRef player = universe.getPlayer(uuid);
19
20// Get player count
21int count = universe.getPlayerCount();

World

Basic Info

1World world = player.getWorld();
2
3// World properties
4String name = world.getName();
5long tick = world.getTick();
6boolean alive = world.isAlive();
7boolean paused = world.isPaused();
8
9// Players in this world
10List<Player> players = world.getPlayers();
11int playerCount = world.getPlayerCount();

Thread-Safe Execution

1// Execute code on the world thread (REQUIRED for entity modifications)
2world.execute(() -> {
3 player.setModel("Mouse");
4 // ... other entity modifications
5});
critical
All entity modifications MUST be wrapped in world.execute(). See Threading Model.

Spawning Entities

1World world = player.getWorld();
2
3// Spawn position and rotation
4Vector3d position = new Vector3d(100.0, 64.0, 100.0);
5Vector3f rotation = new Vector3f(0f, 0f, 0f);
6
7// Spawn entity (must be on world thread)
8world.execute(() -> {
9 Entity entity = world.spawnEntity(myEntity, position, rotation);
10});

Managing Worlds

1Universe universe = Universe.get();
2
3// Add/load world (returns CompletableFuture)
4CompletableFuture<World> future = universe.addWorld("myworld");
5future.thenAccept(world -> {
6 // World is ready
7});
8
9// Check if world can be loaded
10boolean loadable = universe.isWorldLoadable("myworld");
11
12// Remove world
13universe.removeWorld("myworld");

Broadcasting

1Universe universe = Universe.get();
2
3// Broadcast packet to ALL players on server
4universe.broadcastPacket(myPacket);
5
6// Broadcast to specific world only
7World world = universe.getWorld("default");
8for (Player p : world.getPlayers()) {
9 p.getPlayerConnection().write(myPacket);
10}

World Events

Each world has its own EventRegistry:

1World world = universe.getWorld("default");
2EventRegistry registry = world.getEventRegistry();
3
4// Register world-specific events
5registry.register(SomeEvent.class, event -> {
6 // Only fires for this world
7});

Moving Players Between Worlds

1Universe universe = Universe.get();
2World targetWorld = universe.getWorld("minigame");
3
4// Add player to world (returns CompletableFuture)
5PlayerRef playerRef = player.getPlayerRef();
6CompletableFuture future = targetWorld.addPlayer(playerRef);
7
8// With specific spawn position
9Transform spawn = new Transform(new Vector3d(0, 64, 0), ...);
10targetWorld.addPlayer(playerRef, spawn);