# ItemDamage

`com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventItemDamage`

**Since:** 1.2.7

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

Fires when polling detects a main-hand, off-hand, or armor stack change attributable to its damage
value. Increased and decreased values both trigger it. When the stack also differs in a way other
than damage, only the corresponding [EventHeldItemChange](../player/EventHeldItemChange.md) or [EventArmorChange](../player/EventArmorChange.md) fires; a damage-only change
triggers this event first and then the corresponding stack-change event.  
[damage](#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventItemDamage_damage) is the resulting value, not the amount changed;  
[item](#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventItemDamage_item) wraps the live stack and can be used to modify it.  

```js
JsMacros.on("ItemDamage", JavaWrapper.methodToJava(function (event) {
  const item = event.item;  
  if (!item.isDamageable()) {
    return;  
  }
  const left = item.getMaxDurability() - event.damage;  
  if (left === 1) {
    Chat.log(`${item.getName().getString()} is one hit from breaking`);  
  }
}))
```

## Constructors

### new EventItemDamage {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventItemDamage_constructor-ItemStack-int-}

```js
new EventItemDamage(ItemStack stack, int damage)
```

Wraps the supplied stack and stores the supplied resulting damage value; it does not apply
that value to the stack or validate it against the stack's damage or durability. A null raw
stack is retained by the helper and causes a [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html) when its accessors
are used.

**Parameters:**
- `stack`: raw stack to retain; may be `null`
- `damage`: resulting damage value to store, not required to match the stack

## Fields

### damage {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventItemDamage_damage}

```js
damage: int
```

The stack's current damage value, not the change since the previous tick or remaining
durability.

### item {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventItemDamage_item}

```js
item: ItemStackHelper
```

The changed stack in its current state. This wraps the live stack; modifications affect the
player's item.

## Methods

### toString {#com.jsmacrosce.jsmacros.client.api.event.impl.inventory.EventItemDamage_toString-}

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

Returns a diagnostic string containing the event name and the current helper string for the
stored item. The format is `%s:{"item": %s}`; the `damage` field is omitted,  
though the helper's string may itself include the raw stack's current damage.

**Returns:** diagnostic event-name and item string
