# Sound

`com.jsmacrosce.jsmacros.client.api.event.impl.world.EventSound`

**Since:** 1.2.7

**Cancellable:** Yes. Call `event.cancel()` in a handler before releasing the event lock.

Fires when the sound engine receives a sound instance, before it attempts playback. The reported
 position may be relative rather than world coordinates. Cancelling prevents the playback attempt.  
 ```js
JsMacros.on("Sound", true, JavaWrapper.methodToJava(function (event) {
  if (event.sound === null) {
    return;  
  }
  Chat.log(`Playing ${event.sound} (volume ${event.volume}, pitch ${event.pitch})`);  
  if (event.volume > 2.0) {
    event.cancel();  
  }
}))
 ```

## Constructors

### new EventSound {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventSound_constructor-String-float-float-double-double-double-}

```js
new EventSound(String sound, float volume, float pitch, double x, double y, double z)
```

Initializes this event with the supplied sound label, multipliers, and coordinates; it does
 not play a sound. The nullable label is stored as provided, and the coordinates are reported
 as supplied without conversion; they may be relative rather than world coordinates.

**Parameters:**
- `sound`: nullable sound label; it is stored as provided, not looked up or validated
- `volume`: supplied volume multiplier, stored unchanged
- `pitch`: supplied pitch multiplier, stored unchanged
- `x`: supplied x coordinate, stored unchanged
- `y`: supplied y coordinate, stored unchanged
- `z`: supplied z coordinate, stored unchanged

## Fields

### pitch {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventSound_pitch}

```js
pitch: float
```

Pitch reported by the sound instance; `1.0` is the unmodified value. If reading the
 pitch throws a `NullPointerException`, this is `1.0`.

### position {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventSound_position}

```js
position: Pos3D
```

Coordinates reported by the sound instance; they may be relative rather than world coordinates.

### sound {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventSound_sound}

```js
sound: String
```

Sound id reported by the instance, or `null` if it reported none.

### volume {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventSound_volume}

```js
volume: float
```

Volume reported by the sound instance; `1.0` is the unmodified value. If reading the
 volume throws a `NullPointerException`, this is `1.0`.

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventSound_toString-}

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

Returns a diagnostic string containing the event name and quoted sound label. The label is
 not escaped; a null label appears as the quoted text `"null"`. Volume, pitch, and
 position are omitted.

**Returns:** event name followed by `:{"sound": "..."}`; this is not a complete JSON
         representation of the event
