[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / content/world/serverSource

# content/world/serverSource

## Interfaces

### ServerWorldHandle

Defined in: [packages/prismarine/src/content/world/serverSource.ts:347](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L347)

The world source, plus the one member of it the interaction path reaches past the adapter for.

`targetOf` answers a question about an interaction in progress, so the code that runs the
interaction has to be able to say what it landed on. That is the port rather than the adapter,
and `ServerWorldAdapter` has nowhere to put it: the content packages must not be able to record
a target for themselves.

#### Extends

- [`ServerWorldSource`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#serverworldsource)

#### Methods

##### actorsAt()

> **actorsAt**(`dimension`, `level?`): [`ServerItemActorPort`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/actorPort/index.md#serveritemactorport)

Defined in: [packages/prismarine/src/content/world/serverSource.ts:363](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L363)

The item actor port of one world; see [ServerItemActorPort.duringInteraction](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/actorPort/index.md#duringinteraction).

###### Parameters

###### dimension

`string`

The namespaced dimension identifier.

###### level?

`string`

The level's name, or undefined for the default level.

###### Returns

[`ServerItemActorPort`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/actorPort/index.md#serveritemactorport)

##### at()

> **at**(`dimension`, `level?`): [`ServerWorldAdapter`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#serverworldadapter)

Defined in: [packages/prismarine/src/content/world/serverSource.ts:357](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L357)

The adapter for one world.

The content packages call this with a dimension alone and so reach the default level. A
world of another `worlds.<name>` entry passes its level, so its blocks, random stream and
entity runtime are its own rather than the default level's.

###### Parameters

###### dimension

`string`

The namespaced dimension identifier, such as `minecraft:overworld`.

###### level?

`string`

The level's name, or undefined for the default level.

###### Returns

[`ServerWorldAdapter`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#serverworldadapter)

###### Overrides

[`ServerWorldSource`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#serverworldsource).[`at`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#at-1)

##### closeLevel()

> **closeLevel**(`level`): `void`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:377](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L377)

Forgets the adapters and entity runtimes of a level that has unloaded, once its save is
written, so the level loaded again under that name starts from what the save holds rather
than from the entities and draws of the instance before it.

###### Parameters

###### level

`string`

The level's name.

###### Returns

`void`

##### entitiesAt()

> **entitiesAt**(`dimension`, `level?`): [`LiveEntityRuntime`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/data/live/classes/LiveEntityRuntime.md) \| `undefined`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:370](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L370)

The entity runtime of one world, or undefined when its adapter was not built yet or the
source runs no data-driven entities. Builds nothing.

###### Parameters

###### dimension

`string`

The namespaced dimension identifier.

###### level?

`string`

The level's name, or undefined for the default level.

###### Returns

[`LiveEntityRuntime`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/data/live/classes/LiveEntityRuntime.md) \| `undefined`

##### goalWorld()?

> `optional` **goalWorld**(`entity`): [`GoalWorld`](https://jsprismarine.dev/api/@jsprismarine/entity-goals/index.md#goalworld) \| `undefined`

Defined in: [packages/prismarine/src/content/world/adapter.ts:609](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/adapter.ts#L609)

Resolves a goal world from the runtime that owns this entity, when the source can see
every dimension. This avoids binding entities in secondary dimensions to `at()`'s
default adapter.

###### Parameters

###### entity

[`EntityInstance`](https://jsprismarine.dev/api/@jsprismarine/entities/classes/EntityInstance.md)

###### Returns

[`GoalWorld`](https://jsprismarine.dev/api/@jsprismarine/entity-goals/index.md#goalworld) \| `undefined`

###### Inherited from

[`ServerWorldSource`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#serverworldsource).[`goalWorld`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#goalworld-1)

##### restoreRandomStates()

> **restoreRandomStates**(`states`): `void`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:384](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L384)

Restores exactly the adapter streams represented by a replay state.

###### Parameters

###### states

`unknown`

###### Returns

`void`

##### saveRandomStates()

> **saveRandomStates**(): readonly (readonly \[`string`, [`SeededRandomState`](https://jsprismarine.dev/api/@jsprismarine/predicates/index.md#seededrandomstate)\])[]

Defined in: [packages/prismarine/src/content/world/serverSource.ts:382](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L382)

Captures the seeded random stream of each content adapter already built, under its
`worldKeyOf` key, which for the default level is the bare dimension.

###### Returns

readonly (readonly \[`string`, [`SeededRandomState`](https://jsprismarine.dev/api/@jsprismarine/predicates/index.md#seededrandomstate)\])[]

***

### ServerWorldSourceOptions

Defined in: [packages/prismarine/src/content/world/serverSource.ts:41](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L41)

What [serverWorldSource](#serverworldsource) is built over.

#### Properties

##### content

> `readonly` **content**: [`ContentLookup`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/views/index.md#contentlookup)

Defined in: [packages/prismarine/src/content/world/serverSource.ts:49](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L49)

The built content, read at call time; see [ContentLookup](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/views/index.md#contentlookup).

##### entityRuntimes?

> `readonly` `optional` **entityRuntimes?**: [`EntityRuntimes`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/data/live/classes/EntityRuntimes.md)

Defined in: [packages/prismarine/src/content/world/serverSource.ts:75](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L75)

The server's data-driven entity runtimes.

Supplied by a server that runs its entities through
`@jsprismarine/entities` rather than through the written classes. One
runtime is opened per world as that world's adapter is assembled,
because the `spawning` and `ai` groups are projections of it.
Left out, and those two groups stay absent and every member of them says
which subsystem owes it.

##### random?

> `readonly` `optional` **random?**: [`RandomSource`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#randomsource)

Defined in: [packages/prismarine/src/content/world/serverSource.ts:64](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L64)

Replaces the random draws, which is how a test drives a probabilistic rule either way.

##### seed

> `readonly` **seed**: `bigint`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:54](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L54)

The default level's world seed, which `level.seed` reports and which seeds the default
random source.

#### Methods

##### defaultLevel()?

> `optional` **defaultLevel**(): `string` \| `undefined`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:83](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L83)

The default level's name. A caller that names it reaches the same world as one that
passes no level, which is how the content packages address it.

Left out, and the source serves one level: whatever level a caller names, it reaches the
default level's worlds, so a test's world double and its level double are one world.

###### Returns

`string` \| `undefined`

##### difficulty()

> **difficulty**(): `number`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:62](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L62)

The configured difficulty, as the protocol numbers it.

###### Returns

`number`

##### seedOf()?

> `optional` **seedOf**(`level`): `bigint`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:60](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L60)

The seed of a level other than the default, for its adapters' `level.seed` and random
source. Left out, every level reports [seed](#seed).

###### Parameters

###### level

`string`

The level's name.

###### Returns

`bigint`

##### worldFor()

> **worldFor**(`dimension`, `level?`): [`World`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/World/classes/World.md) \| `undefined`

Defined in: [packages/prismarine/src/content/world/serverSource.ts:47](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L47)

The live world of one dimension, or undefined when none of it is loaded.

###### Parameters

###### dimension

`string`

The namespaced dimension identifier.

###### level?

`string`

The level's name, or undefined for the default level.

###### Returns

[`World`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/World/classes/World.md) \| `undefined`

## Variables

### BLOCK\_SOUND\_EVENTS

> `const` **BLOCK\_SOUND\_EVENTS**: `Readonly`\<`Record`\<[`ContentBlockSound`](https://jsprismarine.dev/api/@jsprismarine/prismarine/content/world/adapter/index.md#contentblocksound), [`LevelSoundEvent`](https://jsprismarine.dev/api/@jsprismarine/minecraft/index.md#levelsoundevent)\>\>

Defined in: [packages/prismarine/src/content/world/serverSource.ts:95](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L95)

The level sound event each block sound is, which the client plays in the block's material.

#### Bds See

toggle-door

#### Bds See

toggle-trapdoor

#### Bds See

toggle-fence-gate

#### Bds See

press-button

#### Bds See

step-on-pressure-plate

## Functions

### serverWorldSource()

> **serverWorldSource**(`options`): [`ServerWorldHandle`](#serverworldhandle)

Defined in: [packages/prismarine/src/content/world/serverSource.ts:394](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/content/world/serverSource.ts#L394)

The world the content packages act through on a running server.

#### Parameters

##### options

[`ServerWorldSourceOptions`](#serverworldsourceoptions)

#### Returns

[`ServerWorldHandle`](#serverworldhandle)

A source that hands out one adapter per world, built on first use and kept, so the
  block group's neighbor-update budget and the item cooldowns of a world outlive the call that
  made them.
