API reference / @jsprismarine/client / ClientWorld
Class: ClientWorld
Defined in: client/src/ClientWorld.ts:100
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.
Example
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
Starts listening to a client's packets, for the life of the client.
Parameters
client
The client whose packets this world reads. Attach before connect to see the join.
Returns
ClientWorld
Properties
PACKETS
readonlystaticPACKETS: readonlyPacketConstructor[]
Defined in: client/src/ClientWorld.ts:102
The packets this world reads, registered on the client's registry when it lacks them.
Methods
actor()
actor(
runtimeId):WorldActor|undefined
Defined in: client/src/ClientWorld.ts:228
One actor by runtime id.
Parameters
runtimeId
bigint
Returns
WorldActor | undefined
actors()
actors():
WorldActor[]
Defined in: client/src/ClientWorld.ts:218
Every actor the client can see.
Returns
actorsOfType()
actorsOfType(
type):WorldActor[]
Defined in: client/src/ClientWorld.ts:223
The actors of one identifier the client can see.
Parameters
type
string
Returns
attribute()
attribute(
name):number|undefined
Defined in: client/src/ClientWorld.ts:203
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
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[]
Defined in: client/src/ClientWorld.ts:277
Every chat, system and translated line the server sent, oldest first.
Returns
readonly Text[]
chunksLoadedAround()
chunksLoadedAround(
radius):boolean
Defined in: client/src/ClientWorld.ts:246
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
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
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
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
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
The player's game type, as StartGame and SetPlayerGameType numbered it.
Returns
number | undefined
getOpenContainer()
getOpenContainer():
WorldContainer|undefined
Defined in: client/src/ClientWorld.ts:272
The container screen the server has open, or undefined when none is.
Returns
WorldContainer | undefined
getPosition()
getPosition():
WorldPosition|undefined
Defined in: client/src/ClientWorld.ts:175
The player's position, or undefined before the server placed it.
Returns
WorldPosition | undefined
getRespawnState()
getRespawnState():
number|undefined
Defined in: client/src/ClientWorld.ts:213
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
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
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
The player's health, or undefined before the server sent it.
Returns
number | undefined
inventory()
inventory(
windowId): readonlyItemStackDescriptorData[]
Defined in: client/src/ClientWorld.ts:267
The contents of one window, as the last InventoryContent and the InventorySlots after it left it.
Parameters
windowId
number
Returns
readonly ItemStackDescriptorData[]
loadedChunks()
loadedChunks():
string[]
Defined in: client/src/ClientWorld.ts:238
The chunk columns the client holds, as x,z keys.
Returns
string[]
setPosition()
setPosition(
position):void
Defined in: client/src/ClientWorld.ts:180
Records a move the caller made itself, such as one it reported in its input.
Parameters
position
Returns
void
titles()
titles():
Readonly<WorldTitles>
Defined in: client/src/ClientWorld.ts:287
The HUD's title, subtitle and action bar as the server last set them.
Returns
Readonly<WorldTitles>