Skip to content

Damage ​

com.jsmacrosce.jsmacros.client.api.event.impl.player.EventDamage

Since1.2.7Not cancellable

Fires when a call decreases the local player's health, before the incoming value is applied.
It dispatches before EventHealthChange,
which dispatches before EventEntityDamaged.
The injected event supplies a generic damage source, so source is its generic damage type ID and attacker is null.

js
JsMacros.on("Damage", JavaWrapper.methodToJava(function (event) {
 Chat.log(`Took ${event.change} damage, ${event.health} hp left`);  
 if (4.0 >= event.health) {
   Chat.log("About to die");  
 }
}))

Constructors ​

new EventDamage ​

new EventDamage(DamageSource source, float health, float change)#
Initializes the event with the supplied damage source and health values. The source's message ID is stored as source; the causing entity is wrapped as attacker, or null when absent. A null source throws NullPointerException.

Parameters:

  • source: damage source used to obtain its message ID and causing entity
  • health: incoming health value
  • change: amount of health lost

Fields ​

change ​

change: floatread-only#
Amount of health lost; positive, unlike the matching change which is negative on the same change.

health ​

health: floatread-only#
Incoming player health value, before it is applied.

Methods ​

toString ​

toString(): String#
Returns a diagnostic string containing this event's name, health, and change values.
Returns: a string in the form eventName:{"health": %f, "change": %f}