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

# world/sleeping

## Interfaces

### BedBlock

Defined in: [packages/prismarine/src/world/sleeping.ts:106](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L106)

A block position.

#### Properties

##### x

> `readonly` **x**: `number`

Defined in: [packages/prismarine/src/world/sleeping.ts:107](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L107)

##### y

> `readonly` **y**: `number`

Defined in: [packages/prismarine/src/world/sleeping.ts:108](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L108)

##### z

> `readonly` **z**: `number`

Defined in: [packages/prismarine/src/world/sleeping.ts:109](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L109)

***

### SleepCount

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

How many of a dimension's players are there to sleep, and how many of them do.

#### Properties

##### active

> `readonly` **active**: `number`

Defined in: [packages/prismarine/src/world/sleeping.ts:51](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L51)

The players who are not spectators.

##### sleeping

> `readonly` **sleeping**: `number`

Defined in: [packages/prismarine/src/world/sleeping.ts:53](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L53)

Those of them asleep.

***

### SleepCounted

Defined in: [packages/prismarine/src/world/sleeping.ts:39](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L39)

One player, as a dimension's sleep count reads it.

#### Properties

##### sleeping

> `readonly` **sleeping**: `boolean`

Defined in: [packages/prismarine/src/world/sleeping.ts:43](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L43)

Whether it lies in a bed.

##### sleptLongEnough

> `readonly` **sleptLongEnough**: `boolean`

Defined in: [packages/prismarine/src/world/sleeping.ts:45](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L45)

