> For the complete documentation index, see [llms.txt](https://walksy.gitbook.io/walksylib-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://walksy.gitbook.io/walksylib-docs/advanced/events.md).

# Events

WalksyLib provides client events in `main.walksy.lib.core.event.WalksyLibEvents`. Example:

```java
WalksyLibEvents.END_CLIENT_TICK.register(minecraft -> {
});
```

## Lifecycle & ticking

| Event                                               | Parameters    | Fires                                      |
| --------------------------------------------------- | ------------- | ------------------------------------------ |
| `CLIENT_READY`                                      | `Minecraft`   | Once, when the client has finished loading |
| `START_CLIENT_TICK` / `END_CLIENT_TICK`             | `Minecraft`   | Every client tick                          |
| `START_LOCAL_PLAYER_TICK` / `END_LOCAL_PLAYER_TICK` | `LocalPlayer` | Every tick of the local player             |
| `CLIENT_JOIN_SERVER`                                | login packet  | When joining a world or server             |
| `CLIENT_LEFT_SERVER`                                | none          | When leaving a world or server             |

## Rendering

| Event        | Parameters                     | Fires                                           |
| ------------ | ------------------------------ | ----------------------------------------------- |
| `RENDER_HUD` | `WLGraphics2D`, `DeltaTracker` | While the HUD is drawn                          |
| `RENDER_3D`  | `WLGraphics3D`                 | During world rendering, for drawing in 3D space |

```java
WalksyLibEvents.RENDER_3D.register(graphics -> {
});
```

## Input

| Event                | Parameters                          |
| -------------------- | ----------------------------------- |
| `KEY_INPUT`          | `code, action, scancode, modifiers` |
| `MOUSE_BUTTON_INPUT` | `button, action, modifiers`         |
| `MOUSE_SCROLL_INPUT` | `xOffset, yOffset`                  |
| `FILE_DROP`          | dropped files, failed count         |

## Gameplay

| Event            | Parameters           | Fires                                   |
| ---------------- | -------------------- | --------------------------------------- |
| `ATTACK_ENTITY`  | local player, target | When the local player attacks an entity |
| `SHIELD_DISABLE` | player               | When a player's shield is disabled      |

## Packets

| Event                  | Fires                                        |
| ---------------------- | -------------------------------------------- |
| `START_RECEIVE_PACKET` | Before a packet is handled. **Cancellable.** |
| `END_RECEIVE_PACKET`   | After a packet is handled                    |

```java
WalksyLibEvents.START_RECEIVE_PACKET.register((packet, listener, ensureSameThread, cancellable) -> {
    if (packet instanceof ClientboundSoundPacket && muted) {
        cancellable.cancel();
    }
});
```

Calling `cancellable.cancel()` stops the packet from being handled and skips any remaining listeners.
