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

# Class: JavaClient

Defined in: [client/src/java/JavaClient.ts:231](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L231)

A Minecraft: Java Edition client, with no interface attached to it.

It does what a vanilla client does to get into a world and stay there: the handshake, the
login, with encryption when the server asks for it and compression when the server turns it
on, the configuration, then play. In play it answers keep-alives, accepts each teleport, says
how many chunks it can take after each batch and tells the server once it loaded the world.
Every packet it reads is reported, with its fields, through the `packet` event.

## Example

```typescript
const client = new JavaClient({ host: '127.0.0.1', username: 'Steve' });
client.on('chat', (message) => console.log(message));
await client.connect();
client.chat('Hello');
```

## Extends

- `EventEmitter`\<[`JavaClientEvents`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#javaclientevents)\>

## Constructors

### Constructor

> **new JavaClient**(`options`): `JavaClient`

Defined in: [client/src/java/JavaClient.ts:254](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L254)

#### Parameters

##### options

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

#### Returns

`JavaClient`

#### Overrides

`EventEmitter<JavaClientEvents>.constructor`

## Methods

### chat()

> **chat**(`line`): `void`

Defined in: [client/src/java/JavaClient.ts:410](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L410)

Says a line in chat, or runs it as a command when it starts with a slash. Chat goes
unsigned, as a client without a Mojang key sends it.

#### Parameters

##### line

`string`

What the player typed.

#### Returns

`void`

***

### connect()

> **connect**(): `Promise`\<`void`\>

Defined in: [client/src/java/JavaClient.ts:338](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L338)

Joins the server: resolves once the client is in play, has accepted its first position and
has told the server it loaded the world around it.

#### Returns

`Promise`\<`void`\>

#### Throws

When the server refuses the login or the connection closes first.

***

### disconnect()

> **disconnect**(): `void`

Defined in: [client/src/java/JavaClient.ts:463](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L463)

Hangs up.

#### Returns

`void`

***

### dropHeldItem()

> **dropHeldItem**(`all?`): `void`

Defined in: [client/src/java/JavaClient.ts:443](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L443)

Presses the drop key, as one `Player Action`: one item of the stack in the hand, or the
whole stack with `all`, as Ctrl+Q drops it. Vanilla sends a drop at the origin, facing down.

#### Parameters

##### all?

`boolean` = `false`

Whether the whole stack goes.

#### Returns

`void`

***

### getBrand()

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

Defined in: [client/src/java/JavaClient.ts:488](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L488)

The server's `minecraft:brand`.

#### Returns

`string` \| `undefined`

***

### getChunkCount()

> **getChunkCount**(): `number`

Defined in: [client/src/java/JavaClient.ts:503](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L503)

How many chunk columns the client holds.

#### Returns

`number`

***

### getHealth()

> **getHealth**(): \{ `food`: `number`; `health`: `number`; `saturation`: `number`; \} \| `undefined`

Defined in: [client/src/java/JavaClient.ts:483](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L483)

The latest `Set Health`.

#### Returns

\{ `food`: `number`; `health`: `number`; `saturation`: `number`; \} \| `undefined`

***

### getLogin()

> **getLogin**(): [`PlayLoginPayload`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#playloginpayload) \| `undefined`

Defined in: [client/src/java/JavaClient.ts:478](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L478)

What `Login (play)` and the latest `Respawn` said: the entity id, the dimension and the game mode.

#### Returns

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

***

### getPhase()

> **getPhase**(): `"login"` \| `"status"` \| `"play"` \| `"configuration"` \| `"handshake"`

Defined in: [client/src/java/JavaClient.ts:468](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L468)

The phase the conversation is in, `handshake` before it starts and after it ends.

#### Returns

`"login"` \| `"status"` \| `"play"` \| `"configuration"` \| `"handshake"`

***

### getPose()

> **getPose**(): [`JavaPose`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#javapose) \| `undefined`

Defined in: [client/src/java/JavaClient.ts:473](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L473)

Where the player is, once the server placed it.

#### Returns

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

***

### getResourcePacks()

> **getResourcePacks**(): `ReadonlyMap`\<`string`, `JavaLoadedResourcePack`\>

Defined in: [client/src/java/JavaClient.ts:493](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L493)

The resource packs the client loaded from the server and still has, by id, bottom first: the last loaded is on top.

#### Returns

`ReadonlyMap`\<`string`, `JavaLoadedResourcePack`\>

***

### hasChunk()

> **hasChunk**(`x`, `z`): `boolean`

Defined in: [client/src/java/JavaClient.ts:498](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L498)

Whether the client holds the chunk column at chunk `x`, `z`: sent, and not unloaded since.

#### Parameters

##### x

`number`

##### z

`number`

#### Returns

`boolean`

***

### move()

> **move**(`to`, `onGround?`): `void`

Defined in: [client/src/java/JavaClient.ts:431](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L431)

Moves the player and turns it, as one `Set Player Position and Rotation`.

#### Parameters

##### to

`Partial`\<[`JavaPose`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#javapose)\>

Where the player's feet are now, and where it looks; a field left out stays.

##### onGround?

`boolean` = `true`

Whether the player stands on something.

#### Returns

`void`

***

### next()

> **next**\<`D`\>(`definition`, `accept?`): `Promise`\<`JavaPayload`\<`D`\>\>

Defined in: [client/src/java/JavaClient.ts:513](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L513)

Waits for the next packet of one kind.

#### Type Parameters

##### D

`D` *extends* `JavaPacketDefinition`\<`Record`\<`string`, [`WireType`](https://jsprismarine.dev/api/@jsprismarine/protocol/namespaces/t/index.md#wiretype)\<`unknown`\>\>\>

#### Parameters

##### definition

`D`

The packet.

##### accept?

(`payload`) => `boolean`

Which of them to wait for; any, when left out.

#### Returns

`Promise`\<`JavaPayload`\<`D`\>\>

Its fields.

***

### send()

> **send**\<`D`\>(`definition`, `value`): `void`

Defined in: [client/src/java/JavaClient.ts:401](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L401)

Writes one packet to the server.

#### Type Parameters

##### D

`D` *extends* `JavaPacketDefinition`\<`Record`\<`string`, [`WireType`](https://jsprismarine.dev/api/@jsprismarine/protocol/namespaces/t/index.md#wiretype)\<`unknown`\>\>\>

#### Parameters

##### definition

`D`

A serverbound packet of the phase the client is in.

##### value

`JavaPayload`\<`D`\>

Its fields.

#### Returns

`void`

***

### swapHands()

> **swapHands**(): `void`

Defined in: [client/src/java/JavaClient.ts:453](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L453)

Presses the swap hands key, as one `Player Action` at the origin, as vanilla sends it.

#### Returns

`void`

***

### status()

> `static` **status**(`host`, `port?`, `protocol?`): `Promise`\<[`JavaServerStatus`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#javaserverstatus)\>

Defined in: [client/src/java/JavaClient.ts:273](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/client/src/java/JavaClient.ts#L273)

Asks a server for its server list entry, as the multiplayer screen does. The ping that
follows is answered with its number, and the connection closes.

#### Parameters

##### host

`string`

The server's address.

##### port?

`number` = `JAVA_DEFAULT_PORT`

Its port; defaults to [JAVA\_DEFAULT\_PORT](https://jsprismarine.dev/api/@jsprismarine/client/index.md#java_default_port).

##### protocol?

`JavaProtocol` = `NEWEST_JAVA_RELEASE`

The release to report; defaults to the newest the protocol package has.

#### Returns

`Promise`\<[`JavaServerStatus`](https://jsprismarine.dev/api/@jsprismarine/client/index.md#javaserverstatus)\>

The server's status JSON, raw and parsed.
