-
Notifications
You must be signed in to change notification settings - Fork 30
Scheduled Updates
Scheduled Updates is a built-in feature of the Inventory Framework that allows developers to automatically refresh any view at fixed intervals — essentially, it “calls update() every X ticks.”
Scheduled updates are defined in the view configuration using the onInit method.
Use the scheduleUpdate setting to specify the update interval in ticks.
@Override
public void onInit(ViewConfigBuilder config) {
config.scheduleUpdate(intervalInTicks);
}Example: Automatically update the view every 1 second (20 ticks):
@Override
public void onInit(ViewConfigBuilder config) {
config.scheduleUpdate(20L /* ticks */);
}Since scheduled updates only trigger a view update, dynamically rendered items will automatically react to these updates.
The example below demonstrates Dynamic Item Rendering and State Management.
private final MutableIntState counterState = mutableState(0);
@Override
public void onInit(ViewConfigBuilder config) {
config.scheduleUpdate(20L /* ticks */);
}
@Override
public void onFirstRender(RenderContext render) {
render.firstSlot().renderWith(() -> new ItemStack(
/* type = */ Material.DIAMOND,
/* amount = */ counterState.increment(render)
));
}When scheduled updates are enabled for a view, the global onUpdate trigger is automatically invoked each time the view’s scheduled update interval elapses.
This allows you to execute recurring logic (e.g., dynamic data updates, or timed effects like changing items) without manually managing a Timer State.
@Override
public void onInit(ViewConfigBuilder config) {
// Schedules every 20 ticks
config.scheduleUpdate(20L);
}
@Override
public void onUpdate(Context context) {
// Called automatically every 20 ticks
}A global scheduler manages all scheduled updates across views.
When a player opens a view, it is added to the scheduler’s task list.
At each interval, the scheduler executes the update() method for all active view contexts.
- The scheduler is initialized when a new player's view triggers
onOpen. - When a player closes a view, if its context becomes invalid (i.e., no other viewers share it), the scheduler stops executing updates for that context.
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.