# OpenContainer

`com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventOpenContainer`

**Since:** 1.6.5

**Cancellable:** Yes. Call `event.cancel()` in a handler before releasing the event lock.

Fires after a container screen is set. Cancelling restores the previously displayed screen, or
a `KeyMacrosScreen(null)` fallback if there was none. In creative mode it is skipped for
container screens other than the creative inventory. Unlike
[EventOpenScreen](../player/EventOpenScreen.md), it only fires for
container screens and fires after that event.  
```js
JsMacros.on("OpenContainer", true, JavaWrapper.methodToJava(function (event) {
  if (event.screen.getScreenClassName() === "ShulkerBoxScreen") {
    Chat.log("no shulker boxes today");  
    event.cancel();  
  }
}))
```

## Constructors

### new EventOpenContainer {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventOpenContainer_constructor-AbstractContainerScreen-}

```js
new EventOpenContainer(AbstractContainerScreen<?> screen)
```

Wraps the supplied container screen and retains it as the event screen. This does not open or
display a screen; a non-null `screen` must implement [IScreen](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IScreen.md). A failed cast occurs
after the inventory wrapper is created. A null input leaves both [screen](#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventOpenContainer_screen) and
[inventory](#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventOpenContainer_inventory) null.

**Parameters:**
- `screen`: the container screen to wrap and retain; may be null

## Fields

### inventory {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventOpenContainer_inventory}

```js
inventory: Inventory<?>
```

The opening container, wrapped in a fresh [Inventory](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/inventory/Inventory.md) for the screen's menu.

### screen {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventOpenContainer_screen}

```js
screen: IScreen
```

The container screen that is opening, as an [IScreen](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IScreen.md). Its class name is available from
[getScreenClassName()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/classes/render/IScreen.md#com.jsmacrosce.jsmacros.client.api.classes.render.IScreen_getScreenClassName-).

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventOpenContainer_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the event name, screen name, and inventory.  
The format is `%s:{"screenName": "%s", "inventory": %s}`; values are inserted
with [String.format(String, Object...)](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html) formatting, not JSON serialization. The
computed screen name from the stored screen is rendered as `"null"` when null; a null inventory is rendered as
unquoted `null`.

**Returns:** the formatted event and payload summary
