aboutsummaryrefslogtreecommitdiff
path: root/azalea-inventory/src/item/mod.rs
blob: 015ca0e2d064174419d6b47bc2c57a993b08d958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use azalea_registry::builtin::ItemKind;

use crate::{components::MaxStackSize, default_components::get_default_component};

pub mod consume_effect;

pub trait MaxStackSizeExt {
    /// Get the maximum stack size for this item.
    ///
    /// This is a signed integer to be consistent with the `count` field of
    /// [`ItemStackData`].
    ///
    /// [`ItemStackData`]: crate::ItemStackData
    fn max_stack_size(&self) -> i32;

    /// Whether this item can be stacked with other items.
    ///
    /// This is equivalent to `self.max_stack_size() > 1`.
    fn stackable(&self) -> bool {
        self.max_stack_size() > 1
    }
}

impl MaxStackSizeExt for ItemKind {
    fn max_stack_size(&self) -> i32 {
        get_default_component::<MaxStackSize>(*self).map_or(64, |s| s.count)
    }
}