Skip to main content

steel_core/behavior/items/
shield.rs

1use std::borrow::Cow;
2
3use steel_macros::item_behavior;
4use steel_registry::{data_components::vanilla_components::BASE_COLOR, item_stack::ItemStack};
5use text_components::TextComponent;
6
7use crate::behavior::ItemBehavior;
8
9use super::dynamic_name::{default_name, description_id, translated};
10
11/// Shield behavior providing the base-color-specific name.
12// TODO: Complete the shared Item.use BLOCKS_ATTACKS path so shields can block.
13#[item_behavior]
14pub struct ShieldItem;
15
16impl ItemBehavior for ShieldItem {
17    fn get_name<'a>(&self, stack: &'a ItemStack) -> Cow<'a, TextComponent> {
18        let Some(color) = stack.get(BASE_COLOR) else {
19            return default_name(stack);
20        };
21        let Some(description_id) = description_id(stack) else {
22            return default_name(stack);
23        };
24        translated(
25            format!("{description_id}.{}", color.serialized_name()),
26            None,
27        )
28    }
29}