Skip to content

Sound ​

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

Since1.2.7Cancellable

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", 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 ​

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 ​

pitch: floatread-only#
Pitch reported by the sound instance; 1.0 is the unmodified value. If reading the pitch throws a NullPointerException, this is 1.0.

position ​

position: Pos3Dread-only#
Coordinates reported by the sound instance; they may be relative rather than world coordinates.

sound ​

sound: Stringread-only#
Sound id reported by the instance, or null if it reported none.

volume ​

volume: floatread-only#
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 ​

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