pub trait ContainerContext {
// Required methods
fn open_chest(&self, x: i32, y: i32, z: i32);
fn open_crafting_table(&self, x: i32, y: i32, z: i32);
fn open(&self, container: &Container);
fn notify_viewers(
&self,
x: i32,
y: i32,
z: i32,
slot_index: i16,
item: Slot,
);
}Expand description
Container interaction: chests, crafting tables, custom windows.
Required Methods§
Sourcefn open_chest(&self, x: i32, y: i32, z: i32)
fn open_chest(&self, x: i32, y: i32, z: i32)
Opens a chest container at the given position for the current player.
Sourcefn open_crafting_table(&self, x: i32, y: i32, z: i32)
fn open_crafting_table(&self, x: i32, y: i32, z: i32)
Opens a crafting table window at the given position for the current player.
Sourcefn open(&self, container: &Container)
fn open(&self, container: &Container)
Opens a custom container window for the current player.
Takes a reference so the Container can be stored in a static,
cloned across calls, or shared — opening doesn’t consume it.
§Example
ⓘ
static SHOP: LazyLock<Container> = LazyLock::new(|| {
Container::builder()
.inventory_type(InventoryType::Generic9x6)
.title("Shop")
.build()
});
ctx.containers().open(&SHOP);Sourcefn notify_viewers(&self, x: i32, y: i32, z: i32, slot_index: i16, item: Slot)
fn notify_viewers(&self, x: i32, y: i32, z: i32, slot_index: i16, item: Slot)
Notifies every other player viewing the same block-backed container that a slot changed.
Sends SetContainerSlot to all players whose OpenContainer
component points at (x, y, z), excluding the current
player. Used by ContainerPlugin from the
ContainerSlotChangedEvent handler to keep co-viewers in sync.
No-op for virtual containers (they are per-player).