# BlockUpdate

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

**Since:** 1.2.7

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

Fires after a block-state or block-entity update packet is handled. Section updates produce one
`'STATE'` event per block; block-entity data packets produce `'ENTITY'` events.  
Listeners can be narrowed down with a
[FiltererBlockUpdate](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/event/filterer/FiltererBlockUpdate.md), which can match
on position, area, block id, block states and update type.  
```js
JsMacros.on("BlockUpdate", JavaWrapper.methodToJava(function (event) {
  const pos = event.block.getBlockPos();  
  if (event.updateType === "ENTITY") {
    Chat.log(`BlockEntity data at ${pos.getX()}, ${pos.getY()}, ${pos.getZ()}`);  
  } else {
    Chat.log(`Block became ${event.block.getId()} at ${pos.getX()}, ${pos.getY()}, ${pos.getZ()}`);  
  }
}))
```

**Filterer:** [FiltererBlockUpdate](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/event/filterer/FiltererBlockUpdate.md). Create it with `JsMacros.createEventFilterer("BlockUpdate")` and pass it to the filterer overload of `JsMacros.on`.

## Constructors

### new EventBlockUpdate {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventBlockUpdate_constructor-BlockState-BlockEntity-BlockPos-String-}

```js
new EventBlockUpdate(BlockState block, BlockEntity blockEntity, BlockPos blockPos, String updateType)
```

Initializes the event with a helper wrapping the supplied block state and the supplied update label.  
The block state must be non-null; a null `block` causes [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html) during
construction. The entity and position are retained as supplied without validation or copying;  
a null position is accepted here but causes [NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html) when position-dependent
access or [toString()](#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventBlockUpdate_toString-) is used. The update label is stored unchanged and is not restricted
to `"STATE"` or `"ENTITY"`.

**Parameters:**
- `block`: the block state to wrap; must not be `null`
- `blockEntity`: the associated block entity, retained as supplied and possibly `null`
- `blockPos`: the associated position, retained as supplied and possibly `null`
- `updateType`: the update label, retained unchanged and possibly `null`

## Fields

### block {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventBlockUpdate_block}

```js
block: BlockDataHelper
```

Snapshot of the block state, position, and optional block entity associated with this update.  
For `'ENTITY'` updates, it also exposes block-entity NBT data. Read the position from
[getBlockPos()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/BlockDataHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getBlockPos-), the id from
[getId()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/BlockDataHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getId-), the NBT from
[getNBT()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/BlockDataHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getNBT-) and the state from
[getBlockState()](../../../../../../../../../classes/com/jsmacrosce/jsmacros/client/api/helper/world/BlockDataHelper.md#com.jsmacrosce.jsmacros.client.api.helper.world.BlockDataHelper_getBlockState-).

### updateType {#com.jsmacrosce.jsmacros.client.api.event.impl.world.EventBlockUpdate_updateType}

```js
updateType: String
```

Kind of update that triggered this event:  
`'STATE'` for a block state change, `'ENTITY'` for a block entity data update.

## Methods

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

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

Returns a diagnostic string containing the event name and the block helper's string form.  
Formatting dereferences the stored position; if it is `null`, this method throws
[NullPointerException](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/NullPointerException.html).

**Returns:** the event name and block helper formatted as `%s:{"block": %s}`
