# HitResultHelper

`com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper`

**Since:** 1.9.1

Wraps a crosshair hit result, with shared access to its hit position and subtype-specific access
 for block and entity hits. Use [InteractionManagerHelper.getTarget()](../InteractionManagerHelper.md#com.jsmacrosce.jsmacros.client.api.helper.InteractionManagerHelper_getTarget-)
 for the current target or [resolve(HitResult)](#com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper_resolve-HitResult-) to wrap a raw result. Misses use [Block](HitResultHelper.Block.md).  
 ```js
const interactions = Player.interactions();  
const target = interactions === null ? null : interactions.getTarget();  
if (target === null) {
  // nothing under the crosshair at all
} else if (target instanceof HitResults.Entity) {
  const entity = target.getEntity();  
  Chat.log(`the crosshair is on ${entity.getName()} at ${target.getPos()}`);  
} else if (target instanceof HitResults.Block) {
  const blockPos = target.getBlockPos();  
  if (blockPos !== null) {
    Chat.log(`the crosshair is on the ${target.getSide().getName()} face of ${blockPos}`);  
  }
}

// the point where the ray landed is on all three kinds
if (target !== null) { Chat.log(target.getPos()); }
 ```

Available in scripts as `HitResults.Result`.

## Type Parameters

- `T`: the Minecraft hit-result type wrapped by this helper

## Nested types

- [Block](HitResultHelper.Block.md)
- [Entity](HitResultHelper.Entity.md)

## Methods

### asBlock {#com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper_asBlock-}

```js
asBlock(): HitResultHelper.Block
```

Returns this target as a block hit or miss, or `null` for other hit-result types.

**Returns:** this target as a [Block](HitResultHelper.Block.md), or `null` if it is not a block target.

**Since:** 1.9.1

### asEntity {#com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper_asEntity-}

```js
asEntity(): HitResultHelper.Entity
```

Returns this target as an entity hit, or `null` for other hit-result types.

**Returns:** this target as an [Entity](HitResultHelper.Entity.md), or `null` if it is not an entity target.

**Since:** 1.9.1

### getPos {#com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper_getPos-}

```js
getPos(): Pos3D
```

Returns the hit location as a world-space point, without rounding its coordinates.

**Returns:** where the hit landed, as a point in the world.

**Since:** 1.9.1

### resolve {#com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper_resolve-HitResult-}

```js
static resolve(HitResult hr): HitResultHelper<?>
```

Wraps a raw hit result as a [Block](HitResultHelper.Block.md) for block hits and misses, or an [Entity](HitResultHelper.Entity.md) for
 entity hits. Returns `null` for a null input.

**Parameters:**
- `hr`: the raw hit result to wrap, or `null`.

**Returns:** the matching subclass of this helper, or `null` if `hr` was `null`.

**Since:** 1.9.1

### toString {#com.jsmacrosce.jsmacros.client.api.helper.world.HitResultHelper_toString-}

```js
toString(): String
```

Returns a diagnostic string containing the hit position.

**Returns:** a diagnostic containing the position rendered from `getPos()`.
