withHook

fun <T> withHook(action: (EntityChange) -> Unit, body: () -> T): T

Calls the specified function body with the given state-change action, registers the action, and returns its result.

The action will be unregistered at the end of the call to the body block.