API reference / @jsprismarine/prismarine / entity/playerComponents / PlayerComponents
Class: PlayerComponents
Defined in: packages/prismarine/src/entity/playerComponents.ts:356
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
Parameters
attributes
Attributes
The player's attributes, where food, saturation, exhaustion, experience and the other attributes live.
written
Hears each write that changed a field.
metadata?
PlayerMetadata = ...
The player's actor metadata, where air, breathing and sprinting live.
Returns
PlayerComponents
Methods
experience()
experience():
ExperienceHolder
Defined in: packages/prismarine/src/entity/playerComponents.ts:436
The experience fields as the holder the experience curve spends and grants through.
Returns
get()
get<
F>(field):PlayerComponentValues[F]
Defined in: packages/prismarine/src/entity/playerComponents.ts:374
The value a field holds.
Type Parameters
F
F extends keyof PlayerComponentValues
Parameters
field
F
Returns
maxAir()
maxAir():
number
Defined in: packages/prismarine/src/entity/playerComponents.ts:391
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
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 would have.
Parameters
change
() => void
Writes the attributes directly.
Returns
void
resetAttributes()
resetAttributes():
void
Defined in: packages/prismarine/src/entity/playerComponents.ts:426
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
Writes a logged value back without reporting it, which is how the store undoes a write.
Parameters
field
string
value
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
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
Parameters
field
F
value
Returns
void
setAttribute()
setAttribute(
name,value):boolean
Defined in: packages/prismarine/src/entity/playerComponents.ts:403
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
Defined in: packages/prismarine/src/entity/playerComponents.ts:431
Every field's value as plain data, by field name, which the replay digest hashes.