API reference / @jsprismarine/client / JavaClient
Class: JavaClient
Defined in: client/src/java/JavaClient.ts:231
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
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>
Constructors
Constructor
new JavaClient(
options):JavaClient
Defined in: client/src/java/JavaClient.ts:254
Parameters
options
Returns
JavaClient
Overrides
EventEmitter<JavaClientEvents>.constructor
Methods
chat()
chat(
line):void
Defined in: client/src/java/JavaClient.ts:410
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
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
Hangs up.
Returns
void
dropHeldItem()
dropHeldItem(
all?):void
Defined in: client/src/java/JavaClient.ts:443
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
The server's minecraft:brand.
Returns
string | undefined
getChunkCount()
getChunkCount():
number
Defined in: client/src/java/JavaClient.ts:503
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
The latest Set Health.
Returns
{ food: number; health: number; saturation: number; } | undefined
getLogin()
getLogin():
PlayLoginPayload|undefined
Defined in: client/src/java/JavaClient.ts:478
What Login (play) and the latest Respawn said: the entity id, the dimension and the game mode.
Returns
PlayLoginPayload | undefined
getPhase()
getPhase():
"login"|"status"|"play"|"configuration"|"handshake"
Defined in: client/src/java/JavaClient.ts:468
The phase the conversation is in, handshake before it starts and after it ends.
Returns
"login" | "status" | "play" | "configuration" | "handshake"
getPose()
getPose():
JavaPose|undefined
Defined in: client/src/java/JavaClient.ts:473
Where the player is, once the server placed it.
Returns
JavaPose | undefined
getResourcePacks()
getResourcePacks():
ReadonlyMap<string,JavaLoadedResourcePack>
Defined in: client/src/java/JavaClient.ts:493
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
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
Moves the player and turns it, as one Set Player Position and Rotation.
Parameters
to
Partial<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
Waits for the next packet of one kind.
Type Parameters
D
D extends JavaPacketDefinition<Record<string, 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
Writes one packet to the server.
Type Parameters
D
D extends JavaPacketDefinition<Record<string, 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
Presses the swap hands key, as one Player Action at the origin, as vanilla sends it.
Returns
void
status()
staticstatus(host,port?,protocol?):Promise<JavaServerStatus>
Defined in: client/src/java/JavaClient.ts:273
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.
protocol?
JavaProtocol = NEWEST_JAVA_RELEASE
The release to report; defaults to the newest the protocol package has.
Returns
Promise<JavaServerStatus>
The server's status JSON, raw and parsed.