-
Notifications
You must be signed in to change notification settings - Fork 31
Shared Contexts
Shared contexts are contexts whose container (inventory), its display, 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.
There are two ways to create a shared context:
- Linking it directly to a specific group of players through
open. - Preparing the context to receive a group of players before opening it, via
prepare.
The difference between both is that: preparing and opening a context are different things, from the moment a context is opened for one or more players it becomes a confined context. That is, he cannot receive more players than he already has.
// `open` returns a MyView instance, and not a context so you won't have access to it anyway
viewFrame.open(MyView.class, list of players);The biggest advantage of shared contexts is that you can do whatever you need to with it before it is displayed and registered.
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.close();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.
You can find practical examples in the examples directory.