Add entity equipment support
Description
Main additions:
- Add a Bevy
ComponentcalledEquipmentwhich tracks entity's current equipment and if they have been modified. - Add a Bevy system called
update_equipmentwhich sendsSetEquipmentpackets to all clients in view, when an entity with aEquipmentcomponent is modified. - Modify
McEntity::write_init_packetsto also sendSetEquipmentpackets. - Add
random_equipment.rsexample
These change only have cosmetic effect for now, but the Equipment component can be also used when dealing with game logic when equipment data is required.
Test Plan
Steps:
cargo test -p valence --tests(there is a unit test inequipment.rs)- Run the
random_equipmentexample with:cargo run --example random_equipment - Join the server on
localhost - An armor stand is spawned near the spawn point
- Every
McEntitywill be assigned a random set of equipment every second
Video of the random_equipment example
https://user-images.githubusercontent.com/49251043/220204501-9cfa5e61-d486-4ecc-93d8-34e965c63dfd.mp4
PROBLEM: As we can see from the video, our client only display equipment changes from other players, but not from our own player entity. This happens because the equipment of our player entity are tracked client-side, thus the SetEquipment packet does have effect when the entity_id is equal to your player entity id. There might me another packet type which can be used for such case, but I'm not sure don't know which one 😞
Related
Issue related: #223
@dyc3 Thank you for the review! I've made some changes based on your recomendations
Just quickly chiming in, I think the packet you're looking for to set the player's inventory is Set Container Content, see: https://wiki.vg/Protocol#Set_Container_Content
This is sent on first connect to initialize the player inventory, and I think Set Container Slot can be used afterwards to target the armor specifically, also see: https://wiki.vg/Protocol#Set_Container_Slot
@mymatsubara are you still working on this PR?
@LeoDog896 I stopped working on it. Feel free to close it
:+1: I'll fork your valence fork to continue this PR.
@LeoDog896 Thank you very much! If you got any question about the code, feel free to ask me.