valence
valence copied to clipboard
Add events for when an entity has been loaded or unloaded by a client.
Describe the problem related to your feature request.
Within a plugin, it may be necessary to detect when an entity has been loaded or unloaded by a client. Some examples include:
- Boss bars, where the boss bar associated with a boss should be created or destroyed as the boss enters and exits the client's view.
- Entity effect packets that should be sent for the loaded entity with effects.
Currently, entity initialization and deinitialization is hard-coded in valence and cannot be extended from the outside.
What solution would you like?
Add two new events:
#[derive(Event)]
pub struct EntityLoadEvent {
pub client: Entity,
pub entity: Entity,
}
#[derive(Event)]
pub struct EntityUnloadEvent {
pub client: Entity,
pub entity: Entity,
}
Send them at the appropriate time in the client update systems.
Annoyingly, sending the events can't happen in parallel, so the event writer will need to be wrapped in a mutex or the events will need to be placed in an intermediate buffer before sending.
Benchmarks should be done to make sure this isn't hurting performance too much.
What alternative(s) have you considered?
- We could just ignore the problem and grab all the data we need in the client update systems' entity query. Status quo is more efficient than dealing with events.
- Detect entity init and deinit from the entitys' chunk position. This is error prone and maybe not possible.