-
-
Notifications
You must be signed in to change notification settings - Fork 151
Entity Equipment #662
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
Comments
This seems like a good thing, you might not always want the equipment and player inventories to be in sync. |
im currently working on implementing this and im looking for a way to send the equipment of an entity as soon as the player "renders" (or requests the data) from the server. |
I would have a look on how we handle entity changes and updates, there is currently one system to handle most of the entity related packets: https://github.com/valence-rs/valence/blob/76fb18f185913a9279862a3084787b2afeb514f2/crates/valence_entity/src/query.rs the systems above shows how it works when an entity is loaded by the client One approach would just be to also add a I have not really considered what benefits/downsides it is to have this as its own plugin myself, I think there might be performance differences between the two. Maybe someone else than me has a better idea if a change such as this deserves its own crate/plugin (as opposed to living in the valance_entity crate and systems). Regardless I think that's the rough idea on how it could be achieved, no matter what approach you think is appropriate. |
thanks! i believe it would probably be the best to have a seperate |
@dyc3 would you be ok with having equipment logic in a seperate (but activated by default) plugin? |
i believe we could maybe emit a event here: |
something like this could work: /// This event will be emitted when a entity is unloaded for a client (e.g when moving out of range of the entity).
#[derive(Debug, Clone, PartialEq, Event)]
pub struct UnloadEntityForClientEvent {
/// The client to unload the entity for.
pub client: Entity,
/// The MC Entity ID of the entity that will be unloaded.
pub entity_unloaded: EntityId,
}
/// This event will be emitted when a entity is loaded for a client (e.g when moving into range of the entity).
#[derive(Debug, Clone, PartialEq, Event)]
pub struct LoadEntityForClientEvent {
/// The client to load the entity for.
pub client: Entity,
/// The MC Entity ID of the entity that will be loaded.
pub entity_loaded: EntityId,
}
pub(crate) fn update_view_and_layers(
...
mut unload_entity_writer: EventWriter<UnloadEntityForClientEvent>,
mut load_entity_writer: EventWriter<LoadEntityForClientEvent>,
) {
// Wrap the events in this, so we only need one channel.
enum ChannelEvent {
UnloadEntity(UnloadEntityForClientEvent),
LoadEntity(LoadEntityForClientEvent),
}
let (tx, rx) = crossbeam_channel::unbounded();
(clients).par_iter_mut().for_each(
// in here, send the events to our channel
...
);
// Send the events using the bevy event writers
for event in rx.try_iter() {
match event {
ChannelEvent::UnloadEntity(event) => {
unload_entity_writer.send(event);
},
ChannelEvent::LoadEntity(event) => {
load_entity_writer.send(event);
},
};
}
} I believe this would also be generally useful outside of equipment context. |
# Objective - make valence work with entity equipment (armor, main/off hand items) # Solution adds the crate `valence_equipment` that exposes the Equipment Plugin. every `LivingEntity` will have a `Equipment` Component. The Equipment plugin will NOT be compatible with the inventory by default (thats intended, as that makes it possible to use the equipment feature without the inventory feature + I do think there are probably use cases where you want to make players appear as having armor, although they dont have it in their inventory) This PR would add Events when entities are (un)loaded by a player (used for sending equipment once the player loads an entity). I do believe this might also be a useful feature outside of the equipment feature. used #254 as reference + stole example idea fixes #662 Opening as a draft for now (might refactor the updating/event emitting system). Let me know what you think of the Entity Load/Unload events.
Uh oh!
There was an error while loading. Please reload this page.
Describe the problem related to your feature request.
Valence does not sync player equipment (held items, armor, etc)
What solution would you like?
a Equipment plugin which exposes a Equipment component.
What alternative(s) have you considered?
this could also be implemented in the inventory crate, although in my opinion it would be better to implement equipment as a seperate Plugin.
Additional context
related #254
I believe an Equipment Component could be implemented like this
that would make it pretty easy to use.
I also think this should be as seperate as possible from
valence_inventory
(so people using this crate would have to implement custom logic to update equipment based on inventory changes, but that should not be to hard)we would have to use Inventory to get the HeldItem
thats the packet https://wiki.vg/index.php?title=Protocol&oldid=18375#Set_Equipment
Edit:
since we would have to use setters/getters (so we garuantee that updated the changed field)
we might as well store the actual items in a list instead of the fields.
Edit 2:
My idea was that valence would only provide this component, and an updater system.
So you would have to implement custom logic if you want to lets say set your equipment when you put on armor (as i do think there are use cases where you dont want to bind it to the inventory)
Any thoughts on that?
The text was updated successfully, but these errors were encountered: