# InteractEntity

`com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity`

**Cancellable:** No. Calling `event.cancel()` throws `UnsupportedOperationException`.

Fires after the local player's entity-interact action returns, except when it returns
[InteractionResult.FAIL](https://mcsrc.dev/2/26.3/net/minecraft/world/InteractionResult). [result](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity_result) is true when the result
consumes the action and false when it does not; false is not an event rejection. This event
reports the interact action, not attacks, which use
[EventAttackEntity](EventAttackEntity.md).  
```js
JsMacros.on("InteractEntity", JavaWrapper.methodToJava(function (event) {
  Chat.log(`${event.result ? "Consumed" : "Passed"}: ${event.entity.getType()}`);  
}))
```

```js
JsMacros.on("InteractEntity", JavaWrapper.methodToJava(function (event) {
  if (event.result) {
    Chat.log(`${event.offhand ? "Off hand" : "Main hand"} used on ${event.entity.getType()}`);  
  }
}))
```

## Constructors

### new EventInteractEntity {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity_constructor-boolean-boolean-Entity-}

```js
new EventInteractEntity(boolean offhand, boolean accepted, Entity entity)
```

Stores the interaction hand, consumption flag, and wrapped entity; this constructor does
not perform or dispatch an interaction.

**Parameters:**
- `offhand`: whether the supplied hand flag indicates the off hand; `false`
                indicates the main hand
- `accepted`: the supplied action-consumption flag, stored as `result`
- `entity`: the Minecraft entity to wrap; wrapping fails with [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html)
              if it is `null`

## Fields

### entity {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity_entity}

```js
entity: EntityHelper<?>
```

The clicked entity, wrapped in the most specific
[EntityHelper](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/EntityHelper.md) subclass for its
type, so it can be narrowed with `instanceof EntityHelpers.Player` and the other
namespace types; `asLiving()`, `asPlayer()` and the other `as...()`
helpers are casts. Its type is available from
[getType()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/EntityHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getType-)
and its name from
[getName()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/EntityHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.entity.EntityHelper_getName-).

### offhand {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity_offhand}

```js
offhand: boolean
```

`true` if the click was made with the off hand, `false` if it was made with the
main hand.

### result {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity_result}

```js
result: boolean
```

`true` if the interaction result consumes the action, `false` if it does not.  
The event is not fired when the result is `FAIL`.

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventInteractEntity_toString-}

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

Returns this event's diagnostic string, including its event name, entity representation,  
and stored result flag.

**Returns:** a string formatted as `%s:{"entity": %s, "result": "%s"}`; the entity
        field uses the helper's runtime representation, and the offhand flag is omitted
