> 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/actions/slots.md).

# Слоты и броня

Временная смена слота в руке и надевание лучшей брони.

`slots()` нужен, когда предмет требуется в руке ненадолго: например, взять жемчуг, бросить его и вернуться на меч. Ещё он умеет надевать броню получше.

`select(hotbar)` возвращает объект `HeldSlot`. Он помнит, какой слот был выбран до него, поэтому руку можно занять на пару тиков и затем вернуть прежний слот. Если скрипт выключится до того, как слот вернули, он вернётся автоматически.

```java
slots().using(inventory().findHotbar("ender_pearl"), () -> interaction().useItem(false));

if (slots().bestArmor(Slots.HEAD) >= 0) slots().equipArmor(Slots.HEAD);
```

## Как это работает

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

## Slots

| Метод                    | Тип        | Описание                                                                                           |
| ------------------------ | ---------- | -------------------------------------------------------------------------------------------------- |
| `selected()`             | `int`      | выбранный слот хотбара; `-1`, если игрока нет                                                      |
| `select(hotbar)`         | `HeldSlot` | выбрать слот и сообщить об этом серверу; `null`, если слот не подходит                             |
| `selectSilently(hotbar)` | `boolean`  | выбрать слот без запоминания прежнего                                                              |
| `sync()`                 | `boolean`  | повторно отправить серверу выбранный слот                                                          |
| `using(hotbar, body)`    | `boolean`  | выбрать слот, выполнить тело и вернуть слот на следующем тике, даже если тело выбросило исключение |
| `bestArmor(part)`        | `int`      | слот инвентаря с бронёй лучше надетой или `-1`; считает так же, как Auto Armor                     |
| `equipArmor(part)`       | `boolean`  | надеть лучший предмет брони, клики идут через очередь Quick                                        |

Части тела: `Slots.HEAD`, `CHEST`, `LEGS`, `FEET`.

## HeldSlot

У `HeldSlot` срабатывает только первый вызов из `restore()`, `restoreWhenSafe()`, `keep()` и `close()`. Последующие вызовы ничего не делают.

| Метод               | Тип    | Описание                                                             |
| ------------------- | ------ | -------------------------------------------------------------------- |
| `slot()`            | `int`  | слот, выбранный через этот объект                                    |
| `originalSlot()`    | `int`  | слот, который был выбран до этого                                    |
| `restore()`         | `void` | вернуть слот сразу                                                   |
| `restoreWhenSafe()` | `void` | вернуть на следующем тике, чтобы удар успел уйти с нужным предметом  |
| `keep()`            | `void` | не возвращать слот                                                   |
| `close()`           | `void` | то же, что `restoreWhenSafe()`; `HeldSlot` реализует `AutoCloseable` |

`using` выбирает слот и выполняет действие в одном тике. Если между ними нужна пауза, используйте `select`, храните `HeldSlot` в поле и возвращайте слот вручную. Так сделано в [Автосупе](/examples/auto-soup.md).


---

# 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/actions/slots.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.
