> For the complete documentation index, see [llms.txt](https://docs.quickclient.cc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.quickclient.cc/examples/chest-taker.md).

# Сундук в инвентарь

Скрипт, который забирает всё из открытого сундука и закрывает его.

Когда игрок открывает сундук, скрипт забирает всё шифт-кликами с паузой между ними и закрывает его. Пример показывает, как ловить открытие экрана, как кликать по очереди и почему один клик за тик лучше тридцати.

```java
package my;

import hex.script.api.CheckBox;
import hex.script.api.Script;
import hex.script.api.Slider;
import hex.script.api.event.ScreenEvent;

public class ChestTaker extends Script {

    private final Slider delay = slider("Пауза", 2f, 0f, 10f, 1f).postfix("t");
    private final CheckBox autoClose = checkBox("Закрывать", true);
    private final CheckBox onlyChests = checkBox("Только сундуки", true);

    private boolean working;
    private int cooldown;

    @Override
    public String description() {
        return "Забирает всё из открытого сундука";
    }

    @Override
    public void activate() {
        working = false;
        on(ScreenEvent.class, event -> {
            if (event.opened() && event.screen().container()) {
                working = !onlyChests.value() || container().type().contains("generic_9x");
                cooldown = delay.intValue();
            } else if (event.closed()) {
                working = false;
            }
        });
    }

    @Override
    public void onTick() {
        if (!working || !container().open()) return;
        if (cooldown-- > 0) return;
        cooldown = delay.intValue();

        int slot = nextFilled();
        if (slot >= 0) {
            container().shiftClick(slot);
            return;
        }
        if (autoClose.value()) container().close();
        working = false;
    }

    private int nextFilled() {
        for (int slot = 0; slot < container().size(); slot++) {
            if (!container().slot(slot).empty()) return slot;
        }
        return -1;
    }
}
```

## Разбор

**Старт по событию, работа в тике.** `ScreenEvent` сообщает, что контейнер открылся, но кликать прямо в обработчике рано: содержимое приходит от сервера чуть позже. Флаг `working` и первый `cooldown` дают ему время прийти.

**Один клик за тик.** Тридцать шифт-кликов за один тик сервер сразу заметит. Паузу между кликами в тиках можно настроить. Значение ноль тоже работает, но и тогда будет не больше одного клика за тик.

**Поиск слота каждый тик.** После шифт-клика предметы в сундуке сдвигаются, а если инвентарь заполнен, стопка остаётся на месте. Поиск с начала справляется с обоими случаями: при полном инвентаре скрипт кликает одну и ту же стопку, пока не сработает закрытие.

**Тип контейнера вместо заголовка.** Сервер может переименовать заголовок как угодно, а тип меню `generic_9x3` или `generic_9x6` всё равно останется типом сундука.

**Закрытие в общей очереди.** Клики уходят в очередь Quick, и `close()` встаёт туда же. Сундук закроется после последнего клика, а не вместо него.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.quickclient.cc/examples/chest-taker.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
