[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/client](https://jsprismarine.dev/api/@jsprismarine/client/index.md) / ClientWorld

# Class: ClientWorld

Defined in: [client/src/ClientWorld.ts:100](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L100)

What a client knows about the world from the packets the server sent it: where its player
is, the chunks it holds, the actors it can see, its health and inventory, the chat and titles
it was shown, and the screens the server opened.

A retail client draws these; this one keeps them where a test, a bot or a tool can read them.
It only listens: nothing here answers the server or changes what the client sends. The
client decodes only the packets something registered, so attaching a world registers the
ones it reads that the client does not already decode, and a client that never attaches one
spends nothing on them.

Positions are the server's: the player's moves when the server teleports or corrects it, and
when the caller reports a move of its own through [ClientWorld.setPosition](#setposition).

## Example

```typescript
const client = new Client({ host: '127.0.0.1' });
const world = new ClientWorld(client);
await client.connect();
console.log(world.health(), world.actorsOfType('minecraft:pig').length);
```

## Constructors

### Constructor

> **new ClientWorld**(`client`): `ClientWorld`

Defined in: [client/src/ClientWorld.ts:157](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L157)

Starts listening to a client's packets, for the life of the client.

#### Parameters

##### client

[`Client`](https://jsprismarine.dev/api/@jsprismarine/client/classes/Client.md)

The client whose packets this world reads. Attach before `connect` to see the join.

#### Returns

`ClientWorld`

## Properties

### PACKETS

> `readonly` `static` **PACKETS**: readonly [`PacketConstructor`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#packetconstructor)[]

Defined in: [client/src/ClientWorld.ts:102](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L102)

The packets this world reads, registered on the client's registry when it lacks them.

## Methods

### actor()

> **actor**(`runtimeId`): [`WorldActor`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldactor) \| `undefined`

Defined in: [client/src/ClientWorld.ts:228](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L228)

One actor by runtime id.

#### Parameters

##### runtimeId

`bigint`

#### Returns

[`WorldActor`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldactor) \| `undefined`

***

### actors()

> **actors**(): [`WorldActor`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldactor)[]

Defined in: [client/src/ClientWorld.ts:218](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L218)

Every actor the client can see.

#### Returns

[`WorldActor`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldactor)[]

***

### actorsOfType()

> **actorsOfType**(`type`): [`WorldActor`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldactor)[]

Defined in: [client/src/ClientWorld.ts:223](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L223)

The actors of one identifier the client can see.

#### Parameters

##### type

`string`

#### Returns

[`WorldActor`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldactor)[]

***

### attribute()

> **attribute**(`name`): `number` \| `undefined`

Defined in: [client/src/ClientWorld.ts:203](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L203)

The value of one of the player's attributes, such as `minecraft:health`.

#### Parameters

##### name

`string`

#### Returns

`number` \| `undefined`

***

### blockAt()

> **blockAt**(`x`, `y`, `z`): `number` \| `undefined`

Defined in: [client/src/ClientWorld.ts:262](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L262)

The runtime id of the block an `UpdateBlock` or `UpdateSubChunkBlocks` last set at this
position, on the normal layer.

#### Parameters

##### x

`number`

##### y

`number`

##### z

`number`

#### Returns

`number` \| `undefined`

***

### chat()

> **chat**(): readonly [`Text`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#text-3)[]

Defined in: [client/src/ClientWorld.ts:277](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L277)

Every chat, system and translated line the server sent, oldest first.

#### Returns

readonly [`Text`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#text-3)[]

***

### chunksLoadedAround()

> **chunksLoadedAround**(`radius`): `boolean`

Defined in: [client/src/ClientWorld.ts:246](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L246)

Whether the client holds every column within `radius` chunks of the player.

#### Parameters

##### radius

`number`

The radius in chunks, counted as a square around the player's column.

#### Returns

`boolean`

***

### commandOutput()

> **commandOutput**(): readonly `object`[]

Defined in: [client/src/ClientWorld.ts:282](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L282)

What the server answered each of the player's commands with, oldest first.

#### Returns

readonly `object`[]

***

### forms()

> **forms**(): readonly `object`[]

Defined in: [client/src/ClientWorld.ts:292](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L292)

Every form the server asked the player to fill in, oldest first.

#### Returns

readonly `object`[]

***

### getDimension()

> **getDimension**(): `number` \| `undefined`

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

The numeric id of the dimension the player is in, or `undefined` before the join.

#### Returns

`number` \| `undefined`

***

### getDisconnectReason()

> **getDisconnectReason**(): `string` \| `undefined`

Defined in: [client/src/ClientWorld.ts:297](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L297)

The reason the server gave when it disconnected the client, or `undefined` while it has not.

#### Returns

`string` \| `undefined`

***

### getGamemode()

> **getGamemode**(): `number` \| `undefined`

Defined in: [client/src/ClientWorld.ts:198](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L198)

The player's game type, as `StartGame` and `SetPlayerGameType` numbered it.

#### Returns

`number` \| `undefined`

***

### getOpenContainer()

> **getOpenContainer**(): [`WorldContainer`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldcontainer) \| `undefined`

Defined in: [client/src/ClientWorld.ts:272](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L272)

The container screen the server has open, or `undefined` when none is.

#### Returns

[`WorldContainer`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldcontainer) \| `undefined`

***

### getPosition()

> **getPosition**(): [`WorldPosition`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldposition) \| `undefined`

Defined in: [client/src/ClientWorld.ts:175](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L175)

The player's position, or `undefined` before the server placed it.

#### Returns

[`WorldPosition`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldposition) \| `undefined`

***

### getRespawnState()

> **getRespawnState**(): `number` \| `undefined`

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

The `state` of the last `Respawn` the server sent, or `undefined` when none came.

#### Returns

`number` \| `undefined`

***

### getTeleportCount()

> **getTeleportCount**(): `number`

Defined in: [client/src/ClientWorld.ts:188](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L188)

How many teleports of the player the server has sent. A client's next input after one
says it handled it, and an input that does not is still taken as from the old position.

#### Returns

`number`

***

### hasChunk()

> **hasChunk**(`chunkX`, `chunkZ`): `boolean`

Defined in: [client/src/ClientWorld.ts:233](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L233)

Whether the client holds the chunk column at these chunk coordinates.

#### Parameters

##### chunkX

`number`

##### chunkZ

`number`

#### Returns

`boolean`

***

### health()

> **health**(): `number` \| `undefined`

Defined in: [client/src/ClientWorld.ts:208](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L208)

The player's health, or `undefined` before the server sent it.

#### Returns

`number` \| `undefined`

***

### inventory()

> **inventory**(`windowId`): readonly [`ItemStackDescriptorData`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#itemstackdescriptordata)[]

Defined in: [client/src/ClientWorld.ts:267](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L267)

The contents of one window, as the last `InventoryContent` and the `InventorySlot`s after it left it.

#### Parameters

##### windowId

`number`

#### Returns

readonly [`ItemStackDescriptorData`](https://jsprismarine.dev/api/@jsprismarine/protocol/index.md#itemstackdescriptordata)[]

***

### loadedChunks()

> **loadedChunks**(): `string`[]

Defined in: [client/src/ClientWorld.ts:238](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L238)

The chunk columns the client holds, as `x,z` keys.

#### Returns

`string`[]

***

### setPosition()

> **setPosition**(`position`): `void`

Defined in: [client/src/ClientWorld.ts:180](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L180)

Records a move the caller made itself, such as one it reported in its input.

#### Parameters

##### position

[`WorldPosition`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldposition)

#### Returns

`void`

***

### titles()

> **titles**(): `Readonly`\<[`WorldTitles`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldtitles)\>

Defined in: [client/src/ClientWorld.ts:287](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/ClientWorld.ts#L287)

The HUD's title, subtitle and action bar as the server last set them.

#### Returns

`Readonly`\<[`WorldTitles`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#worldtitles)\>
