hytopia
Version:
The HYTOPIA SDK makes it easy for developers to create massively multiplayer games using JavaScript or TypeScript.
821 lines (364 loc) • 10.4 kB
Markdown
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) > [server](./server.md) > [World](./server.world.md)
## World class
Represents an isolated simulation space (a world) on the server.
When to use: your primary container for game objects, physics, and players. Use multiple worlds to run separate rooms, arenas, or instances. Do NOT use for: cross-world global state; keep that in your own services or `GameServer`<!-- -->.
**Signature:**
```typescript
export default class World extends EventRouter implements protocol.Serializable
```
**Extends:** [EventRouter](./server.eventrouter.md)
**Implements:** protocol.Serializable
## Remarks
Prefer creating worlds via `WorldManager.createWorld` or `WorldManager.getDefaultWorld` so IDs and lifecycle are managed consistently.
Initialization: - Call `World.start` to begin ticking (auto-started when created by `WorldManager`<!-- -->). - Use `set*` methods for runtime lighting or skybox changes.
<h2>Events</h2>
This class is an EventRouter, and instances of it emit events with payloads listed under `WorldEventPayloads`<!-- -->.
## Example
```typescript
const world = WorldManager.instance.createWorld({
name: 'My World',
skyboxUri: 'skyboxes/partly-cloudy',
});
```
\*\*Category:\*\* Core
## Constructors
<table><thead><tr><th>
Constructor
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[(constructor)(options)](./server.world._constructor_.md)
</td><td>
</td><td>
Creates a world instance with the provided options.
Use for: direct construction only when you need custom lifecycle control. Do NOT use for: routine world creation; prefer `WorldManager.createWorld`<!-- -->.
</td></tr>
</tbody></table>
## Properties
<table><thead><tr><th>
Property
</th><th>
Modifiers
</th><th>
Type
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[ambientLightColor](./server.world.ambientlightcolor.md)
</td><td>
`readonly`
</td><td>
[RgbColor](./server.rgbcolor.md)
</td><td>
The color of the ambient light.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[ambientLightIntensity](./server.world.ambientlightintensity.md)
</td><td>
`readonly`
</td><td>
number
</td><td>
The intensity of the ambient light.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[audioManager](./server.world.audiomanager.md)
</td><td>
`readonly`
</td><td>
[AudioManager](./server.audiomanager.md)
</td><td>
The audio manager for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[blockTypeRegistry](./server.world.blocktyperegistry.md)
</td><td>
`readonly`
</td><td>
[BlockTypeRegistry](./server.blocktyperegistry.md)
</td><td>
The block type registry for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[chatManager](./server.world.chatmanager.md)
</td><td>
`readonly`
</td><td>
[ChatManager](./server.chatmanager.md)
</td><td>
The chat manager for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[chunkLattice](./server.world.chunklattice.md)
</td><td>
`readonly`
</td><td>
[ChunkLattice](./server.chunklattice.md)
</td><td>
The chunk lattice for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[directionalLightColor](./server.world.directionallightcolor.md)
</td><td>
`readonly`
</td><td>
[RgbColor](./server.rgbcolor.md)
</td><td>
The color of the directional light.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[directionalLightIntensity](./server.world.directionallightintensity.md)
</td><td>
`readonly`
</td><td>
number
</td><td>
The intensity of the directional light.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[directionalLightPosition](./server.world.directionallightposition.md)
</td><td>
`readonly`
</td><td>
[Vector3Like](./server.vector3like.md)
</td><td>
The position the directional light originates from (relative to the camera).
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[entityManager](./server.world.entitymanager.md)
</td><td>
`readonly`
</td><td>
[EntityManager](./server.entitymanager.md)
</td><td>
The entity manager for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[fogColor](./server.world.fogcolor.md)
</td><td>
`readonly`
</td><td>
[RgbColor](./server.rgbcolor.md) \| undefined
</td><td>
The fog color, or undefined to use ambient light color.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[fogFar](./server.world.fogfar.md)
</td><td>
`readonly`
</td><td>
number
</td><td>
The maximum distance from the camera at which fog stops being applied.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[fogNear](./server.world.fognear.md)
</td><td>
`readonly`
</td><td>
number
</td><td>
The minimum distance from the camera to start applying fog.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[id](./server.world.id.md)
</td><td>
`readonly`
</td><td>
number
</td><td>
The unique ID of the world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[loop](./server.world.loop.md)
</td><td>
`readonly`
</td><td>
[WorldLoop](./server.worldloop.md)
</td><td>
The world loop that drives ticking for this world.
</td></tr>
<tr><td>
[name](./server.world.name.md)
</td><td>
`readonly`
</td><td>
string
</td><td>
The name of the world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[particleEmitterManager](./server.world.particleemittermanager.md)
</td><td>
`readonly`
</td><td>
[ParticleEmitterManager](./server.particleemittermanager.md)
</td><td>
The particle emitter manager for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[sceneUIManager](./server.world.sceneuimanager.md)
</td><td>
`readonly`
</td><td>
[SceneUIManager](./server.sceneuimanager.md)
</td><td>
The scene UI manager for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[simulation](./server.world.simulation.md)
</td><td>
`readonly`
</td><td>
[Simulation](./server.simulation.md)
</td><td>
The physics simulation for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[skyboxIntensity](./server.world.skyboxintensity.md)
</td><td>
`readonly`
</td><td>
number
</td><td>
The intensity of the world's skybox brightness.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[skyboxUri](./server.world.skyboxuri.md)
</td><td>
`readonly`
</td><td>
string
</td><td>
The URI of the skybox cubemap for this world.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[tag](./server.world.tag.md)
</td><td>
`readonly`
</td><td>
string \| undefined
</td><td>
An arbitrary identifier tag for your own logic.
\*\*Category:\*\* Core
</td></tr>
</tbody></table>
## Methods
<table><thead><tr><th>
Method
</th><th>
Modifiers
</th><th>
Description
</th></tr></thead>
<tbody><tr><td>
[loadMap(map)](./server.world.loadmap.md)
</td><td>
</td><td>
Loads a map into the world, replacing any prior map contents.
Use for: initializing or fully resetting a world from serialized map data. Do NOT use for: incremental edits while players are actively interacting with the world.
</td></tr>
<tr><td>
[setAmbientLightColor(color)](./server.world.setambientlightcolor.md)
</td><td>
</td><td>
Sets the color of the world's ambient light.
</td></tr>
<tr><td>
[setAmbientLightIntensity(intensity)](./server.world.setambientlightintensity.md)
</td><td>
</td><td>
Sets the intensity of the world's ambient light.
</td></tr>
<tr><td>
[setDirectionalLightColor(color)](./server.world.setdirectionallightcolor.md)
</td><td>
</td><td>
Sets the color of the world's directional light.
</td></tr>
<tr><td>
[setDirectionalLightIntensity(intensity)](./server.world.setdirectionallightintensity.md)
</td><td>
</td><td>
Sets the intensity of the world's directional light.
</td></tr>
<tr><td>
[setDirectionalLightPosition(position)](./server.world.setdirectionallightposition.md)
</td><td>
</td><td>
Sets the position the world's directional light originates from relative to a player's camera.
</td></tr>
<tr><td>
[setFogColor(color)](./server.world.setfogcolor.md)
</td><td>
</td><td>
Sets the color of the world's fog.
</td></tr>
<tr><td>
[setFogFar(far)](./server.world.setfogfar.md)
</td><td>
</td><td>
Sets the maximum distance from the camera at which fog stops being applied.
</td></tr>
<tr><td>
[setFogNear(near)](./server.world.setfognear.md)
</td><td>
</td><td>
Sets the minimum distance from the camera to start applying fog.
</td></tr>
<tr><td>
[setSkyboxIntensity(intensity)](./server.world.setskyboxintensity.md)
</td><td>
</td><td>
Sets the intensity of the world's skybox brightness.
</td></tr>
<tr><td>
[setSkyboxUri(skyboxUri)](./server.world.setskyboxuri.md)
</td><td>
</td><td>
Sets the cubemap URI of the world's skybox.
</td></tr>
<tr><td>
[start()](./server.world.start.md)
</td><td>
</td><td>
Starts the world loop, which begins ticking physics, entities, and networking.
Use for: resuming a previously stopped world. Do NOT use for: standard world creation when using `WorldManager.createWorld` (it auto-starts).
\*\*Side effects:\*\* Emits `WorldEvent.START`<!-- -->.
\*\*Category:\*\* Core
</td></tr>
<tr><td>
[stop()](./server.world.stop.md)
</td><td>
</td><td>
Stops the world loop, pausing physics, entities, and networking ticks.
Use for: pausing a world or preparing for a full map reset. Do NOT use for: disconnecting players; they remain assigned to this world.
\*\*Side effects:\*\* Emits `WorldEvent.STOP`<!-- -->.
\*\*Category:\*\* Core
</td></tr>
</tbody></table>