Skip to content

Entity Equipment #662

Description

@maxomatic458

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

#[derive(Debug, Default, Clone, Component)]
pub struct Equipment {
    main_hand: ItemStack,
    off_hand: ItemStack,
    boots: ItemStack,
    leggings: ItemStack,
    chestplate: ItemStack,
    helmet: ItemStack,

    /// Contains a set bit for each modified slot in `slots`.
    #[doc(hidden)]
    pub changed: u8,
}

impl Equipment {
    pub const SLOT_COUNT: u8 = 5;
    
    pub const MAIN_HAND_SLOT: u8 = 0;
    pub const OFF_HAND_SLOT: u8 = 1;
    pub const BOOTS_SLOT: u8 = 2;
    pub const LEGGINGS_SLOT: u8 = 3;
    pub const CHESTPLATE_SLOT: u8 = 4;
    pub const HELMET_SLOT: u8 = 5;
    
    pub fn main_hand(&self) -> &ItemStack {
        self.main_hand;
    }
    
    pub fn set_main_hand(&self) {
         ...
     }
     ...
}

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions