Skip to content

Scheduled Updates

Natan Vieira edited this page Nov 8, 2025 · 22 revisions

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.”

Configuration

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 Usage

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)
    ));
}

Global Trigger

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
}

Internal Mechanics

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.

▶️ Introduction

🧩 Core Topics

💡 Built-In Features

🧰 Extra Features

🤓 Advanced Usage

⚙️ Internal Mechanisms

You can find practical examples in the examples directory.

Clone this wiki locally