Skip to content

BlockUpdate ​

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

Since1.2.7Not cancellable

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, 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. Create it with JsMacros.createEventFilterer("BlockUpdate") and pass it to the filterer overload of JsMacros.on.

Constructors ​

new EventBlockUpdate ​

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 during construction. The entity and position are retained as supplied without validation or copying; a null position is accepted here but causes NullPointerException when position-dependent access or 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 ​

block: BlockDataHelperread-only#
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(), the id from getId(), the NBT from getNBT() and the state from getBlockState().

updateType ​

updateType: Stringread-only#
Kind of update that triggered this event: 'STATE' for a block state change, 'ENTITY' for a block entity data update.

Methods ​

toString ​

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.
Returns: the event name and block helper formatted as %s:{"block": %s}