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

# Rays and the crosshair

How to find the block, its side and the entity under the crosshair.

This page collects the methods that help you find out where the player is looking: at which block, at which side of it and at which entity.

```java
Block looking = world().raycastBlock(5.0);
if (looking != null && looking.is("chest")) {
    chat("Chest at " + looking.x() + " " + looking.y() + " " + looking.z());
}

Entity aimed = entities().crosshair();
if (aimed != null) chat("Aiming at " + aimed.name());
```

## Blocks

| Method                                    | Type    | Description                                                      |
| ----------------------------------------- | ------- | ---------------------------------------------------------------- |
| `world().raycastBlock(distance)`          | `Block` | the first block along the ray from the eyes or `null`            |
| `world().raycastBlock(distance, liquids)` | `Block` | the same, but you can choose whether water and lava stop the ray |
| `world().raycastSide(distance)`           | `int`   | which side of the block the ray hit; `-1` if the ray hit nothing |

Side numbers: 0 bottom, 1 top, 2 north, 3 south, 4 west, 5 east. `interaction().useBlock` and `startBreaking` accept the same numbers, see [Interaction](/en/actions/interaction.md).

## Entities

| Method                                                               | Type     | Description                                            |
| -------------------------------------------------------------------- | -------- | ------------------------------------------------------ |
| `entities().crosshair()`                                             | `Entity` | the entity under the crosshair or `null`               |
| `interaction().attackPoint(entity)`                                  | `Point`  | the point on the target's hitbox closest to the player |
| `interaction().attackPoint(entity, mode, maxDistance, throughWalls)` | `Point`  | a point that takes the mode and walls into account     |

`attackPoint` does not cast a ray from the eyes. It looks for a point on the hitbox that can actually be hit. Mode `"nearest"` takes the closest point, `"center"` the center, and `"multi"` tries several points and checks whether walls block them. If there is nothing to hit, `null` is returned.

## Angle to a point

`rotations().angleTo(x, y, z)` returns how many degrees the view direction differs from the direction to a point, from 0 to 180. This is useful when you only need to check whether the player is looking roughly in the right direction, without rays. More on the [Rotations](/en/actions/rotations.md) page.


---

# 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/game/raycast.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.
