valence icon indicating copy to clipboard operation
valence copied to clipboard

Add entity equipment support

Open mymatsubara opened this issue 2 years ago • 6 comments

Description

Main additions:

  • Add a Bevy Component called Equipment which tracks entity's current equipment and if they have been modified.
  • Add a Bevy system called update_equipment which sends SetEquipment packets to all clients in view, when an entity with a Equipment component is modified.
  • Modify McEntity::write_init_packets to also send SetEquipment packets.
  • Add random_equipment.rs example

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:

  1. cargo test -p valence --tests (there is a unit test in equipment.rs)
  2. Run the random_equipment example with: cargo run --example random_equipment
  3. Join the server on localhost
  4. An armor stand is spawned near the spawn point
  5. Every McEntity will 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

mymatsubara avatar Feb 20 '23 22:02 mymatsubara

@dyc3 Thank you for the review! I've made some changes based on your recomendations

mymatsubara avatar Feb 22 '23 01:02 mymatsubara

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

murl-digital avatar Feb 23 '23 23:02 murl-digital

@mymatsubara are you still working on this PR?

tristan-f-r avatar Jun 28 '23 14:06 tristan-f-r

@LeoDog896 I stopped working on it. Feel free to close it

mymatsubara avatar Jun 28 '23 14:06 mymatsubara

:+1: I'll fork your valence fork to continue this PR.

tristan-f-r avatar Jun 28 '23 14:06 tristan-f-r

@LeoDog896 Thank you very much! If you got any question about the code, feel free to ask me.

mymatsubara avatar Jun 28 '23 18:06 mymatsubara