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

# world/SpawnPlacement

## Interfaces

### BodyBox

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:94](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L94)

The size of a body: centered on its position and extending up from the feet.

#### Properties

##### height

> `readonly` **height**: `number`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:96](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L96)

##### width

> `readonly` **width**: `number`

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

***

### PlayerSpawn

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:32](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L32)

Where a player is put, as feet positions on block centers.

#### Properties

##### position

> `readonly` **position**: [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:36](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L36)

Where the player actually starts.

##### relocated

> `readonly` **relocated**: `boolean`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:38](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L38)

Whether the requested spot was rejected and the player moved to another column.

##### requested

> `readonly` **requested**: [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:34](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L34)

Where the spawn point says, before the terrain is consulted.

***

### SpawnTerrain

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:20](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L20)

What placing a spawn needs to know about the world.

#### Properties

##### maxY

> `readonly` **maxY**: `number`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:22](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L22)

##### minY

> `readonly` **minY**: `number`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:21](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L21)

#### Methods

##### getBlockName()

> **getBlockName**(`x`, `y`, `z`): `Promise`\<`string`\>

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:26](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L26)

The block's state name, such as `minecraft:birch_leaves`.

###### Parameters

###### x

`number`

###### y

`number`

###### z

`number`

###### Returns

`Promise`\<`string`\>

##### getHighestBlock()

> **getHighestBlock**(`x`, `z`): `Promise`\<`number` \| `null`\>

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:28](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L28)

The y of the column's highest block that is not air, or null for an empty column.

###### Parameters

###### x

`number`

###### z

`number`

###### Returns

`Promise`\<`number` \| `null`\>

##### isObstructed()

> **isObstructed**(`x`, `y`, `z`): `Promise`\<`boolean`\>

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:24](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L24)

Whether a player's body cannot occupy the block.

###### Parameters

###### x

`number`

###### y

`number`

###### z

`number`

###### Returns

`Promise`\<`boolean`\>

## Type Aliases

### RelocationOffset

> **RelocationOffset** = () => `number`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:42](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L42)

Returns a whole number from `-SPAWN_RELOCATION_RANGE` to `SPAWN_RELOCATION_RANGE`.

#### Returns

`number`

## Variables

### SPAWN\_RELOCATION\_RANGE

> `const` **SPAWN\_RELOCATION\_RANGE**: `15` = `15`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:17](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L17)

How far, in blocks along each axis, a spawn that lands on leaves is moved.

Measured, not documented: across nine relocations by an unpinned BDS the offset never went
past 15 on either axis.

***

### UNKNOWN\_SPAWN\_HEIGHT

> `const` **UNKNOWN\_SPAWN\_HEIGHT**: `32767` = `32767`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:9](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L9)

The spawn height that means "the surface, wherever it is".

A Bedrock Dedicated Server writes it into a new world's `level.dat` before anybody has
joined, and resolves it per player against the column's terrain.

## Functions

### clearRespawnFeet()

> **clearRespawnFeet**(`spawn`, `terrain`, `box`): `number`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:111](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L111)

The feet height a respawn can stand at: the spawn's own, raised until the body fits.

The body is the one the player has, not a fixed size: its width says which columns it covers
around the block corner the respawn exchange stands it over, and its height says how many
blocks it fills above the feet. A stored height can be the ground itself on a world whose
spawn was written as the top block, so a block in the way moves the player up to the first
height where nothing is. A spot already free is kept.

#### Parameters

##### spawn

[`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

the spawn, in block coordinates.

##### terrain

what to ask about the blocks around it.

###### maxY

`number`

###### isObstructed

(`x`, `y`, `z`) => `boolean`

##### box

[`BodyBox`](#bodybox)

the body that has to fit, from the player's own entity.

#### Returns

`number`

***

### placePlayerSpawn()

> **placePlayerSpawn**(`spawn`, `terrain`, `random?`): `Promise`\<[`PlayerSpawn`](#playerspawn)\>

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:159](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L159)

Places a player who has no position of their own, the way a Bedrock Dedicated Server does.

Measured against an unpinned BDS, one fresh player per case:

1. The feet start one block above the stored spawn height, centered on the block. A height of
   [UNKNOWN\_SPAWN\_HEIGHT](#unknown-spawn-height) starts them on the column's highest block instead.
2. If the feet or the head would be inside a solid block, the player moves up the column to
   the first two free blocks.
3. If the first block below the feet is leaves, the player is moved to a random column up to
   [SPAWN\_RELOCATION\_RANGE](#spawn-relocation-range) blocks away on each axis, one block higher. BDS does not
   check that column, so neither does this: the player can land over water, or inside a hill.
4. Anything else is kept as it is, even a spot in mid-air, which the player then falls from.

Water below the feet is accepted, and so is a column whose top is leaves when the feet end
up underneath them: only what the player would land on matters.

#### Parameters

##### spawn

[`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

the world spawn, in block coordinates.

##### terrain

[`SpawnTerrain`](#spawnterrain)

##### random?

[`RelocationOffset`](#relocationoffset) = `randomOffset`

picks each relocation offset; replace it to make placement deterministic.

#### Returns

`Promise`\<[`PlayerSpawn`](#playerspawn)\>

***

### requestedSpawnPosition()

> **requestedSpawnPosition**(`spawn`): [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:58](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L58)

Where the spawn point says a player's feet go, before the terrain is consulted: one block
above the stored height, centered on the block.

#### Parameters

##### spawn

[`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

the world spawn, in block coordinates.

#### Returns

[`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

***

### respawnPoint()

> **respawnPoint**(`spawn`, `eyeHeight`): `object`

Defined in: [packages/prismarine/src/world/SpawnPlacement.ts:76](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/SpawnPlacement.ts#L76)

Where a player who died comes back, as an unpinned Bedrock Dedicated Server says it, measured
with the world spawn at (5, 63, -6):

- `announced`: the `SearchingForSpawn` sent at the death, the eyes over the spawn block's
  center at its own height, (5.5, 64.62, -5.5);
- `block`: the `SearchingForSpawn` that opens the answer to the client's
  `ClientReadyToSpawn`, the spawn block itself, (5, 63, -6);
- `eyes`: the `ReadyToSpawn` after it, the eyes over the block's corner, (5, 64.62, -6). The
  client puts its player there, so the server does too.

Unlike [placePlayerSpawn](#placeplayerspawn) for a join, nothing here is raised one block or centered.

#### Parameters

##### spawn

[`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

the world spawn, in block coordinates.

##### eyeHeight

`number`

how far above the feet a player's position is.

#### Returns

`object`

##### announced

> **announced**: [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

##### block

> **block**: [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

##### eyes

> **eyes**: [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)
