Crate valence_equipment

Source
Expand description

§valence_equipment

Manages Minecraft’s entity equipment (armor, held items) via the Equipment component. By default this is separated from an entities Inventory (which means that changes are only visible to other players), but it can be synced by attaching the EquipmentInventorySync component to a entity (currently only Players).

§Example

use bevy_ecs::prelude::*;
use valence_equipment::*;
use valence_server::{
    ItemStack, ItemKind,
    entity::player::PlayerEntity,
};
// Add equipment to players when they are added to the world.
fn init_equipment(
    mut clients: Query<
        &mut Equipment,
        (
            Added<Equipment>,
            With<PlayerEntity>,
        ),
    >,
) {
    for mut equipment in &mut clients
    {
        equipment.set_main_hand(ItemStack::new(ItemKind::DiamondSword, 1, None));
        equipment.set_off_hand(ItemStack::new(ItemKind::Shield, 1, None));
        equipment.set_feet(ItemStack::new(ItemKind::DiamondBoots, 1, None));
        equipment.set_legs(ItemStack::new(ItemKind::DiamondLeggings, 1, None));
        equipment.set_chest(ItemStack::new(ItemKind::DiamondChestplate, 1, None));
        equipment.set_head(ItemStack::new(ItemKind::DiamondHelmet, 1, None));
    }
}

§See also

Examples related to inventories in the valence/examples/ directory:

  • equipment

Structs§

Equipment
Contains the visible equipment of a LivingEntity, such as armor and held items. By default this is not synced with a player’s [valence_inventory::Inventory], so the armor the player has equipped in their inventory, will not be visible by other players. You would have to change the equipment in this component here or attach the EquipmentInventorySync component to the player entity to sync the equipment with the inventory.
EquipmentChangeEvent
EquipmentInteractionBroadcast
This component will broadcast item interactions (e.g. drawing a bow, eating food) to other players using LivingFlags::set_using_item.
EquipmentInventorySync
This component will sync a player’s Equipment, which is visible to other players, with the player [Inventory].
EquipmentPlugin
EquipmentSlotChange