Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add events for when an entity has been loaded or unloaded by a client. #442

Open
rj00a opened this issue Aug 4, 2023 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@rj00a
Copy link
Member

rj00a commented Aug 4, 2023

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.
@rj00a rj00a added the enhancement New feature or request label Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant