API reference / @jsprismarine/content / Instance
Class: Instance<H, S, F>
Defined in: packages/content/src/instances.ts:17
The third of the three content layers: one live thing of a type, holding a reference to that type and nothing else but its own state.
An instance is an item stack or an entity. A block in chunk storage is not one: it is a runtime id, and the hot path reads a flattened array rather than building a handle per block.
The type reference is a Holder, so reloading content points every live instance at the new type without walking the world. An instance whose identifier the reload dropped reports that instead of ticking a stale type.
Extended by
Type Parameters
H
H extends HookSignatures<H>
S
S = undefined
F
F extends string = never
Constructors
Constructor
new Instance<
H,S,F>(holder,state):Instance<H,S,F>
Defined in: packages/content/src/instances.ts:22
Parameters
holder
A holder from the registry of resolved types.
state
S
Whatever the domain keeps per instance, such as an item count.
Returns
Instance<H, S, F>
Properties
holder
Defined in: packages/content/src/instances.ts:23
A holder from the registry of resolved types.
state
state:
S
Defined in: packages/content/src/instances.ts:24
Whatever the domain keeps per instance, such as an item count.
Accessors
type
Get Signature
get type():
Type<H,F>
Defined in: packages/content/src/instances.ts:32
The type this instance is an instance of.
Throws
When the current content has no type under the holder's key.
Returns
Type<H, F>
Methods
dispatch()
dispatch<
K>(hook, ...args):void
Defined in: packages/content/src/instances.ts:41
Calls every handler the type binds for the hook, in dispatch order.
Type Parameters
K
K extends string
Parameters
hook
K
args
...Parameters<H[K]>
Returns
void
Throws
When the current content has no type under the holder's key.
dispatchFirst()
dispatchFirst<
K>(hook, ...args):ReturnType<H[K]> |undefined
Defined in: packages/content/src/instances.ts:51
Calls handlers in dispatch order until one returns a value other than undefined.
Type Parameters
K
K extends string
Parameters
hook
K
args
...Parameters<H[K]>
Returns
ReturnType<H[K]> | undefined
That handler's result, or undefined when every handler declines.
Throws
When the current content has no type under the holder's key.