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

# player/PlayerSession

## Classes

- [PlayerSession](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/PlayerSession/classes/PlayerSession.md)

## Interfaces

### Arrival

Defined in: [packages/prismarine/src/player/PlayerSession.ts:155](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L155)

Where a player lands when [PlayerSession.changeWorld](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/PlayerSession/classes/PlayerSession.md#changeworld) moves them.

The position is the feet position in `world`, as a portal's exit, the End platform, a spawn
block and `/tp` all produce it. A player's own position is their eyes (see
`EYE_HEIGHT`), so `changeWorld` raises the arrival once, and
`ChangeDimensionPacket` and the `MovePlayer` teleport at the end of the change both carry
those eyes.

#### Extended by

- [`PortalArrival`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/portal/DimensionTravel/index.md#portalarrival)

#### Properties

##### closesLoadingScreen?

> `optional` **closesLoadingScreen?**: `boolean`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:168](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L168)

Whether the client closes a loading screen for this change, which the change then stays
pending on. Defaults to true; a respawn after a death is the one the client does not.

##### pitch

> **pitch**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:161](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L161)

##### position

> **position**: [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:159](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L159)

Feet position in `world`, never the eyes.

##### respawn?

> `optional` **respawn?**: `boolean`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:163](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L163)

Whether the change follows a death rather than a portal or a teleport. Defaults to false.

##### world

> **world**: [`World`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/World/classes/World.md)

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

The world the player arrives in.

##### yaw

> **yaw**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:160](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L160)

***

### OpenBlockContainer

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

A screen a block opened for one player, as the session remembers it.

#### Properties

##### bookshelfPower

> **bookshelfPower**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:241](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L241)

Bookshelves around an enchanting table, as the last redraw counted them.

Kept rather than recounted when a row is taken, so the rows the player was shown and the
row that is applied are drawn from one number. Zero for every other screen.

##### identifier

> `readonly` **identifier**: `string`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:224](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L224)

The block standing there when it was opened.

##### inputs

> `readonly` **inputs**: ([`Item`](https://jsprismarine.dev/api/@jsprismarine/prismarine/item/Item/classes/Item.md) \| `null`)[]

Defined in: [packages/prismarine/src/player/PlayerSession.ts:234](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L234)

The workstation's own input slots, in the order that station's recipe declares them.

They live on the window rather than on the block because they are the player's: closing
the screen is what gives them back, and a second player at the same table has their own
inputs.

##### loomSelection?

> `optional` **loomSelection?**: `object`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:260](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L260)

A loom's patterns the player may pick from, and the one picked, by its place among them, or
-1 for none. Undefined until the loom's slots first change.

###### patterns

> `readonly` **patterns**: readonly `string`[]

###### selected

> **selected**: `number`

##### mount?

> `readonly` `optional` **mount?**: [`OpenMount`](#openmount)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:245](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L245)

Set when the window is the inventory screen of the mount the player rides.

##### pickedOffer?

> `optional` **pickedOffer?**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:255](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L255)

The offer of a trade screen the player picked, by its place in the offers, or undefined until
a Java client picks one. A pick past the first is the only offer its payment pays for.

##### pickedRecipe?

> `optional` **pickedRecipe?**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:265](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L265)

The stonecutter recipe the player picked, by its place in the list the input is cut by, or
undefined before a stack first goes in, and -1 once the list changed with none picked.

##### position

> `readonly` **position**: [`Vector3`](https://jsprismarine.dev/api/@jsprismarine/math/classes/Vector3.md)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:222](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L222)

The block it belongs to, which is what an enchanting table needs to count bookshelves.

##### screen

> `readonly` **screen**: [`WindowTypes`](https://jsprismarine.dev/api/@jsprismarine/minecraft/index.md#windowtypes)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:226](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L226)

The `Container Type` the client is drawing.

##### trade?

> `readonly` `optional` **trade?**: [`OpenTrade`](#opentrade)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:243](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L243)

Set when the window is a villager's trade screen rather than a block's container.

##### typedName?

> `optional` **typedName?**: `string`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:250](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L250)

The name the player typed into an anvil's field, or undefined until the client sends one.
A Java client sends it with every change, and with the item's own name as the item goes in.

##### windowId

> `readonly` **windowId**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:220](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L220)

The `Container Id` it was opened under.

***

### OpenMount

Defined in: [packages/prismarine/src/player/PlayerSession.ts:269](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L269)

The mount a mount's inventory screen is open on, and where the screen keeps each slot.

#### Properties

##### columns

> `readonly` **columns**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:279](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L279)

How many columns of chest slots the screen shows, three rows each.

##### entity

> `readonly` **entity**: `bigint`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:271](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L271)

The mount's runtime id.

##### slots

> `readonly` **slots**: readonly (`number` \| `undefined`)[]

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

The mount's `inventory` container slot behind each of the screen's own slots, in the
screen's order: the saddle, the armor or carpet, then the chest slots. A slot the mount
lacks, such as a llama's saddle, is undefined and shows empty.

