# EntityUnload

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

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

Fires when an entity is removed from the client world. The reason is the removal reason's name;  
 the available names depend on the Minecraft version.  
 ```js
JsMacros.on("EntityUnload", JavaWrapper.methodToJava(function (event) {
  Chat.log(`${event.entity.getType()} unloaded (${event.reason})`);  
}))
 ```

## Constructors

### new EventEntityUnload {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventEntityUnload_constructor-Entity-Entity.RemovalReason-}

```js
new EventEntityUnload(Entity e, Entity.RemovalReason reason)
```

Wraps the entity and captures the removal reason as a string; it does not perform the removal.  
 Construction throws [NullPointerException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/NullPointerException.html) if either argument is `null`.

**Parameters:**
- `e`: the Minecraft entity to wrap; must not be `null`
- `reason`: the removal reason to convert to a string; must not be `null`

## Fields

### entity {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventEntityUnload_entity}

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

The entity being removed from the client world.

### reason {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventEntityUnload_reason}

```js
reason: String
```

The removal reason's name; available names depend on the Minecraft version.

## Methods

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

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

Returns a diagnostic string containing the event name, entity helper string, and captured reason.  
 The format is `%s:{"entity": %s, "reason": "%s"}`; the reason is the captured string,  
 quoted in the output, not a newly computed enum value or serialized entity data.

**Returns:** the diagnostic string in the format described above
