pub struct ItemStack {
pub item_id: u32,
pub amount: u32,
pub durability: Option<f32>,
}Expand description
A stack of identical items in an inventory.
This is the primary ECS component for representing items in the world or in a container. It is serialised via bincode when crossing the WASM boundary (get_component / set_component).
§Example
use openstranded_common_items::ItemStack;
let stack = ItemStack::new(23, 1); // one stone
let tool = ItemStack::with_durability(30, 1, 100.0); // hammer at full healthFields§
§item_id: u32Item type ID (matches ItemDef.id).
amount: u32Number of items in this stack.
durability: Option<f32>Remaining durability for tools / weapons.
None means the item doesn’t have durability (non-tools).
Some(n) means current durability; when it reaches 0 the item breaks.
Implementations§
Source§impl ItemStack
impl ItemStack
Sourcepub const MAX_STACK: u32 = 999
pub const MAX_STACK: u32 = 999
Maximum amount per stack.
This is a game-wide constant from the original game (999). Individual item types may override this in the future.
Sourcepub const fn new(item_id: u32, amount: u32) -> ItemStack
pub const fn new(item_id: u32, amount: u32) -> ItemStack
Create a new stack of amount items of type item_id.
Durability is set to None (non-relevant for non-tools).
Sourcepub const fn with_durability(
item_id: u32,
amount: u32,
durability: f32,
) -> ItemStack
pub const fn with_durability( item_id: u32, amount: u32, durability: f32, ) -> ItemStack
Create a new stack with a specific durability value.
Useful for tools and weapons that degrade over time.