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

# Slots and armor

Switching the held slot for a short time and putting on better armor.

`slots()` is for when you need an item in hand for a short time: for example, take a pearl, throw it and switch back to your sword. It can also put on better armor.

`select(hotbar)` returns a `HeldSlot` object. It remembers which slot was selected before it, so you can use the hand for a couple of ticks and then switch back to the previous slot. If the script is disabled before the slot is switched back, it is restored automatically.

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

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

## How it works

* The first line takes a pearl from the hotbar, throws it and switches back to the previous slot on the next tick.
* The second line puts on a helmet if the inventory has one better than the one being worn.

## Slots

| Method                   | Type       | Description                                                                                       |
| ------------------------ | ---------- | ------------------------------------------------------------------------------------------------- |
| `selected()`             | `int`      | selected hotbar slot; `-1` if there is no player                                                  |
| `select(hotbar)`         | `HeldSlot` | select a slot and tell the server; `null` if the slot is not valid                                |
| `selectSilently(hotbar)` | `boolean`  | select a slot without remembering the previous one                                                |
| `sync()`                 | `boolean`  | send the selected slot to the server again                                                        |
| `using(hotbar, body)`    | `boolean`  | select a slot, run the body and switch back on the next tick, even if the body threw an exception |
| `bestArmor(part)`        | `int`      | inventory slot with armor better than what is worn, or `-1`; scored the same way as Auto Armor    |
| `equipArmor(part)`       | `boolean`  | put on the best armor piece, clicks go through Quick's queue                                      |

Body parts: `Slots.HEAD`, `CHEST`, `LEGS`, `FEET`.

## HeldSlot

Only the first call out of `restore()`, `restoreWhenSafe()`, `keep()` and `close()` has an effect on a `HeldSlot`. Later calls do nothing.

| Method              | Type   | Description                                                                     |
| ------------------- | ------ | ------------------------------------------------------------------------------- |
| `slot()`            | `int`  | the slot selected through this object                                           |
| `originalSlot()`    | `int`  | the slot that was selected before                                               |
| `restore()`         | `void` | switch back right away                                                          |
| `restoreWhenSafe()` | `void` | switch back on the next tick, so the hit has time to go out with the right item |
| `keep()`            | `void` | do not switch back                                                              |
| `close()`           | `void` | same as `restoreWhenSafe()`; `HeldSlot` implements `AutoCloseable`              |

`using` selects the slot and runs the action in the same tick. If you need a pause between them, use `select`, keep the `HeldSlot` in a field and switch back yourself. This is how [Auto soup](/en/examples/auto-soup.md) does it.


---

# 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/en/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.