***

### OpenTrade

Defined in: [packages/prismarine/src/player/PlayerSession.ts:306](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L306)

A trade screen's trader, and what happens when the player stops trading.

#### Properties

##### source

> `readonly` **source**: [`TradeSource`](#tradesource)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:310](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L310)

##### title?

> `readonly` `optional` **title?**: `string`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:309](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L309)

The title of the screen as a translation key, such as `entity.villager.farmer`; the trader's name when absent.

##### trader

> `readonly` **trader**: [`TradingActor`](#tradingactor)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:307](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L307)

#### Methods

##### context()

> **context**(): [`TradeContext`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#tradecontext)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:312](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L312)

The player's own state the discounts read, such as Hero of the Village.

###### Returns

[`TradeContext`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#tradecontext)

##### release()

> **release**(): `void`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:314](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L314)

Called once when the screen closes, so the trader is free to trade with someone else.

###### Returns

`void`

##### traded()?

> `optional` **traded**(`result`): `void`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:316](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L316)

Called after each trade that went through, for what the villager does about it.

###### Parameters

###### result

[`TradeResult`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#traderesult)

###### Returns

`void`

***

### PendingDimensionChange

Defined in: [packages/prismarine/src/player/PlayerSession.ts:172](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L172)

A dimension change the client has not yet closed the loading screen for.

#### Properties

##### arrival

> **arrival**: [`Arrival`](#arrival)

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

##### loadingScreenId

> **loadingScreenId**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:174](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L174)

The `Loading Screen Id` the client has to report `EndLoadingScreen` with.

***

### TradeSource

Defined in: [packages/prismarine/src/player/PlayerSession.ts:283](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L283)

What a trade screen needs from the trader it is open on.

#### Properties

##### experience

> `readonly` **experience**: `number`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:299](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L299)

The experience the trader has earned, which a Java client draws the level bar from.

##### level

> `readonly` **level**: `number`

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

The trader's level, from one.

#### Methods

##### offers()

> **offers**(`context?`): readonly [`LiveOffer`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#liveoffer)[]

Defined in: [packages/prismarine/src/player/PlayerSession.ts:288](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L288)

The offers with the prices the player pays now. A change this makes to the trader, such as
a cured discount drawn on the first ask, is logged as the trader's `merchant` field.

###### Parameters

###### context?

[`TradeContext`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#tradecontext)

###### Returns

readonly [`LiveOffer`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#liveoffer)[]

##### tierRequirements()

> **tierRequirements**(): readonly `number`[]

Defined in: [packages/prismarine/src/player/PlayerSession.ts:295](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L295)

The experience each level asks for.

###### Returns

readonly `number`[]

##### trade()

> **trade**(`index`, `context?`): [`TradeResult`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#traderesult)

Defined in: [packages/prismarine/src/player/PlayerSession.ts:293](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L293)

Runs one trade; see `Merchant.trade`. The trade has to log the trader's `merchant`
field: that entry is what sends an open screen its new offers, and nothing else redraws it.

###### Parameters

###### index

`number`

###### context?

[`TradeContext`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#tradecontext)

###### Returns

[`TradeResult`](https://jsprismarine.dev/api/@jsprismarine/trading/index.md#traderesult)

## Type Aliases

### RespawnDestination

> **RespawnDestination** = `ReturnType`\<*typeof* [`respawnPoint`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/SpawnPlacement/index.md#respawnpoint)\> & `object`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:323](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L323)

Where a player comes back after a death: the world, and the three positions the respawn
exchange needs in it. See [respawnPoint](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/SpawnPlacement/index.md#respawnpoint) for what each position is.

#### Type Declaration

##### world

> `readonly` **world**: [`World`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/World/classes/World.md)

***

### SessionMessage

> **SessionMessage** = `Pick`\<[`ShownMessage`](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/presenter/SessionPresenter/index.md#shownmessage), `"message"`\> & `Partial`\<`Omit`\<[`ShownMessage`](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/presenter/SessionPresenter/index.md#shownmessage), `"message"`\>\>

Defined in: [packages/prismarine/src/player/PlayerSession.ts:335](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L335)

A message for [PlayerSession.sendMessage](https://jsprismarine.dev/api/@jsprismarine/prismarine/player/PlayerSession/classes/PlayerSession.md#sendmessage): the text, and what to show it as where it is not a raw line.

***

### TradingActor

> **TradingActor** = `Pick`\<[`ShownActor`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/ShownActor/index.md#shownactor), `"getRuntimeId"` \| `"getPosition"` \| `"getType"`\> & `object`

Defined in: [packages/prismarine/src/player/PlayerSession.ts:303](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/player/PlayerSession.ts#L303)

What a trade screen reads of its trader: the actor the screen is bound to, and its name for the title.

#### Type Declaration

##### getName()

> **getName**(): `string`

###### Returns

`string`
