# Riding

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

**Since:** 1.5.0

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

Fires from a `startRiding` return path when the local player attempts to mount, or when
the player begins removing an existing vehicle. The mount event does not establish that riding
succeeded. [state](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventRiding_state) is `true` for mounting and `false` for dismounting;  
[entity](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventRiding_entity) is the targeted entity or former vehicle, respectively. The dismount event also
fires for externally caused dismounts.  
```js
JsMacros.on("Riding", JavaWrapper.methodToJava(function (event) {
  if (event.state) {
    Chat.log(`Mounting ${event.entity.getType()}`);  
  } else {
    Chat.log(`Dismounted from ${event.entity.getType()}`);  
  }
}))
```

## Constructors

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

```js
new EventRiding(boolean state, Entity entity)
```

Initializes the event with the supplied state and a wrapped entity; this does not perform a
mount or dismount.

**Parameters:**
- `state`: `true` for mounting or `false` for dismounting; this flag does not
             establish that riding succeeded
- `entity`: raw Minecraft entity to wrap: target when mounting or former vehicle when dismounting; `null` fails with [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html) during wrapping

## Fields

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

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

The mounted entity when [state](#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventRiding_state) is `true`, or the former vehicle when it is
`false`. It is wrapped in the corresponding [EntityHelper](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/entity/EntityHelper.md) subclass.

### state {#com.jsmacrosce.jsmacros.client.api.event.impl.player.EventRiding_state}

```js
state: boolean
```

`true` when the player started riding, `false` when the player dismounted.

## Methods

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

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

Returns a diagnostic string containing the event name and the state and entity values.

**Returns:** the event name followed by `{"state": boolean, "entity": entity}`, with
        the boolean unquoted and the entity represented by its `toString()` result
