BlockUpdate
com.jsmacrosce.jsmacros.client.api.event.impl.world.EventBlockUpdate
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 benullblockEntity: the associated block entity, retained as supplied and possiblynullblockPos: the associated position, retained as supplied and possiblynullupdateType: the update label, retained unchanged and possiblynull
Fields
block
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
Methods
toString
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}