-
Notifications
You must be signed in to change notification settings - Fork 36
Shared Contexts
Shared contexts are contexts whose inventory is shared among multiple players, any change to that context is propagated to all players that are linked to it.
Shared Contexts API is experimental and is not subject to the general compatibility guarantees such API may be changed or may be removed completely in any further release.
To create a shared context you need to provide a list of players through ViewFrame's open.
// Opens "MyView" to a list of players
viewFrame.open(MyView.class, list of players);Anything you do in a shared context will be propagated to all players linked to it, everything.
For example adding an item, removing an item, an update timer, everything is shared up to the internal implementation of the inventory depending on the platform your view was created on, even closing the context.
// Closes for everyone and invalidates the context
context.closeForEveryone();If you and to close only for the player of a interaction context use *ForPlayer instead.
// Closes for the player and context is invalidated only if there's no more players on it
context.closeForPlayer();As said in other topics many things are shared and that includes states, from the moment a state is shared and as a side effect something updates in the view, this is propagated to everyone.
MutableState<Int> state = mutableState(0);
state.set(4, sharedContext);If you don't want this behavior to occur I recommend that you create individual states and update the state for everyone depending on your condition.
You can get the list of states of a view using getContexts().
Welcome to the Inventory Framework documentation.
- Pagination — Display large collections of items across multiple pages.
- Layouts (a.k.a. Masks or Patterns) — Define visual patterns for item placement.
- Scheduled Updates
- Anvil Input — Capture text input from players using an anvil GUI.
- Dynamic Title Update — Update the inventory’s title in real time.
- IntelliJ Tooling Plugin — Live inventory preview and API inspections in the IDE.
You can find practical examples in the examples directory.