Add entity equipment support#254
Conversation
dyc3
left a comment
There was a problem hiding this comment.
This is a good start. Mostly minor nitpicks.
Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
|
@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 This is sent on first connect to initialize the player inventory, and I think |
|
@mymatsubara are you still working on this PR? |
|
@LeoDog896 I stopped working on it. Feel free to close it |
|
👍 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. |
# 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.
Description
Main additions:
ComponentcalledEquipmentwhich tracks entity's current equipment and if they have been modified.update_equipmentwhich sendsSetEquipmentpackets to all clients in view, when an entity with aEquipmentcomponent is modified.McEntity::write_init_packetsto also sendSetEquipmentpackets.random_equipment.rsexampleThese change only have cosmetic effect for now, but the
Equipmentcomponent 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)random_equipmentexample with:cargo run --example random_equipmentlocalhostMcEntitywill be assigned a random set of equipment every secondVideo of the
random_equipmentexampleMinecraft.1.19.3.-.Multiplayer.3rd-party.Server.2023-02-20.18-26-53.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
SetEquipmentpacket does have effect when theentity_idis 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