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 entity equipment support #254

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mymatsubara
Copy link

@mymatsubara mymatsubara commented Feb 20, 2023

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

Minecraft.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 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 dyc3 self-requested a review February 20, 2023 23:50
Copy link
Collaborator

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start. Mostly minor nitpicks.

crates/valence/src/equipment.rs Outdated Show resolved Hide resolved
crates/valence/src/equipment.rs Outdated Show resolved Hide resolved
crates/valence/src/equipment.rs Outdated Show resolved Hide resolved
crates/valence/src/equipment.rs Outdated Show resolved Hide resolved
crates/valence/examples/random_equipment.rs Outdated Show resolved Hide resolved
crates/valence/src/equipment.rs Outdated Show resolved Hide resolved
crates/valence/src/equipment.rs Show resolved Hide resolved
@mymatsubara
Copy link
Author

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

@murl-digital
Copy link
Contributor

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

@LeoDog896
Copy link
Contributor

@mymatsubara are you still working on this PR?

@mymatsubara
Copy link
Author

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

@LeoDog896
Copy link
Contributor

👍 I'll fork your valence fork to continue this PR.

@mymatsubara
Copy link
Author

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

This was referenced Oct 12, 2024
dyc3 pushed a commit that referenced this pull request Oct 23, 2024
# 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants