[API reference](https://jsprismarine.dev/api/index.md) / [@jsprismarine/prismarine](https://jsprismarine.dev/api/@jsprismarine/prismarine/index.md) / [entity/playerComponents](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md) / PlayerComponents

# Class: PlayerComponents

Defined in: [packages/prismarine/src/entity/playerComponents.ts:356](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L356)

One player's component state, and the one place it is written.

## Constructors

### Constructor

> **new PlayerComponents**(`attributes`, `written`, `metadata?`): `PlayerComponents`

Defined in: [packages/prismarine/src/entity/playerComponents.ts:365](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L365)

#### Parameters

##### attributes

`Attributes`

The player's attributes, where food, saturation, exhaustion,
  experience and the other attributes live.

##### written

[`PlayerComponentWritten`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md#playercomponentwritten)

Hears each write that changed a field.

##### metadata?

[`PlayerMetadata`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md#playermetadata) = `...`

The player's actor metadata, where air, breathing and sprinting live.

#### Returns

`PlayerComponents`

## Methods

### experience()

> **experience**(): [`ExperienceHolder`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/Experience/index.md#experienceholder)

Defined in: [packages/prismarine/src/entity/playerComponents.ts:436](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L436)

The experience fields as the holder the experience curve spends and grants through.

#### Returns

[`ExperienceHolder`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/Experience/index.md#experienceholder)

***

### get()

> **get**\<`F`\>(`field`): [`PlayerComponentValues`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md#playercomponentvalues)\[`F`\]

Defined in: [packages/prismarine/src/entity/playerComponents.ts:374](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L374)

The value a field holds.

#### Type Parameters

##### F

`F` *extends* keyof [`PlayerComponentValues`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md#playercomponentvalues)

#### Parameters

##### field

`F`

#### Returns

[`PlayerComponentValues`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md#playercomponentvalues)\[`F`\]

***

### maxAir()

> **maxAir**(): `number`

Defined in: [packages/prismarine/src/entity/playerComponents.ts:391](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L391)

The most breath the player can hold, in ticks, which `vitals.air` is kept within.

#### Returns

`number`

***

### reportingChanges()

> **reportingChanges**(`change`): `void`

Defined in: [packages/prismarine/src/entity/playerComponents.ts:416](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L416)

Runs a change made to the attributes behind these fields, such as a respawn's reset, and
reports each field it moved, as [PlayerComponents.set](#set) would have.

#### Parameters

##### change

() => `void`

Writes the attributes directly.

#### Returns

`void`

***

### resetAttributes()

> **resetAttributes**(): `void`

Defined in: [packages/prismarine/src/entity/playerComponents.ts:426](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L426)

Puts every attribute back at its default, as a respawn does, and reports each field it moved.

#### Returns

`void`

***

### restore()

> **restore**(`field`, `value`): `boolean`

Defined in: [packages/prismarine/src/entity/playerComponents.ts:450](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L450)

Writes a logged value back without reporting it, which is how the store undoes a write.

#### Parameters

##### field

`string`

##### value

[`PlainData`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/changelog/PlainData/index.md#plaindata)

#### Returns

`boolean`

Whether `field` names a component field.

#### Throws

When the value has a shape the field never holds.

***

### set()

> **set**\<`F`\>(`field`, `value`): `void`

Defined in: [packages/prismarine/src/entity/playerComponents.ts:382](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L382)

Writes a field and reports the change. An attribute keeps a value inside its bounds, so
the value reported after the write is the one the attribute took.

#### Type Parameters

##### F

`F` *extends* keyof [`PlayerComponentValues`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md#playercomponentvalues)

#### Parameters

##### field

`F`

##### value

[`PlayerComponentValues`](https://jsprismarine.dev/api/@jsprismarine/prismarine/entity/playerComponents/index.md#playercomponentvalues)\[`F`\]

#### Returns

`void`

***

### setAttribute()

> **setAttribute**(`name`, `value`): `boolean`

Defined in: [packages/prismarine/src/entity/playerComponents.ts:403](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L403)

Writes an attribute by its id through the field it is kept in, which reports the change.

#### Parameters

##### name

`string`

The attribute's id, such as `minecraft:movement`.

##### value

`number`

The wanted value, which the attribute keeps inside its bounds.

#### Returns

`boolean`

Whether the attribute is a component field's, which an attribute such as health,
  logged on its own path, is not. Nothing is written when it is not.

***

### snapshot()

> **snapshot**(): [`PlainRecord`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/changelog/PlainData/index.md#plainrecord)

Defined in: [packages/prismarine/src/entity/playerComponents.ts:431](https://github.com/JSPrismarine/JSPrismarine/blob/e928b08f56694af6821b757ce6b196faebd3199c/packages/prismarine/src/entity/playerComponents.ts#L431)

Every field's value as plain data, by field name, which the replay digest hashes.

#### Returns

[`PlainRecord`](https://jsprismarine.dev/api/@jsprismarine/prismarine/world/changelog/PlainData/index.md#plainrecord)