Whether it has slept for [DEEP\_SLEEP\_TICKS](#deep-sleep-ticks).

##### spectator

> `readonly` **spectator**: `boolean`

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

Whether it watches as a spectator, which leaves it out of the count.

## Type Aliases

### BedSleepingProblem

> **BedSleepingProblem** = `"too_far_away"` \| `"obstructed"` \| `"not_safe"` \| `"not_possible_now"` \| `"other"`

Defined in: [packages/prismarine/src/world/sleeping.ts:193](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L193)

Why a player may not lie down in a bed, as Java's `BedSleepingProblem` names it.

## Variables

### BED\_OCCUPIED\_MESSAGE

> `const` **BED\_OCCUPIED\_MESSAGE**: `"block.minecraft.bed.occupied"` = `'block.minecraft.bed.occupied'`

Defined in: [packages/prismarine/src/world/sleeping.ts:207](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L207)

What a bed someone else lies in is told with, Java's.

***

### BED\_PROBLEM\_MESSAGES

> `const` **BED\_PROBLEM\_MESSAGES**: `Readonly`\<`Record`\<`"too_far_away"` \| `"obstructed"` \| `"not_safe"`, `string`\>\>

Defined in: [packages/prismarine/src/world/sleeping.ts:200](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L200)

The translation key each problem is told with, Java's. `not_possible_now` is told with the bed
rule's own `error_message`, and `other` with nothing.

#### Java See

Player$BedSleepingProblem.TOO_FAR_AWAY

***

### DAY\_TICKS

> `const` **DAY\_TICKS**: `24000` = `24_000`

Defined in: [packages/prismarine/src/world/sleeping.ts:25](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L25)

The length of one day on the Overworld's clock.

***

### DEEP\_SLEEP\_TICKS

> `const` **DEEP\_SLEEP\_TICKS**: `100` = `100`

Defined in: [packages/prismarine/src/world/sleeping.ts:15](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L15)

How long a player has to sleep before its sleep counts toward skipping the night, and the most
its sleep counter holds.

#### Java See

Player.isSleepingLongEnough

***

### NOT\_SAFE\_REACH

> `const` **NOT\_SAFE\_REACH**: `object`

Defined in: [packages/prismarine/src/world/sleeping.ts:121](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L121)

How far a monster may be from a bed, across and up or down, and still keep a player from sleeping.

#### Type Declaration

##### across

> `readonly` **across**: `8` = `8`

##### vertical

> `readonly` **vertical**: `5` = `5`

***

### PLAYER\_REST\_PREVENTERS

> `const` **PLAYER\_REST\_PREVENTERS**: `ReadonlySet`\<`string`\>

Defined in: [packages/prismarine/src/world/sleeping.ts:149](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L149)

The entity types whose Java class is a `Monster`, the ones a player looks for around a bed
before it lies down. A slime, a phantom, a ghast and a shulker are hostile but no `Monster`, so
they let a player sleep. `packages/parity` checks this list against the classes of the pinned
jar.

#### Java See

ServerPlayer.startSleepInBed

#### Java See

Monster.isPreventingPlayerRest

***

### RESTLESS\_WHEN\_ANGRY

> `const` **RESTLESS\_WHEN\_ANGRY**: `"minecraft:zombified_piglin"` = `'minecraft:zombified_piglin'`

Defined in: [packages/prismarine/src/world/sleeping.ts:190](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L190)

The one `Monster` that keeps a player from sleeping only while it is angry at that player.

#### Java See

ZombifiedPiglin.isPreventingPlayerRest

***

### SLEEP\_STATUS\_MESSAGES

> `const` **SLEEP\_STATUS\_MESSAGES**: `object`

Defined in: [packages/prismarine/src/world/sleeping.ts:216](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L216)

What the players of a dimension are told while some of them sleep, Java's.

#### Type Declaration

##### counting

> `readonly` **counting**: `"sleep.players_sleeping"` = `'sleep.players_sleeping'`

How many sleep, and how many have to: `%s/%s players sleeping`.

##### skipping

> `readonly` **skipping**: `"sleep.skipping_night"` = `'sleep.skipping_night'`

Enough are asleep, so the night passes once they have slept long enough.

***

### SPAWN\_SET\_MESSAGE

> `const` **SPAWN\_SET\_MESSAGE**: `"block.minecraft.set_spawn"` = `'block.minecraft.set_spawn'`

Defined in: [packages/prismarine/src/world/sleeping.ts:213](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L213)

What a player whose spawn moved is told.

#### Java See

ServerPlayer.SPAWN_SET_MESSAGE

***

### WAKE\_UP\_TICKS

> `const` **WAKE\_UP\_TICKS**: `110` = `110`

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

Where the sleep counter of a player who just got up runs to before it starts again from 0,
which is how long the client keeps the screen dark after waking.

#### Java See

Player.tick

## Functions

### canSleepThroughNights()

> **canSleepThroughNights**(`percentage`): `boolean`

Defined in: [packages/prismarine/src/world/sleeping.ts:103](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L103)

Whether the night can be slept through at all: a `players_sleeping_percentage` past 100 asks
for more players than there are, and the bed only sets the spawn.

#### Parameters

##### percentage

`number`

#### Returns

`boolean`

#### Java Source

ServerLevel.canSleepThroughNights

***

### enoughDeepSleeping()

> **enoughDeepSleeping**(`count`, `players`, `percentage`): `boolean`

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

Whether enough players have slept long enough for the night to pass now.

#### Parameters

##### count

[`SleepCount`](#sleepcount)

##### players

readonly [`SleepCounted`](#sleepcounted)[]

##### percentage

`number`

#### Returns

`boolean`

#### Java Source

SleepStatus.areEnoughDeepSleeping

***

### enoughSleeping()

> **enoughSleeping**(`count`, `percentage`): `boolean`

Defined in: [packages/prismarine/src/world/sleeping.ts:88](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L88)

Whether enough players are asleep for the night to pass once they have slept long enough.

#### Parameters

##### count

[`SleepCount`](#sleepcount)

##### percentage

`number`

#### Returns

`boolean`

#### Java Source

SleepStatus.areEnoughSleeping

***

### morningAfter()

> **morningAfter**(`dayTime`): `number`

Defined in: [packages/prismarine/src/world/sleeping.ts:33](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L33)

The day time the night skips to, the next morning: the `minecraft:wake_up_from_sleep` marker
of the Overworld's day timeline is tick 0 of every day.

#### Parameters

##### dayTime

`number`

The day time now.

#### Returns

`number`

#### Java Source

ClockTimeMarker.resolveTimeToMoveTo

***

### notSafeBoxOf()

> **notSafeBoxOf**(`bed`): `object`

Defined in: [packages/prismarine/src/world/sleeping.ts:128](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L128)

The box around a bed a monster keeps a player out of it from: 8 blocks across and 5 up and
down from the bed's bottom center.

#### Parameters

##### bed

[`BedBlock`](#bedblock)

#### Returns

`object`

##### max

> **max**: [`BedBlock`](#bedblock)

##### min

> **min**: [`BedBlock`](#bedblock)

#### Java See

ServerPlayer.startSleepInBed

***

### reachesBedBlock()

> **reachesBedBlock**(`at`, `bed`): `boolean`

Defined in: [packages/prismarine/src/world/sleeping.ts:117](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L117)

Whether a body at `at` can reach a bed's block: within 3 blocks of its bottom center across and
2 up or down.

#### Parameters

##### at

###### x

`number`

###### y

`number`

###### z

`number`

##### bed

[`BedBlock`](#bedblock)

#### Returns

`boolean`

#### Java Source

ServerPlayer.isReachableBedBlock

***

### sleepCountChanged()

> **sleepCountChanged**(`before`, `after`): `boolean`

Defined in: [packages/prismarine/src/world/sleeping.ts:70](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L70)

Whether a new count is worth telling the players about: somebody is or was asleep, and the
count moved.

#### Parameters

##### before

[`SleepCount`](#sleepcount)

##### after

[`SleepCount`](#sleepcount)

#### Returns

`boolean`

#### Java Source

SleepStatus.update

***

### sleepCountOf()

> **sleepCountOf**(`players`): [`SleepCount`](#sleepcount)

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

The players of a dimension, counted.

#### Parameters

##### players

readonly [`SleepCounted`](#sleepcounted)[]

#### Returns

[`SleepCount`](#sleepcount)

#### Java See

SleepStatus.update

***

### sleepersNeeded()

> **sleepersNeeded**(`percentage`, `active`): `number`

Defined in: [packages/prismarine/src/world/sleeping.ts:81](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/world/sleeping.ts#L81)

How many players have to sleep for the night to pass: the `players_sleeping_percentage` share
of those there, rounded up, and at least one.

#### Parameters

##### percentage

`number`

The game rule's value.

##### active

`number`

The players who are not spectators.

#### Returns

`number`

#### Java Source

SleepStatus.sleepersNeeded
