Skip to content

Interaction Handling

Natan Vieira edited this page Mar 4, 2023 · 11 revisions

There are global and component-specific interaction treatments (items are components).

Global

This will send a message whenever the player interacts with the inventory.

import me.devnatan.inventoryframework.View;

class CoolView extends View {

    @Override
    public void onClick(SlotClickContext slotClick) {
        slotClick.getPlayer().sendMessage("Clicked on " + slotClick.getClickedSlot());
    }

}

Also called in interactions of the player's own inventory, it is possible to distinguish which inventory was clicked using isOnEntityContainer().

import me.devnatan.inventoryframework.View;

class CoolView extends View {

    @Override
    public void onClick(SlotClickContext slotClick) {
        if (slotClick.isOnEntityContainer()) {
            // clicked on player inventory (bottom)
        } else {
            // clicked on view inventory (top)
        }
    }

}

Individual

Items have a series of options related to interaction treatment, it is possible to define them individually for each of them

import me.devnatan.inventoryframework.View;

class CoolView extends View {

    @Override
    public void onFirstRender(RenderContext ctx) {
	ctx.firstSlot(new ItemStack(Material.DIAMOND))
	    .onClick(click -> click.getPlayer().sendMessage("Clicked on diamond"));
    }

Welcome to the Inventory Framework documentation.

▶️ Introduction

🧩 Core Topics

💡 Built-In Features

🧰 Extra Features

🤓 Advanced Usage

⚙️ Internal Mechanisms

🛠️ Tooling

You can find practical examples in the examples directory.

Clone this wiki locally