94 lines
2.3 KiB
Markdown
94 lines
2.3 KiB
Markdown
---
|
|
title: Universe & Worlds
|
|
type: docs
|
|
weight: 1
|
|
---
|
|
|
|
## Universe
|
|
|
|
The Universe is a singleton managing all worlds:
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.universe.Universe;
|
|
import com.hypixel.hytale.server.core.universe.world.World;
|
|
import java.util.Map;
|
|
|
|
Universe universe = Universe.get();
|
|
|
|
// Get specific world
|
|
World world = universe.getWorld("default");
|
|
|
|
// Get all worlds
|
|
Map<String, World> worlds = universe.getWorlds();
|
|
|
|
// Check if world exists (hasWorld doesn't exist - use null check)
|
|
if (universe.getWorld("creative") != null) {
|
|
// World exists
|
|
}
|
|
```
|
|
|
|
## World
|
|
|
|
Each world contains chunks, entities, and players:
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.entity.entities.Player;
|
|
import com.hypixel.hytale.server.core.universe.PlayerRef;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
|
|
World world = Universe.get().getWorld("default");
|
|
|
|
// Get world name
|
|
String name = world.getName();
|
|
|
|
// Get all players (returns List<Player>)
|
|
List<Player> players = world.getPlayers();
|
|
|
|
// Get player refs
|
|
Collection<PlayerRef> playerRefs = world.getPlayerRefs();
|
|
```
|
|
|
|
{{< callout type="warning" >}}
|
|
**Note:** `world.getEntities()` does not exist on World. Entities are managed through the EntityStore component system.
|
|
{{< /callout >}}
|
|
|
|
## World Operations
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.asset.type.blocktype.config.BlockType;
|
|
import com.hypixel.hytale.math.vector.Vector3i;
|
|
|
|
// Get block at position
|
|
BlockType blockType = world.getBlockType(x, y, z);
|
|
BlockType blockType = world.getBlockType(new Vector3i(x, y, z));
|
|
|
|
// Set block (takes String block type key, not BlockType)
|
|
world.setBlock(x, y, z, "stone");
|
|
|
|
// If you have a BlockType, use getId()
|
|
if (blockType != null) {
|
|
world.setBlock(x, y, z, blockType.getId());
|
|
}
|
|
```
|
|
|
|
{{< callout type="info" >}}
|
|
**Note:** `world.getSpawnPoint()` does not exist directly on World. Spawn configuration is accessed via `world.getWorldConfig().getSpawnProvider()`.
|
|
{{< /callout >}}
|
|
|
|
## World from Player Events
|
|
|
|
```java
|
|
import com.hypixel.hytale.server.core.event.events.player.PlayerConnectEvent;
|
|
import java.util.logging.Level;
|
|
|
|
getEventRegistry().register(PlayerConnectEvent.class, event -> {
|
|
PlayerRef playerRef = event.getPlayerRef();
|
|
World world = event.getWorld(); // Can be null!
|
|
|
|
if (world != null) {
|
|
getLogger().at(Level.INFO).log("Player joined world: " + world.getName());
|
|
}
|
|
});
|
|
```
|