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

# Packets

Reading and cancelling packets in events and sending your own packets.

This section lets you see the packets exchanged with the server, cancel packets you do not need and send your own. Packets are read in the `packetSend` and `packetReceive` events, which pass a `PacketInfo` with the packet's data. To build and send packets that are inconvenient to create by hand, use `packets()`.

```java
on("packetReceive", event -> {
    PacketInfo packet = (PacketInfo) event.payload();
    if (packet.is("SetHeldSlot")) event.cancel();
});

packets().send(packets().swing(false));
packets().send(packets().look(yaw, pitch, true, false));
```

## How it works

* The handler cancels the packet the server uses to switch the player's held slot.
* Below it, a main hand swing and a rotation are sent.

## PacketInfo

`PacketInfo` is only available inside the handler. Quick reuses these objects, so save the values you need right away. If the packet type is unknown, it only has `type()` and no fields.

| Method                      | Type       | Description                                                                                           |
| --------------------------- | ---------- | ----------------------------------------------------------------------------------------------------- |
| `type()`                    | `String`   | simple class name of the packet, for example `ClientboundSetHeldSlotPacket`; nested classes use a dot |
| `is(name)`                  | `boolean`  | whether the type contains this string, case insensitive: `"SetHeldSlot"` works                        |
| `incoming()`, `outgoing()`  | `boolean`  | came from the server or is going to the server                                                        |
| `has(key)`                  | `boolean`  | whether the field was parsed                                                                          |
| `keys()`                    | `String[]` | names of the parsed fields                                                                            |
| `getInt(key, fallback)`     | `int`      | integer field                                                                                         |
| `getDouble(key, fallback)`  | `double`   | decimal field                                                                                         |
| `getBoolean(key, fallback)` | `boolean`  | flag; a number counts as `true` if it is not zero                                                     |
| `getString(key, fallback)`  | `String`   | string; a number is returned as text                                                                  |

To find out which fields a packet has, print it with `log().info(packet.toString())`: the log will show the type and all the keys.

## Building and sending

A packet sent by the script also goes through `packetSend`, like any other.

| Method                                           | Type      | Description                                   |
| ------------------------------------------------ | --------- | --------------------------------------------- |
| `send(packet)`                                   | `boolean` | send; `false` if there is no connection       |
| `name(packet)`                                   | `String`  | packet class name                             |
| `is(packet, name)`                               | `boolean` | check by name                                 |
| `position(x, y, z, onGround, collision)`         | `Object`  | position packet                               |
| `look(yaw, pitch, onGround, collision)`          | `Object`  | rotation packet                               |
| `onGround(onGround, collision)`                  | `Object`  | only the flags, no coordinates                |
| `attack(entity)`                                 | `Object`  | attack                                        |
| `interact(entity, offhand, sneaking)`            | `Object`  | interaction with an entity                    |
| `interactAt(entity, x, y, z, offhand, sneaking)` | `Object`  | interaction at a point relative to the entity |
| `slot(hotbar)`                                   | `Object`  | hotbar slot change                            |
| `swing(offhand)`                                 | `Object`  | hand swing                                    |
| `blockAction(action, x, y, z, side)`             | `Object`  | action on a block or item                     |
| `playerCommand(action)`                          | `Object`  | player state command                          |
| `closeContainer(containerId)`                    | `Object`  | close a container                             |
| `respawn()`                                      | `Object`  | respawn                                       |
| `useItem(offhand, sequence, yaw, pitch)`         | `Object`  | use the item in hand                          |

Constants from `Packets`:

| Group           | Values                                                                                       |
| --------------- | -------------------------------------------------------------------------------------------- |
| `blockAction`   | `START_DIG`, `ABORT_DIG`, `STOP_DIG`, `DROP_STACK`, `DROP_ITEM`, `RELEASE_USE`, `SWAP_HANDS` |
| sides           | `DOWN`, `UP`, `NORTH`, `SOUTH`, `WEST`, `EAST`                                               |
| `playerCommand` | `SPRINT_START`, `SPRINT_STOP`, `ELYTRA`, `STOP_SLEEPING`, `OPEN_INVENTORY`                   |

There is no sneaking in `playerCommand`: since 26.2 it is sent in the input packet. For sneaking, use `control().sneaking(boolean)`.

If the packet you need is not listed here, send it through a mixin, see [Mixins and hooks](/en/extras/mixins.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/en/actions/packets.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.
